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

MinDate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 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 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