These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * phpDocumentor |
||
4 | * |
||
5 | * PHP Version 5.3 |
||
6 | * |
||
7 | * @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com) |
||
8 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
9 | * @link http://phpdoc.org |
||
10 | */ |
||
11 | |||
12 | namespace phpDocumentor\Descriptor\Builder\Reflector; |
||
13 | |||
14 | use phpDocumentor\Descriptor\ClassDescriptor; |
||
15 | use phpDocumentor\Descriptor\Collection; |
||
16 | use phpDocumentor\Reflection\ClassReflector; |
||
17 | use phpDocumentor\Reflection\ConstantReflector; |
||
18 | use phpDocumentor\Reflection\Php\Class_; |
||
19 | use phpDocumentor\Reflection\Php\Constant; |
||
20 | use phpDocumentor\Reflection\Php\Method; |
||
21 | use phpDocumentor\Reflection\Php\Property; |
||
22 | |||
23 | /** |
||
24 | * Assembles an ClassDescriptor using an ClassReflector. |
||
25 | */ |
||
26 | class ClassAssembler extends AssemblerAbstract |
||
27 | { |
||
28 | /** |
||
29 | * Creates a Descriptor from the provided data. |
||
30 | * |
||
31 | * @param Class_ $data |
||
32 | * |
||
33 | * @return ClassDescriptor |
||
34 | */ |
||
35 | 1 | public function create($data) |
|
36 | { |
||
37 | 1 | $classDescriptor = new ClassDescriptor(); |
|
38 | |||
39 | 1 | $classDescriptor->setFullyQualifiedStructuralElementName($data->getFqsen()); |
|
40 | 1 | $classDescriptor->setName($data->getName()); |
|
41 | 1 | $classDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: $this->getBuilder()->getDefaultPackage()); |
|
0 ignored issues
–
show
|
|||
42 | 1 | $classDescriptor->setLine($data->getLocation()->getLineNumber()); |
|
43 | 1 | $classDescriptor->setParent($data->getParent()); |
|
44 | 1 | $classDescriptor->setAbstract($data->isAbstract()); |
|
45 | 1 | $classDescriptor->setFinal($data->isFinal()); |
|
46 | 1 | $classDescriptor->setNamespace(substr($data->getFqsen(), 0, -strlen($data->getName())-1)); |
|
47 | |||
48 | 1 | foreach ($data->getInterfaces() as $interfaceClassName) { |
|
49 | 1 | $classDescriptor->getInterfaces()->set((string)$interfaceClassName, $interfaceClassName); |
|
50 | } |
||
51 | |||
52 | 1 | $this->assembleDocBlock($data->getDocBlock(), $classDescriptor); |
|
53 | |||
54 | 1 | $this->addConstants($data->getConstants(), $classDescriptor); |
|
55 | 1 | $this->addProperties($data->getProperties(), $classDescriptor); |
|
56 | 1 | $this->addMethods($data->getMethods(), $classDescriptor); |
|
57 | 1 | $this->addUses($data->getUsedTraits(), $classDescriptor); |
|
58 | |||
59 | 1 | return $classDescriptor; |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * Registers the child constants with the generated Class Descriptor. |
||
64 | * |
||
65 | * @param Constant[] $constants |
||
66 | * @param ClassDescriptor $classDescriptor |
||
67 | * |
||
68 | * @return void |
||
69 | */ |
||
70 | 1 | protected function addConstants($constants, $classDescriptor) |
|
71 | { |
||
72 | 1 | foreach ($constants as $constant) { |
|
73 | 1 | $constantDescriptor = $this->getBuilder()->buildDescriptor($constant); |
|
74 | 1 | if ($constantDescriptor) { |
|
75 | $constantDescriptor->setParent($classDescriptor); |
||
76 | 1 | $classDescriptor->getConstants()->set($constantDescriptor->getName(), $constantDescriptor); |
|
77 | } |
||
78 | } |
||
79 | 1 | } |
|
80 | |||
81 | /** |
||
82 | * Registers the child properties with the generated Class Descriptor. |
||
83 | * |
||
84 | * @param Property[] $properties |
||
85 | * @param ClassDescriptor $classDescriptor |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | 1 | protected function addProperties($properties, $classDescriptor) |
|
90 | { |
||
91 | 1 | foreach ($properties as $property) { |
|
92 | 1 | $propertyDescriptor = $this->getBuilder()->buildDescriptor($property); |
|
93 | 1 | if ($propertyDescriptor) { |
|
94 | $propertyDescriptor->setParent($classDescriptor); |
||
95 | 1 | $classDescriptor->getProperties()->set($propertyDescriptor->getName(), $propertyDescriptor); |
|
96 | } |
||
97 | } |
||
98 | 1 | } |
|
99 | |||
100 | /** |
||
101 | * Registers the child methods with the generated Class Descriptor. |
||
102 | * |
||
103 | * @param Method[] $methods |
||
104 | * @param ClassDescriptor $classDescriptor |
||
105 | * |
||
106 | * @return void |
||
107 | */ |
||
108 | 1 | protected function addMethods($methods, $classDescriptor) |
|
109 | { |
||
110 | 1 | foreach ($methods as $method) { |
|
111 | 1 | $methodDescriptor = $this->getBuilder()->buildDescriptor($method); |
|
112 | 1 | if ($methodDescriptor) { |
|
113 | $methodDescriptor->setParent($classDescriptor); |
||
114 | 1 | $classDescriptor->getMethods()->set($methodDescriptor->getName(), $methodDescriptor); |
|
115 | } |
||
116 | } |
||
117 | 1 | } |
|
118 | |||
119 | /** |
||
120 | * Registers the used traits with the generated Class Descriptor. |
||
121 | * |
||
122 | * @param string[] $traits |
||
123 | * @param ClassDescriptor $classDescriptor |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | 1 | protected function addUses(array $traits, ClassDescriptor $classDescriptor) |
|
128 | { |
||
129 | 1 | $classDescriptor->setUsedTraits(new Collection($traits)); |
|
130 | 1 | } |
|
131 | } |
||
132 |
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: