1 | <?php |
||
38 | class PropertyAccessor extends RawPropertyAccessor |
||
39 | { |
||
40 | /** |
||
41 | * Reflection information about the composite being accessed |
||
42 | * |
||
43 | * @var ReflectionComposite |
||
44 | */ |
||
45 | protected $reflect; |
||
46 | |||
47 | /** |
||
48 | * Creates the PropertyAccessor for the given object, using the |
||
49 | * given reflection information |
||
50 | * |
||
51 | * @param object $object The object to access |
||
52 | * @param ReflectionComposite $reflect Reflection information about |
||
53 | * the composite |
||
54 | */ |
||
55 | 29 | public function __construct($object, ReflectionComposite $reflect) |
|
61 | |||
62 | /** |
||
63 | * Initializes the given object with the given parameters, enforcing |
||
64 | * the constructor requirements and auto building any left overs |
||
65 | */ |
||
66 | 12 | public function constructObject(...$args) |
|
112 | |||
113 | /** |
||
114 | * Builds a property automatically |
||
115 | * |
||
116 | * @param ReflectionProperty $property The property to build |
||
117 | */ |
||
118 | 4 | protected function buildProperty(ReflectionProperty $property) |
|
130 | |||
131 | /** |
||
132 | * Returns the value of the property |
||
133 | * |
||
134 | * @param string $property The name of the property to get |
||
135 | * @return mixed The value of the property |
||
136 | */ |
||
137 | 7 | public function getValue(string $property) |
|
141 | |||
142 | /** |
||
143 | * Sets the value of a property, enforcing datatype requirements |
||
144 | * |
||
145 | * @param string $property The name of the property to set |
||
146 | * @param mixed $value The value to set |
||
147 | */ |
||
148 | 9 | public function setValue(string $property, $value) |
|
164 | |||
165 | /** |
||
166 | * Sets the value of a property, enforcing datatype requirements |
||
167 | * |
||
168 | * @param ReflectionProperty $property The property to set |
||
169 | * @param mixed $value The value to set |
||
170 | */ |
||
171 | 16 | protected function setAnyValue(ReflectionProperty $property, $value) |
|
172 | { |
||
173 | 16 | $comparator = new TypeComparator(); |
|
174 | |||
175 | 16 | if ($value instanceof Generic) |
|
176 | { |
||
177 | $valueType = $value->getObjectType(); |
||
178 | } |
||
179 | else |
||
180 | { |
||
181 | 16 | $valueType = (new TypeParser())->parseFromType($value); |
|
182 | } |
||
183 | |||
184 | 16 | if ($comparator->compatible($property->type, $valueType)) |
|
185 | { |
||
186 | 14 | $this->setRawValue($property->name, $value); |
|
187 | } |
||
188 | 5 | elseif ($property->type instanceof ScalarType) |
|
189 | { |
||
190 | 4 | $this->setScalarValue($property, $valueType, $value); |
|
191 | } |
||
192 | else |
||
193 | { |
||
194 | 1 | $this->throwError($property, $valueType); |
|
195 | } |
||
196 | 15 | } |
|
197 | |||
198 | /** |
||
199 | * Attempts to set a property which expects a scalar value |
||
200 | * |
||
201 | * @param ReflectionProperty $property The property to set |
||
202 | * @param ScalarType $valueType The scalar type |
||
203 | * @param mixed $value The value to set |
||
204 | */ |
||
205 | 4 | private function setScalarValue |
|
236 | |||
237 | /** |
||
238 | * Throws an IlleglPropertyTypeException |
||
239 | * |
||
240 | * @param ReflectionProperty $property The property being set |
||
241 | * @param AbstractType $valueType The value being set |
||
242 | */ |
||
243 | 1 | private function throwError |
|
257 | } |
||
258 |
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: