Total Complexity | 6 |
Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
15 | class HydratorGenerator |
||
16 | { |
||
17 | use EnsureDirectory; |
||
18 | |||
19 | /** |
||
20 | * @var DocumentManager |
||
21 | */ |
||
22 | private $documentManager; |
||
23 | |||
24 | public function __construct(DocumentManager $documentManager) |
||
25 | { |
||
26 | $this->documentManager = $documentManager; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * @return string[]|null |
||
31 | */ |
||
32 | public function __invoke(): array |
||
33 | { |
||
34 | $metadataCollection = $this->getMetadataCollection(); |
||
35 | |||
36 | if (count($metadataCollection) === 0) { |
||
37 | return []; |
||
38 | } |
||
39 | |||
40 | $this->getHydratorFactory()->generateHydratorClasses( |
||
41 | $metadataCollection, |
||
42 | $this->ensureDirectory($this->getHydratorDir()) |
||
43 | ); |
||
44 | |||
45 | return array_map(function ($metadata) { |
||
46 | return $metadata->name; |
||
47 | }, $metadataCollection); |
||
48 | } |
||
49 | |||
50 | private function getMetadataCollection(): array |
||
51 | { |
||
52 | return $this->documentManager->getMetadataFactory()->getAllMetadata(); |
||
53 | } |
||
54 | |||
55 | private function getHydratorDir(): string |
||
56 | { |
||
57 | return $this->documentManager->getConfiguration()->getHydratorDir(); |
||
58 | } |
||
59 | |||
60 | private function getHydratorFactory(): HydratorFactory |
||
63 | } |
||
64 | } |
||
65 |