1 | <?php |
||
31 | class FileAssembler extends AssemblerAbstract |
||
32 | { |
||
33 | /** |
||
34 | * Creates a Descriptor from the provided data. |
||
35 | * |
||
36 | * @param File $data |
||
37 | * |
||
38 | * @return FileDescriptor |
||
39 | */ |
||
40 | 1 | public function create($data) |
|
41 | { |
||
42 | 1 | $fileDescriptor = new FileDescriptor($data->getHash()); |
|
43 | 1 | $fileDescriptor->setPackage( |
|
44 | 1 | $this->extractPackageFromDocBlock($data->getDocBlock()) ?: $this->getBuilder()->getDefaultPackage() |
|
|
|||
45 | ); |
||
46 | |||
47 | 1 | $fileDescriptor->setName($data->getName()); |
|
48 | 1 | $fileDescriptor->setPath($data->getPath()); |
|
49 | 1 | if ($this->getBuilder()->getProjectDescriptor()->getSettings()->shouldIncludeSource()) { |
|
50 | 1 | $fileDescriptor->setSource($data->getSource()); |
|
51 | } |
||
52 | |||
53 | 1 | $fileDescriptor->setIncludes(new Collection($data->getIncludes())); |
|
54 | 1 | $fileDescriptor->setNamespaceAliases(new Collection($data->getNamespaces())); |
|
55 | |||
56 | 1 | $this->assembleDocBlock($data->getDocBlock(), $fileDescriptor); |
|
57 | 1 | $this->overridePackageTag($data, $fileDescriptor); |
|
58 | |||
59 | //$this->addMarkers($data->getMarkers(), $fileDescriptor); |
||
60 | 1 | $this->addConstants($data->getConstants(), $fileDescriptor); |
|
61 | 1 | $this->addFunctions($data->getFunctions(), $fileDescriptor); |
|
62 | 1 | $this->addClasses($data->getClasses(), $fileDescriptor); |
|
63 | 1 | $this->addInterfaces($data->getInterfaces(), $fileDescriptor); |
|
64 | 1 | $this->addTraits($data->getTraits(), $fileDescriptor); |
|
65 | |||
66 | 1 | return $fileDescriptor; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Registers the child constants with the generated File Descriptor. |
||
71 | * |
||
72 | * @param Constant[] $constants |
||
73 | */ |
||
74 | 1 | protected function addConstants(array $constants, FileDescriptor $fileDescriptor): void |
|
75 | { |
||
76 | 1 | foreach ($constants as $constant) { |
|
77 | $constantDescriptor = $this->getBuilder()->buildDescriptor($constant); |
||
78 | if ($constantDescriptor) { |
||
79 | $constantDescriptor->setLocation($fileDescriptor, $constant->getLocation()->getLineNumber()); |
||
80 | if (count($constantDescriptor->getTags()->get('package', new Collection())) === 0) { |
||
81 | $constantDescriptor->getTags() |
||
82 | ->set('package', $fileDescriptor->getTags()->get('package', new Collection())); |
||
83 | } |
||
84 | |||
85 | $fileDescriptor->getConstants()->set( |
||
86 | (string) $constantDescriptor->getFullyQualifiedStructuralElementName(), |
||
87 | $constantDescriptor |
||
88 | ); |
||
89 | } |
||
90 | } |
||
91 | 1 | } |
|
92 | |||
93 | /** |
||
94 | * Registers the child functions with the generated File Descriptor. |
||
95 | * |
||
96 | * @param Function_[] $functions |
||
97 | */ |
||
98 | 1 | protected function addFunctions(array $functions, FileDescriptor $fileDescriptor): void |
|
99 | { |
||
100 | 1 | foreach ($functions as $function) { |
|
101 | $functionDescriptor = $this->getBuilder()->buildDescriptor($function); |
||
102 | if ($functionDescriptor) { |
||
103 | $functionDescriptor->setLocation($fileDescriptor, $function->getLocation()->getLineNumber()); |
||
104 | if (count($functionDescriptor->getTags()->get('package', new Collection())) === 0) { |
||
105 | $functionDescriptor->getTags() |
||
106 | ->set('package', $fileDescriptor->getTags()->get('package', new Collection())); |
||
107 | } |
||
108 | |||
109 | $fileDescriptor->getFunctions()->set( |
||
110 | (string) $functionDescriptor->getFullyQualifiedStructuralElementName(), |
||
111 | $functionDescriptor |
||
112 | ); |
||
113 | } |
||
114 | } |
||
115 | 1 | } |
|
116 | |||
117 | /** |
||
118 | * Registers the child classes with the generated File Descriptor. |
||
119 | * |
||
120 | * @param Class_[] $classes |
||
121 | */ |
||
122 | 1 | protected function addClasses(array $classes, FileDescriptor $fileDescriptor): void |
|
142 | |||
143 | /** |
||
144 | * Registers the child interfaces with the generated File Descriptor. |
||
145 | * |
||
146 | * @param Interface_[] $interfaces |
||
147 | */ |
||
148 | 1 | protected function addInterfaces(array $interfaces, FileDescriptor $fileDescriptor): void |
|
166 | |||
167 | /** |
||
168 | * Registers the child traits with the generated File Descriptor. |
||
169 | * |
||
170 | * @param Trait_[] $traits |
||
171 | */ |
||
172 | 1 | protected function addTraits(array $traits, FileDescriptor $fileDescriptor): void |
|
190 | |||
191 | /** |
||
192 | * Registers the markers that were found in a File with the File Descriptor. |
||
193 | * |
||
194 | * @param string[] $markers |
||
195 | */ |
||
196 | protected function addMarkers(array $markers, FileDescriptor $fileDescriptor): void |
||
209 | |||
210 | 1 | protected function overridePackageTag(File $data, FileDescriptor $fileDescriptor): void |
|
223 | } |
||
224 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: