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 | class SetterStrategy implements InjectionStrategyInterface |
||
| 11 | { |
||
| 12 | private $setter; |
||
| 13 | |||
| 14 | 4 | public function __construct() |
|
| 15 | { |
||
| 16 | 4 | $this->setter = new StringPrimitive('set%s'); |
|
| 17 | 4 | } |
|
| 18 | |||
| 19 | /** |
||
| 20 | * {@inheritdoc} |
||
| 21 | */ |
||
| 22 | 8 | public function supports($object, string $property, $value): bool |
|
| 23 | { |
||
| 24 | 8 | $refl = new \ReflectionObject($object); |
|
| 25 | |||
| 26 | 8 | return $refl->hasMethod( |
|
| 27 | 8 | (string) $this->setter->sprintf( |
|
| 28 | 8 | (string) (new StringPrimitive($property))->camelize() |
|
|
0 ignored issues
–
show
|
|||
| 29 | ) |
||
| 30 | ); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * {@inheritdoc} |
||
| 35 | */ |
||
| 36 | 4 | public function inject($object, string $property, $value) |
|
| 37 | { |
||
| 38 | 4 | if (!$this->supports($object, $property, $value)) { |
|
| 39 | 1 | throw new LogicException; |
|
| 40 | } |
||
| 41 | |||
| 42 | 3 | $setter = (string) $this->setter->sprintf( |
|
| 43 | 3 | (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 | 3 | $object->$setter($value); |
|
| 46 | 3 | } |
|
| 47 | } |
||
| 48 |
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.