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 | View Code Duplication | class NamedMethodStrategy implements ExtractionStrategyInterface |
|
| 11 | { |
||
| 12 | /** |
||
| 13 | * {@inheritdoc} |
||
| 14 | */ |
||
| 15 | 5 | public function supports($object, string $property): bool |
|
| 16 | { |
||
| 17 | 5 | $refl = new \ReflectionObject($object); |
|
| 18 | |||
| 19 | 5 | $property = (string) (new StringPrimitive($property)) |
|
|
0 ignored issues
–
show
|
|||
| 20 | 5 | ->camelize() |
|
| 21 | 5 | ->lcfirst(); |
|
| 22 | |||
| 23 | 5 | return $refl->hasMethod($property) && |
|
| 24 | 5 | $refl->getMethod($property)->getNumberOfRequiredParameters() === 0; |
|
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * {@inheritdoc} |
||
| 29 | */ |
||
| 30 | 3 | public function extract($object, string $property) |
|
| 31 | { |
||
| 32 | 3 | if (!$this->supports($object, $property)) { |
|
| 33 | 1 | throw new LogicException; |
|
| 34 | } |
||
| 35 | |||
| 36 | 2 | $property = (string) (new StringPrimitive($property)) |
|
|
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...
|
|||
| 37 | 2 | ->camelize() |
|
| 38 | 2 | ->lcfirst(); |
|
| 39 | |||
| 40 | 2 | return $object->$property(); |
|
| 41 | } |
||
| 42 | } |
||
| 43 |
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.