Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
87.50% |
7 / 8 |
CRAP | |
0.00% |
0 / 1 |
| OptionalToken | |
92.31% |
12 / 13 |
|
87.50% |
7 / 8 |
9.04 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRegexStringLength | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMinimalPossibleLength | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMaximumPossibleLength | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCaseInsensitive | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| toDotAll | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| removeStartAndEndMarkers | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\RegexTools\Parts; |
| 3 | |
| 4 | final class OptionalToken implements RegexPartInterface |
| 5 | { |
| 6 | public function __construct( |
| 7 | public readonly RegexPartInterface $part |
| 8 | ) { |
| 9 | } |
| 10 | |
| 11 | public function __toString(): string |
| 12 | { |
| 13 | return $this->part . '?'; |
| 14 | } |
| 15 | |
| 16 | public function getRegexStringLength(): int |
| 17 | { |
| 18 | return $this->part->getRegexStringLength() + 1; |
| 19 | } |
| 20 | |
| 21 | public function getMinimalPossibleLength(): int |
| 22 | { |
| 23 | return 0; |
| 24 | } |
| 25 | |
| 26 | public function getMaximumPossibleLength(): ?int |
| 27 | { |
| 28 | return $this->part->getMaximumPossibleLength(); |
| 29 | } |
| 30 | |
| 31 | public function toCaseInsensitive(): RegexPartInterface |
| 32 | { |
| 33 | return new OptionalToken( |
| 34 | $this->part->toCaseInsensitive() |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | public function toDotAll(): RegexPartInterface |
| 39 | { |
| 40 | return new OptionalToken( |
| 41 | $this->part->toDotAll() |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | public function removeStartAndEndMarkers(): ?RegexPartInterface |
| 46 | { |
| 47 | $part = $this->part->removeStartAndEndMarkers(); |
| 48 | return $part ? new OptionalToken($part) : null; |
| 49 | } |
| 50 | } |