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

In   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMetadata() 0 10 1
A validate() 0 7 2
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 In 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 not in list of acceptable values');
18
        }
19
20
        return $value;
21
    }
22
23
    public static function getMetadata(): ValidatorMetadata
24
    {
25
        return new ValidatorMetadata(
26
            'In',
27
            "In list",
28
            [
29
                new ValidatorArgs(
30
                    'value',
31
                    '[String!]!',
32
                    'Value'
33
                )
34
            ]
35
        );
36
    }
37
}
38