1 | <?php |
||
33 | class PropertyAccessor extends RawPropertyAccessor |
||
34 | { |
||
35 | /** |
||
36 | * Reflection information about the composite being accessed |
||
37 | * |
||
38 | * @var ReflectionComposite |
||
39 | */ |
||
40 | protected $reflect; |
||
41 | |||
42 | /** |
||
43 | * Creates the PropertyAccessor for the given object, using the |
||
44 | * given reflection information |
||
45 | * |
||
46 | * @param object $object The object to access |
||
47 | * @param ReflectionComposite $reflect Reflection information about |
||
48 | * the composite |
||
49 | */ |
||
50 | 22 | public function __construct($object, ReflectionComposite $reflect) |
|
56 | |||
57 | /** |
||
58 | * Initializes the given object with the given parameters, enforcing |
||
59 | * the constructor requirements and auto building any left overs |
||
60 | */ |
||
61 | 6 | public function constructObject(...$args) |
|
107 | |||
108 | /** |
||
109 | * Builds a property automatically |
||
110 | * |
||
111 | * @param ReflectionProperty $property The property to build |
||
112 | */ |
||
113 | 4 | protected function buildProperty(ReflectionProperty $property) |
|
125 | |||
126 | /** |
||
127 | * Returns the value of the property |
||
128 | * |
||
129 | * @param string $property The name of the property to get |
||
130 | * @return mixed The value of the property |
||
131 | */ |
||
132 | 6 | public function getValue(string $property) |
|
136 | |||
137 | /** |
||
138 | * Sets the value of a property, enforcing datatype requirements |
||
139 | * |
||
140 | * @param string $property The name of the property to set |
||
141 | * @param mixed $value The value to set |
||
142 | */ |
||
143 | 9 | public function setValue(string $property, $value) |
|
159 | |||
160 | /** |
||
161 | * Sets the value of a property, enforcing datatype requirements |
||
162 | * |
||
163 | * @param ReflectionProperty $property The property to set |
||
164 | * @param mixed $value The value to set |
||
165 | */ |
||
166 | 10 | protected function setAnyValue(ReflectionProperty $property, $value) |
|
177 | |||
178 | /** |
||
179 | * Attempts to set a property with a null value |
||
180 | * |
||
181 | * @param ReflectionProperty $property The property to set |
||
182 | */ |
||
183 | 2 | private function setNullValue(ReflectionProperty $property) |
|
194 | |||
195 | /** |
||
196 | * Attempts to set a property with a non null value |
||
197 | * |
||
198 | * @param ReflectionProperty $property The property to set |
||
199 | * @param mixed $value The value to set |
||
200 | */ |
||
201 | 8 | private function setNonNullValue |
|
241 | |||
242 | /** |
||
243 | * Attempts to set a property which expects a scalar value |
||
244 | * |
||
245 | * @param ReflectionProperty $property The property to set |
||
246 | * @param mixed $value The value to set |
||
247 | * @param string $name The name of the scalar type |
||
248 | * @param callable $cast Method to cast a value to the scalar data |
||
249 | * type |
||
250 | */ |
||
251 | 6 | private function setScalarValue |
|
280 | |||
281 | /** |
||
282 | * Attempts to set a property which expects an object value |
||
283 | * |
||
284 | * @param ReflectionProperty $property The property to set |
||
285 | * @param mixed $value The value to set |
||
286 | */ |
||
287 | 5 | private function setObjectValue |
|
307 | |||
308 | /** |
||
309 | * Attempts to set a property which expects a collection value |
||
310 | * |
||
311 | * @param ReflectionProperty $property The property to set |
||
312 | * @param mixed The value to set |
||
313 | */ |
||
314 | private function setCollectionValue |
||
315 | ( |
||
316 | ReflectionProperty $property, |
||
317 | $value |
||
318 | ) |
||
319 | { |
||
320 | if (is_a($value, \ArrayAccess::class) || is_array($value)) |
||
321 | { |
||
322 | $this->setRawValue($property->name, $value); |
||
323 | } |
||
324 | else |
||
325 | { |
||
326 | $this->throwError($property, 'Collection', $value); |
||
327 | } |
||
328 | } |
||
329 | |||
330 | /** |
||
331 | * Throws an IlleglPropertyTypeException |
||
332 | * |
||
333 | * @param ReflectionProperty $property The property being set |
||
334 | * @param string $expected The expected datatype |
||
335 | * @param string $value The value being set |
||
336 | */ |
||
337 | 1 | private function throwError |
|
352 | } |
||
353 |
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: