| Total Complexity | 9 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 7 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | final class Constant implements ValueTransformer |
||
| 10 | { |
||
| 11 | private const PATTERN = '/^(.*)::(.*)$/'; |
||
| 12 | |||
| 13 | public function supports(mixed $value): bool |
||
| 14 | { |
||
| 15 | if (!\is_string($value)) { |
||
| 16 | return false; |
||
| 17 | 5 | } |
|
| 18 | |||
| 19 | 5 | $matches = []; |
|
|
|
|||
| 20 | 1 | ||
| 21 | if (null === $matches = $this->extract($value)) { |
||
| 22 | return false; |
||
| 23 | 4 | } |
|
| 24 | |||
| 25 | 4 | [$class, $constant] = $matches; |
|
| 26 | 1 | ||
| 27 | $constants = (new \ReflectionClass($class))->getConstants(); |
||
| 28 | |||
| 29 | 3 | return \array_key_exists($constant, $constants); |
|
| 30 | 1 | } |
|
| 31 | |||
| 32 | public function transform(mixed $value): mixed |
||
| 41 | } |
||
| 42 | 1 | ||
| 43 | /** |
||
| 44 | 1 | * @return ?array{class-string, string} |
|
| 45 | */ |
||
| 46 | 1 | private function extract(string $value): ?array |
|
| 57 | } |
||
| 58 | } |
||
| 59 |