Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
62.50% |
10 / 16 |
|
87.50% |
7 / 8 |
CRAP | |
0.00% |
0 / 1 |
| EscapedCharacter | |
62.50% |
10 / 16 |
|
87.50% |
7 / 8 |
15.27 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRegexStringLength | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMinimalPossibleLength | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMaximumPossibleLength | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCaseInsensitive | |
33.33% |
3 / 9 |
|
0.00% |
0 / 1 |
5.67 | |||
| toDotAll | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| removeStartAndEndMarkers | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\RegexTools\Parts; |
| 3 | |
| 4 | final class EscapedCharacter implements RegexPartInterface |
| 5 | { |
| 6 | public function __construct(public readonly string $character) |
| 7 | { |
| 8 | assert(strlen($character) === 1); |
| 9 | } |
| 10 | |
| 11 | public function getRegexStringLength(): int |
| 12 | { |
| 13 | return 2; |
| 14 | } |
| 15 | |
| 16 | public function __toString(): string |
| 17 | { |
| 18 | return '\\' . $this->character; |
| 19 | } |
| 20 | |
| 21 | public function getMinimalPossibleLength(): int |
| 22 | { |
| 23 | return strlen($this->character); |
| 24 | } |
| 25 | |
| 26 | public function getMaximumPossibleLength(): int |
| 27 | { |
| 28 | return strlen($this->character); |
| 29 | } |
| 30 | |
| 31 | public function toCaseInsensitive(): RegexPartInterface |
| 32 | { |
| 33 | $u = mb_strtoupper($this->character); |
| 34 | if ($u !== $this->character && !in_array($this->character, ['d', 'D', 'w','W', 's', 'S', 'b', 'B', 'A', 'Z'])) { |
| 35 | return new CaptureGroup([ |
| 36 | new MatchOrMatch( |
| 37 | [$this], |
| 38 | [new EscapedCharacter($u)] |
| 39 | ) |
| 40 | ]); |
| 41 | } |
| 42 | |
| 43 | return $this; |
| 44 | } |
| 45 | |
| 46 | public function toDotAll(): RegexPartInterface |
| 47 | { |
| 48 | return $this; |
| 49 | } |
| 50 | |
| 51 | public function removeStartAndEndMarkers(): ?RegexPartInterface |
| 52 | { |
| 53 | return $this; |
| 54 | } |
| 55 | } |