1 | <?php |
||
28 | class TraitAssembler extends AssemblerAbstract |
||
29 | { |
||
30 | /** |
||
31 | * Creates a Descriptor from the provided data. |
||
32 | * |
||
33 | * @param Trait_ $data |
||
34 | * |
||
35 | * @return TraitDescriptor |
||
36 | */ |
||
37 | 1 | public function create($data) |
|
38 | { |
||
39 | 1 | $traitDescriptor = new TraitDescriptor(); |
|
40 | |||
41 | 1 | $traitDescriptor->setFullyQualifiedStructuralElementName($data->getFqsen()); |
|
42 | 1 | $traitDescriptor->setName($data->getName()); |
|
43 | 1 | $traitDescriptor->setLine($data->getLocation()->getLineNumber()); |
|
44 | 1 | $traitDescriptor->setPackage($this->extractPackageFromDocBlock($data->getDocBlock()) ?: ''); |
|
45 | |||
46 | // Reflection library formulates namespace as global but this is not wanted for phpDocumentor itself |
||
47 | 1 | $traitDescriptor->setNamespace( |
|
48 | 1 | substr((string) $data->getFqsen(), 0, -strlen($data->getName()) - 1) |
|
49 | ); |
||
50 | |||
51 | 1 | $this->assembleDocBlock($data->getDocBlock(), $traitDescriptor); |
|
52 | |||
53 | 1 | $this->addProperties($data->getProperties(), $traitDescriptor); |
|
54 | 1 | $this->addMethods($data->getMethods(), $traitDescriptor); |
|
55 | |||
56 | 1 | return $traitDescriptor; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Registers the child properties with the generated Trait Descriptor. |
||
61 | * |
||
62 | * @param Property[] $properties |
||
63 | */ |
||
64 | protected function addProperties(array $properties, TraitDescriptor $traitDescriptor): void |
||
74 | |||
75 | /** |
||
76 | * Registers the child methods with the generated Trait Descriptor. |
||
77 | * |
||
78 | * @param Method[] $methods |
||
79 | */ |
||
80 | protected function addMethods(array $methods, TraitDescriptor $traitDescriptor): void |
||
90 | } |
||
91 |
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: