Completed
Push — master ( d82441...f18e32 )
by Christian
03:52
created

DateAfter::getRequiredOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\Form\Validator\Constraints;
13
14
use Symfony\Component\Validator\Constraint;
15
use Symfony\Component\Validator\Exception\InvalidOptionsException;
16
17
/**
18
 * @Annotation
19
 *
20
 * @Target({"CLASS", "ANNOTATION"})
21
 */
22
final class DateAfter extends Constraint
23
{
24
    /**
25
     * @var string
26
     */
27
    public $firstField;
28
29
    /**
30
     * @var string
31
     */
32
    public $secondField;
33
34
    /**
35
     * @var string
36
     */
37
    public $message = 'error.second_date_before_first';
38
39
    /**
40
     * @var string
41
     */
42
    public $emptyMessage = 'error.date_part_empty';
43
44
    /**
45
     * @var bool
46
     */
47
    public $required = true;
48
49
    /**
50
     * @param array $options
51
     */
52
    public function __construct($options = null)
53
    {
54
        parent::__construct($options);
55
56
        if ($this->firstField === $this->secondField) {
57
            throw new InvalidOptionsException('The options "firstField" and "secondField" can not be the same for constraint '.__CLASS__, [
58
                'firstField',
59
                'secondField',
60
            ]);
61
        }
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function getRequiredOptions(): array
68
    {
69
        return [
70
            'firstField',
71
            'secondField',
72
        ];
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function getTargets()
79
    {
80
        return self::CLASS_CONSTRAINT;
81
    }
82
}
83