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 | 46 | public function __construct( |
|
110 | |||
111 | /** |
||
112 | * Validate and sanitize the item types |
||
113 | * |
||
114 | * @param \stdClass[] $types Item types |
||
115 | * @return array Validated item types |
||
116 | * @throws InvalidArgumentException If there are no valid types |
||
117 | */ |
||
118 | 46 | protected function validateTypes(array $types) |
|
132 | |||
133 | /** |
||
134 | * Validate the item properties |
||
135 | * |
||
136 | * @param array $properties Item properties |
||
137 | * @return PropertyListInterface Validated item properties |
||
138 | * @throws InvalidArgumentException If the property name is empty |
||
139 | */ |
||
140 | 44 | protected function validateProperties(array $properties) |
|
151 | |||
152 | /** |
||
153 | * Return the item types |
||
154 | * |
||
155 | * @return \stdClass[] Item types |
||
156 | */ |
||
157 | 23 | public function getType() |
|
161 | |||
162 | /** |
||
163 | * Return the item ID (if any) |
||
164 | * |
||
165 | * @return string|null Item id |
||
166 | */ |
||
167 | 19 | public function getId() |
|
171 | |||
172 | /** |
||
173 | * Return the item language (if any) |
||
174 | * |
||
175 | * @return string|null Item language |
||
176 | */ |
||
177 | 18 | public function getLanguage() |
|
181 | |||
182 | /** |
||
183 | * Return all item properties |
||
184 | * |
||
185 | * @return PropertyListInterface Item properties list |
||
186 | */ |
||
187 | 21 | public function getProperties() |
|
191 | |||
192 | /** |
||
193 | * Return the values of a particular property |
||
194 | * |
||
195 | * @param string|\stdClass|Iri $name Property name |
||
196 | * @param string|null $profile Property profile |
||
197 | * @return array Item property values |
||
198 | */ |
||
199 | 10 | public function getProperty($name, $profile = null) |
|
211 | |||
212 | /** |
||
213 | * Return whether the value should be considered empty |
||
214 | * |
||
215 | * @return boolean Value is empty |
||
216 | */ |
||
217 | 17 | public function isEmpty() |
|
221 | |||
222 | /** |
||
223 | * Validate a single property |
||
224 | * |
||
225 | * @param \stdClass $property Property |
||
226 | * @return \stdClass Validated property |
||
227 | */ |
||
228 | 33 | protected function validateProperty($property) |
|
249 | |||
250 | /** |
||
251 | * Validate the structure of a property object |
||
252 | * |
||
253 | * @param \stdClass $property Property object |
||
254 | * @throws InvalidArgumentException If the property object is invalid |
||
255 | */ |
||
256 | 33 | protected function validatePropertyStructure($property) |
|
271 | |||
272 | /** |
||
273 | * Validate a property name |
||
274 | * |
||
275 | * @param \stdClass $property Property |
||
276 | * @return string Property name |
||
277 | */ |
||
278 | 31 | protected function validatePropertyName($property) |
|
292 | |||
293 | /** |
||
294 | * Validate a list of property values |
||
295 | * |
||
296 | * @param array $values Property values |
||
297 | * @return array Validated property values |
||
298 | * @throws InvalidArgumentException If the value is not a nested item |
||
299 | */ |
||
300 | 30 | protected function validatePropertyValues(array $values) |
|
322 | |||
323 | /** |
||
324 | * Validate a single item type |
||
325 | * |
||
326 | * @param \stdClass|Iri|string $type Item type |
||
327 | * @return Iri|null Validated item type |
||
328 | * @throws InvalidArgumentException If the item type object is invalid |
||
329 | */ |
||
330 | 46 | protected function validateType($type) |
|
335 | } |
||
336 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.