Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
15 / 15 |
|
92.31% |
12 / 13 |
|
80.00% |
8 / 10 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Delimiters | |
100.00% |
15 / 15 |
|
92.31% |
12 / 13 |
|
80.00% |
8 / 10 |
|
100.00% |
6 / 6 |
8.51 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| comments | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| brackets | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| values | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| token | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| validate | |
100.00% |
6 / 6 |
|
87.50% |
7 / 8 |
|
60.00% |
3 / 5 |
|
100.00% |
1 / 1 |
3.58 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Quma; |
| 6 | |
| 7 | use InvalidArgumentException; |
| 8 | |
| 9 | /** @api */ |
| 10 | final class Delimiters |
| 11 | { |
| 12 | public const string COMMENT_OPEN = '/*:'; |
| 13 | public const string COMMENT_CLOSE = ':*/'; |
| 14 | public const string BRACKET_OPEN = '[::'; |
| 15 | public const string BRACKET_CLOSE = '::]'; |
| 16 | |
| 17 | public function __construct( |
| 18 | public readonly string $open, |
| 19 | public readonly string $close, |
| 20 | ) { |
| 21 | $this->validate('opening', $this->open); |
| 22 | $this->validate('closing', $this->close); |
| 23 | } |
| 24 | |
| 25 | public static function comments(): self |
| 26 | { |
| 27 | return new self(self::COMMENT_OPEN, self::COMMENT_CLOSE); |
| 28 | } |
| 29 | |
| 30 | public static function brackets(): self |
| 31 | { |
| 32 | return new self(self::BRACKET_OPEN, self::BRACKET_CLOSE); |
| 33 | } |
| 34 | |
| 35 | /** @return array{open: string, close: string} */ |
| 36 | public function values(): array |
| 37 | { |
| 38 | return [ |
| 39 | 'open' => $this->open, |
| 40 | 'close' => $this->close, |
| 41 | ]; |
| 42 | } |
| 43 | |
| 44 | public function token(string $name): string |
| 45 | { |
| 46 | return $this->open . $name . $this->close; |
| 47 | } |
| 48 | |
| 49 | private function validate(string $label, string $delimiter): void |
| 50 | { |
| 51 | if ($delimiter === '') { |
| 52 | throw new InvalidArgumentException("Static placeholder {$label} delimiter must not be empty."); |
| 53 | } |
| 54 | |
| 55 | if (str_contains($delimiter, "\0")) { |
| 56 | throw new InvalidArgumentException( |
| 57 | "Static placeholder {$label} delimiter must not contain NUL bytes.", |
| 58 | ); |
| 59 | } |
| 60 | } |
| 61 | } |