Completed
Push — master ( 767608...f936ed )
by Luis Ramón
02:42
created

DateRange::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
cc 3
eloc 4
nc 2
nop 1
crap 12
1
<?php
2
/**
3
 * Created by Michaël Perrin
4
 *
5
 * Source: http://www.michaelperrin.fr/2013/03/19/range-date-validator-for-symfony2/
6
 */
7
8
namespace AppBundle\Validator\Constraints;
9
10
use Symfony\Component\Validator\Constraint;
11
use Symfony\Component\Validator\Exception\MissingOptionsException;
12
13
/**
14
 * @Annotation
15
 */
16
class DateRange extends Constraint
17
{
18
    public $minMessage = 'This date should be greater than {{ limit }}.';
19
    public $maxMessage = 'This date should be less than {{ limit }}.';
20
    public $invalidMessage = 'This value should be a valid date.';
21
    public $min;
22
    public $max;
23
24
    public function __construct($options = null)
25
    {
26
        parent::__construct($options);
27
28
        if (null === $this->min && null === $this->max) {
29
            throw new MissingOptionsException('Either option "min" or "max" must be given for constraint ' . __CLASS__, array('min', 'max'));
30
        }
31
    }
32
}
33