Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
15 / 15
92.31% covered (success)
92.31%
12 / 13
80.00% covered (warning)
80.00%
8 / 10
83.33% covered (warning)
83.33%
5 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Delimiters
100.00% covered (success)
100.00%
15 / 15
92.31% covered (success)
92.31%
12 / 13
80.00% covered (warning)
80.00%
8 / 10
100.00% covered (success)
100.00%
6 / 6
8.51
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 comments
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 brackets
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 values
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 token
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validate
100.00% covered (success)
100.00%
6 / 6
87.50% covered (warning)
87.50%
7 / 8
60.00% covered (warning)
60.00%
3 / 5
100.00% covered (success)
100.00%
1 / 1
3.58
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Quma;
6
7use InvalidArgumentException;
8
9/** @api */
10final 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}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

Delimiters->__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    }
Delimiters->brackets
32        return new self(self::BRACKET_OPEN, self::BRACKET_CLOSE);
33    }
Delimiters->comments
27        return new self(self::COMMENT_OPEN, self::COMMENT_CLOSE);
28    }
Delimiters->token
44    public function token(string $name): string
45    {
46        return $this->open . $name . $this->close;
47    }
Delimiters->validate
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.");
55        if (str_contains($delimiter, "\0")) {
55        if (str_contains($delimiter, "\0")) {
55        if (str_contains($delimiter, "\0")) {
55        if (str_contains($delimiter, "\0")) {
56            throw new InvalidArgumentException(
57                "Static placeholder {$label} delimiter must not contain NUL bytes.",
60    }
Delimiters->values
39            'open' => $this->open,
40            'close' => $this->close,
41        ];
42    }