| Total Complexity | 9 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Coverage | 96.3% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 11 | final class RegExp |
||
| 12 | { |
||
| 13 | private string $pattern; |
||
| 14 | |||
| 15 | 10 | public function __construct(string $pattern) |
|
| 16 | { |
||
| 17 | 10 | if (@\preg_match($pattern, '') === false) { |
|
| 18 | 1 | throw new DomainException($pattern, \preg_last_error()); |
|
| 19 | } |
||
| 20 | |||
| 21 | 9 | $this->pattern = $pattern; |
|
| 22 | 9 | } |
|
| 23 | |||
| 24 | 6 | public static function of(string $pattern): self |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @throws RegexException |
||
| 31 | */ |
||
| 32 | 3 | public function matches(Str $string): bool |
|
| 33 | { |
||
| 34 | 3 | $value = \preg_match($this->pattern, $string->toString()); |
|
| 35 | |||
| 36 | 3 | if ($value === false) { |
|
| 37 | 1 | throw new RegexException('', \preg_last_error()); |
|
| 38 | } |
||
| 39 | |||
| 40 | 2 | return (bool) $value; |
|
| 41 | } |
||
| 42 | |||
| 43 | |||
| 44 | /** |
||
| 45 | * @throws RegexException |
||
| 46 | * |
||
| 47 | * @return Map<scalar, Str> |
||
| 48 | */ |
||
| 49 | 4 | public function capture(Str $string): Map |
|
| 72 | } |
||
| 73 | |||
| 74 | 2 | public function toString(): string |
|
| 79 |