Total Complexity | 7 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | final class RegexChecker |
||
19 | { |
||
20 | public function isRegexLike(string $value): bool |
||
21 | { |
||
22 | $valueLength = strlen($value); |
||
23 | |||
24 | if ($valueLength < 2) { |
||
25 | return false; |
||
26 | } |
||
27 | |||
28 | $firstCharacter = $value[0]; |
||
29 | $lastCharacter = $value[$valueLength - 1]; |
||
30 | |||
31 | if ($firstCharacter !== $lastCharacter) { |
||
32 | return false; |
||
33 | } |
||
34 | |||
35 | $trimmedValue = trim($value, $firstCharacter); |
||
36 | |||
37 | if (strlen($trimmedValue) !== ($valueLength - 2)) { |
||
38 | return false; |
||
39 | } |
||
40 | |||
41 | if (str_contains($trimmedValue, $firstCharacter)) { |
||
42 | return false; |
||
43 | } |
||
44 | |||
45 | return true; |
||
46 | } |
||
47 | |||
48 | public function validateRegex(string $regex): ?string |
||
58 | ); |
||
59 | } |
||
61 |