1 | <?php |
||
51 | class Item implements ItemInterface |
||
52 | { |
||
53 | /** |
||
54 | * Item type(s) |
||
55 | * |
||
56 | * @var \stdClass[] |
||
57 | */ |
||
58 | protected $type; |
||
59 | |||
60 | /** |
||
61 | * Item properties |
||
62 | * |
||
63 | * @var PropertyListInterface |
||
64 | */ |
||
65 | protected $properties; |
||
66 | |||
67 | /** |
||
68 | * Item ID |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $itemId; |
||
73 | |||
74 | /** |
||
75 | * Item language |
||
76 | * |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $itemLanguage; |
||
80 | |||
81 | /** |
||
82 | * Property list factory |
||
83 | * |
||
84 | * @var PropertyListFactoryInterface |
||
85 | */ |
||
86 | protected $propertyListFactory; |
||
87 | |||
88 | /** |
||
89 | * Item constructor |
||
90 | * |
||
91 | * @param string|\stdClass|\stdClass[] $type Item type(s) |
||
92 | * @param \stdClass[] $properties Item properties |
||
93 | * @param string|null $itemId Item id |
||
94 | * @param string|null $itemLanguage Item language |
||
95 | * @param PropertyListFactoryInterface|null $propertyListFactory Property list factory |
||
96 | */ |
||
97 | 52 | public function __construct( |
|
112 | |||
113 | /** |
||
114 | * Setup the item |
||
115 | * |
||
116 | * @param PropertyListFactory $propertyListFactory Property list factory |
||
117 | * @param string[]|\stdClass[] $type Item type(s) |
||
118 | * @param \stdClass[] $properties Item properties |
||
119 | * @param string $itemId Item ID |
||
120 | * @param string $itemLanguage Item language |
||
121 | */ |
||
122 | 52 | protected function setup( |
|
135 | |||
136 | /** |
||
137 | * Validate and sanitize the item types |
||
138 | * |
||
139 | * @param \stdClass[] $types Item types |
||
140 | * @return array Validated item types |
||
141 | * @throws InvalidArgumentException If there are no valid types |
||
142 | */ |
||
143 | 52 | protected function validateTypes(array $types) |
|
157 | |||
158 | /** |
||
159 | * Validate the item properties |
||
160 | * |
||
161 | * @param array $properties Item properties |
||
162 | * @return PropertyListInterface Validated item properties |
||
163 | * @throws InvalidArgumentException If the property name is empty |
||
164 | */ |
||
165 | 50 | protected function validateProperties(array $properties) |
|
176 | |||
177 | /** |
||
178 | * Return the item types |
||
179 | * |
||
180 | * @return \stdClass[] Item types |
||
181 | */ |
||
182 | 26 | public function getType() |
|
186 | |||
187 | /** |
||
188 | * Return the item ID (if any) |
||
189 | * |
||
190 | * @return string|null Item id |
||
191 | */ |
||
192 | 21 | public function getId() |
|
196 | |||
197 | /** |
||
198 | * Return the item language (if any) |
||
199 | * |
||
200 | * @return string|null Item language |
||
201 | */ |
||
202 | 20 | public function getLanguage() |
|
206 | |||
207 | /** |
||
208 | * Return all item properties |
||
209 | * |
||
210 | * @return PropertyListInterface Item properties list |
||
211 | */ |
||
212 | 21 | public function getProperties() |
|
216 | |||
217 | /** |
||
218 | * Return the values of a particular property |
||
219 | * |
||
220 | * @param string|\stdClass|Iri $name Property name |
||
221 | * @param string|null $profile Property profile |
||
222 | * @return array Item property values |
||
223 | */ |
||
224 | 11 | public function getProperty($name, $profile = null) |
|
236 | |||
237 | /** |
||
238 | * Return whether the value should be considered empty |
||
239 | * |
||
240 | * @return boolean Value is empty |
||
241 | */ |
||
242 | 23 | public function isEmpty() |
|
246 | |||
247 | /** |
||
248 | * Validate a single property |
||
249 | * |
||
250 | * @param \stdClass $property Property |
||
251 | * @return \stdClass Validated property |
||
252 | */ |
||
253 | 39 | protected function validateProperty($property) |
|
274 | |||
275 | /** |
||
276 | * Validate the structure of a property object |
||
277 | * |
||
278 | * @param \stdClass $property Property object |
||
279 | * @throws InvalidArgumentException If the property object is invalid |
||
280 | */ |
||
281 | 39 | protected function validatePropertyStructure($property) |
|
291 | |||
292 | /** |
||
293 | * Validate the properties of a property |
||
294 | * |
||
295 | * @param \stdClass $property Property |
||
296 | * @return bool Property properties are valid |
||
297 | */ |
||
298 | 39 | protected function validatePropertyProperties($property) |
|
305 | |||
306 | /** |
||
307 | * Validate a property name |
||
308 | * |
||
309 | * @param \stdClass $property Property |
||
310 | * @return string Property name |
||
311 | */ |
||
312 | 37 | protected function validatePropertyName($property) |
|
326 | |||
327 | /** |
||
328 | * Validate a list of property values |
||
329 | * |
||
330 | * @param array $values Property values |
||
331 | * @return array Validated property values |
||
332 | * @throws InvalidArgumentException If the value is not a nested item |
||
333 | */ |
||
334 | 36 | protected function validatePropertyValues(array $values) |
|
346 | |||
347 | /** |
||
348 | * Process a (non-empty) property value |
||
349 | * |
||
350 | * @param ValueInterface $value Property value |
||
351 | * @param array $nonEmptyPropertyValues Non-empty property values |
||
352 | */ |
||
353 | 36 | protected function processPropertyValue($value, array &$nonEmptyPropertyValues) |
|
368 | |||
369 | /** |
||
370 | * Validate a single item type |
||
371 | * |
||
372 | * @param \stdClass|Iri|string $type Item type |
||
373 | * @return Iri|null Validated item type |
||
374 | * @throws InvalidArgumentException If the item type object is invalid |
||
375 | */ |
||
376 | 52 | protected function validateType($type) |
|
381 | } |
||
382 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.