Innmind /
Reflection
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | declare(strict_types = 1); |
||
| 3 | |||
| 4 | namespace Innmind\Reflection\ExtractionStrategy; |
||
| 5 | |||
| 6 | use Innmind\Reflection\ExtractionStrategyInterface; |
||
| 7 | use Innmind\Reflection\Exception\LogicException; |
||
| 8 | use Innmind\Immutable\StringPrimitive; |
||
| 9 | |||
| 10 | class GetterStrategy implements ExtractionStrategyInterface |
||
| 11 | { |
||
| 12 | private $getter; |
||
| 13 | |||
| 14 | 5 | public function __construct() |
|
| 15 | { |
||
| 16 | 5 | $this->getter = new StringPrimitive('get%s'); |
|
| 17 | 5 | } |
|
| 18 | |||
| 19 | /** |
||
| 20 | * {@inheritdoc} |
||
| 21 | */ |
||
| 22 | 5 | public function supports($object, string $property): bool |
|
| 23 | { |
||
| 24 | 5 | $refl = new \ReflectionObject($object); |
|
| 25 | 5 | $getter = (string) $this->getter->sprintf( |
|
| 26 | 5 | (string) (new StringPrimitive($property))->camelize() |
|
|
0 ignored issues
–
show
|
|||
| 27 | ); |
||
| 28 | |||
| 29 | 5 | return $refl->hasMethod($getter) && |
|
| 30 | 5 | $refl->getMethod($getter)->getNumberOfRequiredParameters() === 0; |
|
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritdoc} |
||
| 35 | */ |
||
| 36 | 3 | public function extract($object, string $property) |
|
| 37 | { |
||
| 38 | 3 | if (!$this->supports($object, $property)) { |
|
| 39 | 1 | throw new LogicException; |
|
| 40 | } |
||
| 41 | |||
| 42 | 2 | $getter = (string) $this->getter->sprintf( |
|
| 43 | 2 | (string) (new StringPrimitive($property))->camelize() |
|
|
0 ignored issues
–
show
The method
camelize() does not seem to exist on object<Innmind\Immutable\StringPrimitive>.
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||
| 44 | ); |
||
| 45 | |||
| 46 | 2 | return $object->$getter(); |
|
| 47 | } |
||
| 48 | } |
||
| 49 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.