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

Min   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 45.45%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 22
ccs 5
cts 11
cp 0.4545
rs 10
c 3
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 2
A getMetadata() 0 10 1
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 Min implements ValidatorInterface
14
{
15 16
    public static function validate($value, array $options = [], ?Model $model = null)
16
    {
17 16
        $min = $options['value'];
18 16
        if ($value < $min) {
19 16
            throw new ValidatorException('Value is too small.');
20 16
        }
21
22
        return $value;
23
    }
24
25
    public static function getMetadata(): Metadata
26
    {
27
        return new Metadata(
28
            'Min',
29
            "Minimum value",
30
            [
31
                new MetadataParameter(
32
                    'value',
33
                    'Int|Float',
34
                    'Value'
35
                )
36
            ]
37
        );
38
    }
39
}
40