Passed
Push — master ( e7ac2a...2583c1 )
by Bruno
11:28 queued 06:12
created

Equals   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 21
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
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 Equals implements ValidatorInterface
13
{
14 2
    public static function validate($value, array $options = [], Datatype $datatype, ?Model $model = null)
15
    {
16 2
        if ($value !== $options['value']) {
17 1
            throw new ValidatorException('Value is not the expected');
18
        }
19
20 1
        return $value;
21
    }
22
23 1
    public static function getMetadata(): ValidatorMetadata
24
    {
25 1
        return new ValidatorMetadata(
26 1
            'Equals',
27 1
            "Match exactly",
28
            [
29 1
                new ValidatorArgs(
30 1
                    'value',
31 1
                    'String!',
32 1
                    'Value'
33
                )
34
            ]
35
        );
36
    }
37
}
38