| Total Complexity | 6 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class Regexp |
||
| 11 | { |
||
| 12 | private string $regexp; |
||
| 13 | |||
| 14 | public function __construct(string $regexp) |
||
| 15 | { |
||
| 16 | $this->regexp = $this->isRegexp($regexp) ? $regexp : $this->makeRegexp($regexp); |
||
| 17 | } |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Get expression as string |
||
| 21 | */ |
||
| 22 | public function getRegexp(): string |
||
| 23 | { |
||
| 24 | return $this->regexp; |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Check if this expression matches subject |
||
| 29 | */ |
||
| 30 | public function matches(string $subject): bool |
||
| 31 | { |
||
| 32 | return !!preg_match($this->regexp, $subject); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Check if string is a regular expression |
||
| 37 | */ |
||
| 38 | private function isRegexp(string $input): bool |
||
| 45 | } |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Create regular expression from string |
||
| 49 | */ |
||
| 50 | private function makeRegexp(string $input): string |
||
| 55 | ); |
||
| 56 | } |
||
| 57 | } |
||
| 58 |