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\InjectionStrategy; |
||
| 5 | |||
| 6 | use Innmind\Reflection\InjectionStrategyInterface; |
||
| 7 | use Innmind\Reflection\Exception\LogicException; |
||
| 8 | use Innmind\Immutable\StringPrimitive; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Looks for a method named exactly like the property |
||
| 12 | * |
||
| 13 | * Example: |
||
| 14 | * <code> |
||
| 15 | * private $foo; |
||
| 16 | * |
||
| 17 | * public function foo($foo); |
||
| 18 | * </code> |
||
| 19 | */ |
||
| 20 | View Code Duplication | class NamedMethodStrategy implements InjectionStrategyInterface |
|
| 21 | { |
||
| 22 | /** |
||
| 23 | * {@inheritdoc} |
||
| 24 | */ |
||
| 25 | 8 | public function supports($object, string $property, $value): bool |
|
| 26 | { |
||
| 27 | 8 | $refl = new \ReflectionObject($object); |
|
| 28 | |||
| 29 | 8 | $property = (string) (new StringPrimitive($property)) |
|
|
0 ignored issues
–
show
|
|||
| 30 | 8 | ->camelize() |
|
| 31 | 8 | ->lcfirst(); |
|
| 32 | |||
| 33 | 8 | return $refl->hasMethod($property) && |
|
| 34 | 8 | $refl->getMethod($property)->getNumberOfParameters() > 0; |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | 4 | public function inject($object, string $property, $value) |
|
| 41 | { |
||
| 42 | 4 | if (!$this->supports($object, $property, $value)) { |
|
| 43 | 1 | throw new LogicException; |
|
| 44 | } |
||
| 45 | |||
| 46 | 3 | $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...
|
|||
| 47 | 3 | ->camelize() |
|
| 48 | 3 | ->lcfirst(); |
|
| 49 | |||
| 50 | 3 | $object->$property($value); |
|
| 51 | 3 | } |
|
| 52 | } |
||
| 53 |
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.