| Total Complexity | 7 |
| Total Lines | 36 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class AnsiColorParser implements IAnsiColorParser |
||
| 14 | { |
||
| 15 | private const FORMAT = '/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/'; |
||
| 16 | |||
| 17 | public function __construct( |
||
| 20 | } |
||
| 21 | |||
| 22 | public function parseColor(IColor|null|string $color): string |
||
| 23 | { |
||
| 24 | if ($color === '' || $color === null) { |
||
| 25 | return ''; |
||
| 26 | } |
||
| 27 | |||
| 28 | self::assertValid($color); |
||
| 29 | |||
| 30 | return $this->converter->convert($color); |
||
|
|
|||
| 31 | } |
||
| 32 | |||
| 33 | private static function assertValid(IColor|string $color): void |
||
| 34 | { |
||
| 35 | match (true) { |
||
| 36 | self::correctFormat($color) => null, |
||
| 37 | default => throw new InvalidArgumentException( |
||
| 38 | sprintf('Invalid color format: "%s".,', $color) |
||
| 39 | ), |
||
| 40 | }; |
||
| 41 | } |
||
| 42 | |||
| 43 | private static function correctFormat(IColor|string $color): bool |
||
| 49 | } |
||
| 50 | } |
||
| 51 |