Passed
Push — master ( 3d81f7...f53c15 )
by Bruno
07:26
created

NotIn::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Validator;
4
5
use Formularium\Datatype;
6
use Formularium\Exception\ValidatorException;
7
use Formularium\Model;
8
use Formularium\ValidatorInterface;
9
use Formularium\ValidatorMetadata;
10
use Formularium\ValidatorArgs;
11
12
class NotIn implements ValidatorInterface
13
{
14
    public static function validate($value, array $options = [], Datatype $datatype, ?Model $model = null)
15
    {
16
        if (in_array($value, $options['value'])) {
17
            throw new ValidatorException('Value is in list of forbidden values');
18
        }
19
20
        return $value;
21
    }
22
23
    public static function getMetadata(): ValidatorMetadata
24
    {
25
        return new ValidatorMetadata(
26
            'NotIn',
27
            "Not in list",
28
            [
29
                new ValidatorArgs(
30
                    'value',
31
                    '[String!]!',
32
                    'Value'
33
                )
34
            ]
35
        );
36
    }
37
}
38