1 | <?php |
||
30 | class ProjectDescriptorBuilder |
||
31 | { |
||
32 | /** @var string */ |
||
33 | const DEFAULT_PROJECT_NAME = 'Untitled project'; |
||
34 | |||
35 | /** @var AssemblerFactory $assemblerFactory */ |
||
36 | protected $assemblerFactory; |
||
37 | |||
38 | /** @var Filter $filter */ |
||
39 | protected $filter; |
||
40 | |||
41 | /** @var ProjectDescriptor $project */ |
||
42 | protected $project; |
||
43 | |||
44 | private $defaultPackage; |
||
45 | |||
46 | public function __construct(AssemblerFactory $assemblerFactory, Filter $filterManager) |
||
47 | { |
||
48 | $this->assemblerFactory = $assemblerFactory; |
||
49 | $this->filter = $filterManager; |
||
50 | } |
||
51 | |||
52 | 1 | public function createProjectDescriptor() |
|
53 | { |
||
54 | 1 | $this->project = new ProjectDescriptor(self::DEFAULT_PROJECT_NAME); |
|
55 | 1 | } |
|
56 | |||
57 | 1 | public function setProjectDescriptor(ProjectDescriptor $projectDescriptor) |
|
58 | { |
||
59 | 1 | $this->project = $projectDescriptor; |
|
60 | 1 | } |
|
61 | |||
62 | /** |
||
63 | * Returns the project descriptor that is being built. |
||
64 | * |
||
65 | * @return ProjectDescriptor |
||
66 | */ |
||
67 | 2 | public function getProjectDescriptor() |
|
68 | { |
||
69 | 2 | return $this->project; |
|
70 | } |
||
71 | |||
72 | /** |
||
73 | * Verifies whether the given visibility is allowed to be included in the Descriptors. |
||
74 | * |
||
75 | * This method is used anytime a Descriptor is added to a collection (for example, when adding a Method to a Class) |
||
76 | * to determine whether the visibility of that element is matches what the user has specified when it ran |
||
77 | * phpDocumentor. |
||
78 | * |
||
79 | * @param string|integer $visibility One of the visibility constants of the ProjectDescriptor class or the words |
||
80 | * 'public', 'protected', 'private' or 'internal'. |
||
81 | * |
||
82 | * @see ProjectDescriptor where the visibility is stored and that declares the constants to use. |
||
83 | * |
||
84 | * @return boolean |
||
85 | */ |
||
86 | 1 | public function isVisibilityAllowed($visibility) |
|
87 | { |
||
88 | switch ($visibility) { |
||
89 | 1 | case 'public': |
|
90 | $visibility = Settings::VISIBILITY_PUBLIC; |
||
91 | break; |
||
92 | 1 | case 'protected': |
|
93 | $visibility = Settings::VISIBILITY_PROTECTED; |
||
94 | break; |
||
95 | 1 | case 'private': |
|
96 | $visibility = Settings::VISIBILITY_PRIVATE; |
||
97 | break; |
||
98 | 1 | case 'internal': |
|
99 | $visibility = Settings::VISIBILITY_INTERNAL; |
||
100 | break; |
||
101 | } |
||
102 | |||
103 | 1 | return $this->getProjectDescriptor()->isVisibilityAllowed($visibility); |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * Takes the given data and attempts to build a Descriptor from it. |
||
108 | * |
||
109 | * @param mixed $data |
||
110 | * |
||
111 | * @throws \InvalidArgumentException if no Assembler could be found that matches the given data. |
||
112 | * |
||
113 | * @return DescriptorAbstract|Collection|null |
||
114 | */ |
||
115 | public function buildDescriptor($data) |
||
116 | { |
||
117 | $assembler = $this->getAssembler($data); |
||
118 | if (!$assembler) { |
||
119 | throw new \InvalidArgumentException( |
||
120 | 'Unable to build a Descriptor; the provided data did not match any Assembler ' . |
||
121 | get_class($data) |
||
122 | ); |
||
123 | } |
||
124 | |||
125 | if ($assembler instanceof Builder\AssemblerAbstract) { |
||
126 | $assembler->setBuilder($this); |
||
127 | } |
||
128 | |||
129 | // create Descriptor and populate with the provided data |
||
130 | $descriptor = $assembler->create($data); |
||
131 | if (!$descriptor) { |
||
132 | return null; |
||
133 | } |
||
134 | |||
135 | return (!is_array($descriptor) && (!$descriptor instanceof Collection)) |
||
136 | ? $this->filterDescriptor($descriptor) |
||
137 | : $this->filterEachDescriptor($descriptor); |
||
|
|||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Attempts to find an assembler matching the given data. |
||
142 | * |
||
143 | * @param mixed $data |
||
144 | * |
||
145 | * @return AssemblerInterface|null |
||
146 | */ |
||
147 | public function getAssembler($data) |
||
151 | |||
152 | /** |
||
153 | * Analyzes a Descriptor and alters its state based on its state or even removes the descriptor. |
||
154 | * |
||
155 | * @return Filterable |
||
156 | */ |
||
157 | public function filter(Filterable $descriptor) |
||
161 | |||
162 | /** |
||
163 | * Filters each descriptor, validates them, stores the validation results and returns a collection of transmuted |
||
164 | * objects. |
||
165 | * |
||
166 | * @param DescriptorAbstract[] $descriptor |
||
167 | * |
||
168 | * @return Collection |
||
169 | */ |
||
170 | private function filterEachDescriptor($descriptor) |
||
184 | |||
185 | /** |
||
186 | * Filters a descriptor, validates it, stores the validation results and returns the transmuted object or null |
||
187 | * if it is supposed to be removed. |
||
188 | * |
||
189 | * @param Descriptor $descriptor |
||
190 | * |
||
191 | * @return Descriptor|null |
||
192 | */ |
||
193 | protected function filterDescriptor(Descriptor $descriptor) |
||
207 | |||
208 | /** |
||
209 | * Map error code to severity. |
||
210 | * |
||
211 | * @param int $code |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | protected function mapCodeToSeverity($code) |
||
219 | |||
220 | public function build(Project $project) |
||
248 | |||
249 | public function getDefaultPackage() |
||
250 | { |
||
251 | return $this->defaultPackage; |
||
252 | } |
||
253 | } |
||
254 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: