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