| Total Complexity | 6 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | final class GetterStrategy implements ExtractionStrategy |
||
| 13 | { |
||
| 14 | private Str $getter; |
||
| 15 | |||
| 16 | 6 | public function __construct() |
|
| 19 | 6 | } |
|
| 20 | |||
| 21 | /** |
||
| 22 | * {@inheritdoc} |
||
| 23 | */ |
||
| 24 | 6 | public function supports(object $object, string $property): bool |
|
| 25 | { |
||
| 26 | 6 | $refl = new \ReflectionObject($object); |
|
| 27 | 6 | $getter = $this |
|
| 28 | 6 | ->getter |
|
| 29 | ->sprintf(Str::of($property)->camelize()->ucfirst()->toString()) |
||
| 30 | ->toString(); |
||
| 31 | 6 | ||
| 32 | 4 | if (!$refl->hasMethod($getter)) { |
|
| 33 | return false; |
||
| 34 | } |
||
| 35 | 4 | ||
| 36 | $getter = $refl->getMethod($getter); |
||
| 37 | 4 | ||
| 38 | 1 | if (!$getter->isPublic()) { |
|
| 39 | return false; |
||
| 40 | } |
||
| 41 | 4 | ||
| 42 | return $getter->getNumberOfRequiredParameters() === 0; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | 4 | */ |
|
| 48 | public function extract(object $object, string $property) |
||
| 61 | } |
||
| 62 | } |
||
| 63 |