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( |
|
42 | 1 | $this->extractPackageFromDocBlock($data->getDocBlock()) ?: $this->getBuilder()->getDefaultPackage() |
|
0 ignored issues
–
show
|
|||
43 | ); |
||
44 | 1 | $classDescriptor->setLine($data->getLocation()->getLineNumber()); |
|
45 | 1 | $classDescriptor->setParent($data->getParent()); |
|
46 | 1 | $classDescriptor->setAbstract($data->isAbstract()); |
|
47 | 1 | $classDescriptor->setFinal($data->isFinal()); |
|
48 | 1 | $classDescriptor->setNamespace(substr($data->getFqsen(), 0, -strlen($data->getName())-1)); |
|
49 | |||
50 | 1 | foreach ($data->getInterfaces() as $interfaceClassName) { |
|
51 | 1 | $classDescriptor->getInterfaces()->set((string)$interfaceClassName, $interfaceClassName); |
|
52 | } |
||
53 | |||
54 | 1 | $this->assembleDocBlock($data->getDocBlock(), $classDescriptor); |
|
55 | |||
56 | 1 | $this->addConstants($data->getConstants(), $classDescriptor); |
|
57 | 1 | $this->addProperties($data->getProperties(), $classDescriptor); |
|
58 | 1 | $this->addMethods($data->getMethods(), $classDescriptor); |
|
59 | 1 | $this->addUses($data->getUsedTraits(), $classDescriptor); |
|
60 | |||
61 | 1 | return $classDescriptor; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Registers the child constants with the generated Class Descriptor. |
||
66 | * |
||
67 | * @param Constant[] $constants |
||
68 | * @param ClassDescriptor $classDescriptor |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | 1 | protected function addConstants($constants, $classDescriptor) |
|
73 | { |
||
74 | 1 | foreach ($constants as $constant) { |
|
75 | 1 | $constantDescriptor = $this->getBuilder()->buildDescriptor($constant); |
|
76 | 1 | if ($constantDescriptor) { |
|
77 | $constantDescriptor->setParent($classDescriptor); |
||
78 | 1 | $classDescriptor->getConstants()->set($constantDescriptor->getName(), $constantDescriptor); |
|
79 | } |
||
80 | } |
||
81 | 1 | } |
|
82 | |||
83 | /** |
||
84 | * Registers the child properties with the generated Class Descriptor. |
||
85 | * |
||
86 | * @param Property[] $properties |
||
87 | * @param ClassDescriptor $classDescriptor |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | 1 | protected function addProperties($properties, $classDescriptor) |
|
92 | { |
||
93 | 1 | foreach ($properties as $property) { |
|
94 | 1 | $propertyDescriptor = $this->getBuilder()->buildDescriptor($property); |
|
95 | 1 | if ($propertyDescriptor) { |
|
96 | $propertyDescriptor->setParent($classDescriptor); |
||
97 | 1 | $classDescriptor->getProperties()->set($propertyDescriptor->getName(), $propertyDescriptor); |
|
98 | } |
||
99 | } |
||
100 | 1 | } |
|
101 | |||
102 | /** |
||
103 | * Registers the child methods with the generated Class Descriptor. |
||
104 | * |
||
105 | * @param Method[] $methods |
||
106 | * @param ClassDescriptor $classDescriptor |
||
107 | * |
||
108 | * @return void |
||
109 | */ |
||
110 | 1 | protected function addMethods($methods, $classDescriptor) |
|
111 | { |
||
112 | 1 | foreach ($methods as $method) { |
|
113 | 1 | $methodDescriptor = $this->getBuilder()->buildDescriptor($method); |
|
114 | 1 | if ($methodDescriptor) { |
|
115 | $methodDescriptor->setParent($classDescriptor); |
||
116 | 1 | $classDescriptor->getMethods()->set($methodDescriptor->getName(), $methodDescriptor); |
|
117 | } |
||
118 | } |
||
119 | 1 | } |
|
120 | |||
121 | /** |
||
122 | * Registers the used traits with the generated Class Descriptor. |
||
123 | * |
||
124 | * @param string[] $traits |
||
125 | * @param ClassDescriptor $classDescriptor |
||
126 | * |
||
127 | * @return void |
||
128 | */ |
||
129 | 1 | protected function addUses(array $traits, ClassDescriptor $classDescriptor) |
|
130 | { |
||
131 | 1 | $classDescriptor->setUsedTraits(new Collection($traits)); |
|
132 | 1 | } |
|
133 | } |
||
134 |
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: