Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
78.57% |
11 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ObjectProviderFactory | |
78.57% |
11 / 14 |
|
0.00% |
0 / 2 |
6.35 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
create | |
84.62% |
11 / 13 |
|
0.00% |
0 / 1 |
5.09 |
1 | <?php |
2 | namespace Apie\ApieCommonPlugin; |
3 | |
4 | use Apie\Core\Other\ActualFileWriter; |
5 | use Apie\Core\Other\FileWriterInterface; |
6 | use Symfony\Component\Finder\Finder; |
7 | |
8 | final class ObjectProviderFactory |
9 | { |
10 | private function __construct() |
11 | { |
12 | } |
13 | |
14 | public static function create(FileWriterInterface $fileWriter = new ActualFileWriter()): ObjectProvider |
15 | { |
16 | if (class_exists(AvailableApieObjectProvider::class)) { |
17 | return new AvailableApieObjectProvider(); |
18 | } |
19 | $classNames = []; |
20 | foreach (Finder::create()->in(__DIR__ . '/../../')->files()->name('composer.json')->depth([1]) as $file) { |
21 | $contents = json_decode(file_get_contents((string) $file), true); |
22 | if (is_array($contents['extra']['apie-objects'] ?? null)) { |
23 | $classNames = [...$classNames, ...$contents['extra']['apie-objects']]; |
24 | } |
25 | } |
26 | $code = new AvailableApieObjectProviderGenerator($fileWriter); |
27 | $code->generateFile($classNames); |
28 | if (class_exists(AvailableApieObjectProvider::class)) { |
29 | return new AvailableApieObjectProvider(); |
30 | } |
31 | return new class extends ObjectProvider { |
32 | }; |
33 | } |
34 | } |