Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
AvailableApieObjectProviderGenerator
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 generateFile
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 generateAvailableApieObjectProvider
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\ApieCommonPlugin;
3
4use Apie\Core\Other\ActualFileWriter;
5use Apie\Core\Other\FileWriterInterface;
6use Nette\PhpGenerator\PhpFile;
7
8final class AvailableApieObjectProviderGenerator
9{
10    public function __construct(
11        private readonly FileWriterInterface $fileWriter = new ActualFileWriter()
12    ) {
13    }
14
15    public function generateFile(array $classNames): void
16    {
17        $phpCode = $this->generateAvailableApieObjectProvider($classNames);
18        $this->fileWriter->writeFile(__DIR__ . '/AvailableApieObjectProvider.php', $phpCode);
19        @chmod(__DIR__ . '/AvailableApieObjectProvider.php', 0666);
20    }
21
22    private function generateAvailableApieObjectProvider(array $classNames): string
23    {
24        $phpFile = new PhpFile();
25        $namespace = $phpFile->addNamespace('Apie\ApieCommonPlugin');
26
27        $namespace->addUse(ObjectProvider::class);
28
29        $class = $namespace->addClass('AvailableApieObjectProvider');
30        $class->setComment('@codeCoverageIgnore' . PHP_EOL . 'This class is auto-generated');
31
32        $class->setExtends(ObjectProvider::class);
33        $class->addConstant('DEFINED_CLASSES', $classNames)->setVisibility('protected');
34        
35        return (string) $phpFile;
36    }
37}