Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Allowed
100.00% covered (success)
100.00%
2 / 2
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
1.12
100.00% covered (success)
100.00%
1 / 1
 validate
100.00% covered (success)
100.00%
2 / 2
75.00% covered (warning)
75.00%
3 / 4
50.00% covered (danger)
50.00%
1 / 2
100.00% covered (success)
100.00%
1 / 1
1.12
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Sire\Rule;
6
7use Celemas\Sire\Contract;
8use Celemas\Sire\DslSplitter;
9use Celemas\Sire\Validation;
10use Override;
11
12/** @api */
13final 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}