| Total Complexity | 9 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 5 | ||
| Bugs | 2 | Features | 0 |
| 1 | <?php |
||
| 11 | final class Constant implements ValueTransformer |
||
| 12 | { |
||
| 13 | private const PATTERN = '/^(?P<class>.*)::(?P<constant>.*)$/'; |
||
| 14 | |||
| 15 | public function supports($value): bool |
||
| 16 | { |
||
| 17 | 5 | if (!\is_string($value)) { |
|
| 18 | return false; |
||
| 19 | 5 | } |
|
| 20 | 1 | ||
| 21 | $matches = []; |
||
|
|
|||
| 22 | |||
| 23 | 4 | if (null === $matches = $this->extract($value)) { |
|
| 24 | return false; |
||
| 25 | 4 | } |
|
| 26 | 1 | ||
| 27 | if (!class_exists($matches['class']) && !interface_exists($matches['class'])) { |
||
| 28 | return false; |
||
| 29 | 3 | } |
|
| 30 | 1 | ||
| 31 | $constants = (new ReflectionClass($matches['class'])) |
||
| 32 | ->getConstants() |
||
| 33 | 2 | ; |
|
| 34 | 2 | ||
| 35 | return \array_key_exists($matches['constant'], $constants); |
||
| 36 | } |
||
| 37 | 2 | ||
| 38 | public function transform($value) |
||
| 46 | 1 | ; |
|
| 47 | 1 | } |
|
| 48 | |||
| 49 | /** |
||
| 50 | * @return ?array{class: class-string, constant: string} |
||
| 51 | */ |
||
| 52 | private function extract(string $value): ?array |
||
| 62 | } |
||
| 63 | } |
||
| 64 |