Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
10 / 10 |
|
87.50% |
7 / 8 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| RuleRegistry | |
100.00% |
12 / 12 |
|
100.00% |
10 / 10 |
|
87.50% |
7 / 8 |
|
100.00% |
5 / 5 |
7.10 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| withDefaults | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| with | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| withMany | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
|
66.67% |
2 / 3 |
|
100.00% |
1 / 1 |
2.15 | |||
| get | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Sire; |
| 6 | |
| 7 | use Override; |
| 8 | |
| 9 | /** @api */ |
| 10 | final class RuleRegistry implements Contract\RuleRegistry |
| 11 | { |
| 12 | /** @param array<string, Contract\Rule> $rules */ |
| 13 | public function __construct( |
| 14 | private array $rules = [], |
| 15 | private ?Contract\RuleRegistry $fallback = null, |
| 16 | ) {} |
| 17 | |
| 18 | public static function withDefaults(): self |
| 19 | { |
| 20 | return new self([], new DefaultRules()); |
| 21 | } |
| 22 | |
| 23 | public function with(string $name, Contract\Rule $rule): self |
| 24 | { |
| 25 | $rules = $this->rules; |
| 26 | $rules[$name] = $rule; |
| 27 | |
| 28 | return new self($rules, $this->fallback); |
| 29 | } |
| 30 | |
| 31 | /** @param array<string, Contract\Rule> $rules */ |
| 32 | public function withMany(array $rules): self |
| 33 | { |
| 34 | $result = $this; |
| 35 | |
| 36 | foreach ($rules as $name => $rule) { |
| 37 | $result = $result->with($name, $rule); |
| 38 | } |
| 39 | |
| 40 | return $result; |
| 41 | } |
| 42 | |
| 43 | #[Override] |
| 44 | public function get(string $name): ?Contract\Rule |
| 45 | { |
| 46 | if (array_key_exists($name, $this->rules)) { |
| 47 | return $this->rules[$name]; |
| 48 | } |
| 49 | |
| 50 | return $this->fallback?->get($name); |
| 51 | } |
| 52 | } |
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.
| 14 | private array $rules = [], |
| 15 | private ?Contract\RuleRegistry $fallback = null, |
| 16 | ) {} |
| 44 | public function get(string $name): ?Contract\Rule |
| 45 | { |
| 46 | if (array_key_exists($name, $this->rules)) { |
| 47 | return $this->rules[$name]; |
| 50 | return $this->fallback?->get($name); |
| 51 | } |
| 23 | public function with(string $name, Contract\Rule $rule): self |
| 24 | { |
| 25 | $rules = $this->rules; |
| 26 | $rules[$name] = $rule; |
| 27 | |
| 28 | return new self($rules, $this->fallback); |
| 29 | } |
| 20 | return new self([], new DefaultRules()); |
| 21 | } |
| 32 | public function withMany(array $rules): self |
| 33 | { |
| 34 | $result = $this; |
| 35 | |
| 36 | foreach ($rules as $name => $rule) { |
| 36 | foreach ($rules as $name => $rule) { |
| 36 | foreach ($rules as $name => $rule) { |
| 36 | foreach ($rules as $name => $rule) { |
| 37 | $result = $result->with($name, $rule); |
| 38 | } |
| 39 | |
| 40 | return $result; |
| 41 | } |