Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
15 / 15 |
|
52.63% |
10 / 19 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| DefaultRules | |
100.00% |
16 / 16 |
|
100.00% |
15 / 15 |
|
52.63% |
10 / 19 |
|
100.00% |
1 / 1 |
27.30 | |
100.00% |
1 / 1 |
| get | |
100.00% |
16 / 16 |
|
100.00% |
15 / 15 |
|
52.63% |
10 / 19 |
|
100.00% |
1 / 1 |
27.30 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Sire; |
| 6 | |
| 7 | use Override; |
| 8 | |
| 9 | final class DefaultRules implements Contract\RuleRegistry |
| 10 | { |
| 11 | /** @var array<string, Contract\Rule> */ |
| 12 | private array $loaded = []; |
| 13 | |
| 14 | #[Override] |
| 15 | public function get(string $name): ?Contract\Rule |
| 16 | { |
| 17 | if (array_key_exists($name, $this->loaded)) { |
| 18 | return $this->loaded[$name]; |
| 19 | } |
| 20 | |
| 21 | $rule = match ($name) { |
| 22 | 'required' => new Rule\Required(), |
| 23 | 'email' => new Rule\Email(), |
| 24 | 'minlen' => new Rule\MinLength(), |
| 25 | 'maxlen' => new Rule\MaxLength(), |
| 26 | 'min' => new Rule\Minimum(), |
| 27 | 'max' => new Rule\Maximum(), |
| 28 | 'regex' => new Rule\Regex(), |
| 29 | 'in' => new Rule\Allowed(), |
| 30 | default => null, |
| 31 | }; |
| 32 | |
| 33 | if ($rule !== null) { |
| 34 | $this->loaded[$name] = $rule; |
| 35 | } |
| 36 | |
| 37 | return $rule; |
| 38 | } |
| 39 | } |