| @@ 339-359 (lines=21) @@ | ||
| 336 | * @param string $propertyName |
|
| 337 | * @return string|NULL |
|
| 338 | */ |
|
| 339 | protected function detectAccessor($subject, $propertyName) |
|
| 340 | { |
|
| 341 | if (is_array($subject) || ($subject instanceof \ArrayAccess && $subject->offsetExists($propertyName))) { |
|
| 342 | return self::ACCESSOR_ARRAY; |
|
| 343 | } |
|
| 344 | if (is_object($subject)) { |
|
| 345 | $upperCasePropertyName = ucfirst($propertyName); |
|
| 346 | $getter = 'get' . $upperCasePropertyName; |
|
| 347 | if (method_exists($subject, $getter)) { |
|
| 348 | return self::ACCESSOR_GETTER; |
|
| 349 | } |
|
| 350 | if ($this->isExtractableThroughAsserter($subject, $propertyName)) { |
|
| 351 | return self::ACCESSOR_ASSERTER; |
|
| 352 | } |
|
| 353 | if (property_exists($subject, $propertyName)) { |
|
| 354 | return self::ACCESSOR_PUBLICPROPERTY; |
|
| 355 | } |
|
| 356 | } |
|
| 357 | ||
| 358 | return null; |
|
| 359 | } |
|
| 360 | ||
| 361 | /** |
|
| 362 | * Tests whether a property can be extracted through `is*` or `has*` methods. |
|
| @@ 204-224 (lines=21) @@ | ||
| 201 | * @param string $propertyName |
|
| 202 | * @return string|NULL |
|
| 203 | */ |
|
| 204 | protected function detectAccessor($subject, $propertyName) |
|
| 205 | { |
|
| 206 | if (is_array($subject) || ($subject instanceof \ArrayAccess && $subject->offsetExists($propertyName))) { |
|
| 207 | return self::ACCESSOR_ARRAY; |
|
| 208 | } |
|
| 209 | if (is_object($subject)) { |
|
| 210 | $upperCasePropertyName = ucfirst($propertyName); |
|
| 211 | $getter = 'get' . $upperCasePropertyName; |
|
| 212 | if (is_callable([$subject, $getter])) { |
|
| 213 | return self::ACCESSOR_GETTER; |
|
| 214 | } |
|
| 215 | if ($this->isExtractableThroughAsserter($subject, $propertyName)) { |
|
| 216 | return self::ACCESSOR_ASSERTER; |
|
| 217 | } |
|
| 218 | if (property_exists($subject, $propertyName)) { |
|
| 219 | return self::ACCESSOR_PUBLICPROPERTY; |
|
| 220 | } |
|
| 221 | } |
|
| 222 | ||
| 223 | return null; |
|
| 224 | } |
|
| 225 | ||
| 226 | /** |
|
| 227 | * Tests whether a property can be extracted through `is*` or `has*` methods. |
|