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