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

MinDate::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
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 MinDate implements ValidatorInterface
14
{
15
    public static function validate($value, array $options = [], ?Model $model = null)
16
    {
17
        $min = $options['value'];
18
        // TODO: now
19
        $val = Respect::date('Y-m-d');
20
        $val->min($min);
21
        if (!$val->validate($value)) {
22
            throw new ValidatorException('Value is too small.');
23
        }
24
25
        return $value;
26
    }
27
28
    public static function getMetadata(): Metadata
29
    {
30
        return new Metadata(
31
            'MinDate',
32
            "Minimum value for dates",
33
            [
34
                new MetadataParameter(
35
                    'value',
36
                    'Date',
37
                    'Value'
38
                )
39
            ]
40
        );
41
    }
42
}
43