Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
2 / 2 |
|
75.00% |
3 / 4 |
|
50.00% |
1 / 2 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Allowed | |
100.00% |
2 / 2 |
|
75.00% |
3 / 4 |
|
50.00% |
1 / 2 |
|
100.00% |
1 / 1 |
1.12 | |
100.00% |
1 / 1 |
| validate | |
100.00% |
2 / 2 |
|
75.00% |
3 / 4 |
|
50.00% |
1 / 2 |
|
100.00% |
1 / 1 |
1.12 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Sire\Rule; |
| 6 | |
| 7 | use Celemas\Sire\Contract; |
| 8 | use Celemas\Sire\DslSplitter; |
| 9 | use Celemas\Sire\Validation; |
| 10 | use Override; |
| 11 | |
| 12 | /** @api */ |
| 13 | final class Allowed implements Contract\Rule |
| 14 | { |
| 15 | public string $message { |
| 16 | get => '{label} must be an allowed value'; |
| 17 | } |
| 18 | |
| 19 | #[Override] |
| 20 | public function validate(Contract\Value $value, string ...$args): Contract\Validation |
| 21 | { |
| 22 | $allowed = DslSplitter::split($args[0] ?? '', ','); |
| 23 | |
| 24 | return Validation::from(in_array($value->value, $allowed, true)); |
| 25 | } |
| 26 | } |