Max::getMetadata()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
ccs 8
cts 8
cp 1
crap 1
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 4
            throw new ValidatorException('Value is too large.');
20
        }
21
22 12
        return $value;
23
    }
24
25 1
    public static function getMetadata(): Metadata
26
    {
27 1
        return new Metadata(
28 1
            'Max',
29 1
            "Maximum value",
30
            [
31 1
                new MetadataParameter(
32 1
                    'value',
33 1
                    'Int|Float', // TODO: Mixed
34 1
                    'Value'
35
                )
36
            ]
37
        );
38
    }
39
}
40