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