Passed
Push — master ( 68d9d2...a847ca )
by Bruno
05:30
created

Max::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
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\Metadata;
10
use Formularium\MetadataParameter;
11
use Respect\Validation\Validator as Respect;
12
13
class Max implements ValidatorInterface
14
{
15 16
    public static function validate($value, array $options = [], ?Model $model = null)
16
    {
17 16
        $max = $options['value'];
18 16
        if ($value > $max) {
19 16
            throw new ValidatorException('Value is too large.');
20 16
        }
21
22
        return $value;
23
    }
24
25
    public static function getMetadata(): Metadata
26
    {
27
        return new Metadata(
28
            'Max',
29
            "Maximum value",
30
            [
31
                new MetadataParameter(
32
                    'value',
33
                    'Int|Float', // TODO: Mixed
34
                    'Value'
35
                )
36
            ]
37
        );
38
    }
39
}
40