1 | <?php |
||
7 | class ExpirationDateValidator |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $year; |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $month; |
||
18 | |||
19 | /** |
||
20 | * ExpirationDateValidator constructor. |
||
21 | * |
||
22 | * @param string $year |
||
23 | * @param string $month |
||
24 | */ |
||
25 | 5 | public function __construct(string $year, string $month) |
|
30 | |||
31 | /** |
||
32 | * @param $year |
||
33 | * |
||
34 | * @return $this |
||
35 | */ |
||
36 | 5 | protected function setYear($year) |
|
37 | { |
||
38 | 5 | $year = trim($year); |
|
39 | |||
40 | 5 | if (strlen($year) == 2) { |
|
41 | 2 | $year = substr(date('Y'), 0, 2).$year; |
|
42 | } |
||
43 | |||
44 | 5 | $this->year = $year; |
|
45 | |||
46 | 5 | return $this; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * @param string $year |
||
51 | * @param string $month |
||
52 | * |
||
53 | * @return mixed |
||
54 | */ |
||
55 | 1 | public static function validate(string $year, string $month) |
|
59 | |||
60 | /** |
||
61 | * @return bool |
||
62 | */ |
||
63 | 5 | public function isValid() |
|
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | 5 | protected function month() |
|
77 | |||
78 | /** |
||
79 | * @return bool |
||
80 | */ |
||
81 | 5 | protected function isValidYear() |
|
88 | |||
89 | /** |
||
90 | * @return bool |
||
91 | */ |
||
92 | 5 | protected function isValidMonth() |
|
98 | |||
99 | /** |
||
100 | * @return bool |
||
101 | */ |
||
102 | 5 | protected function isFeatureDate() |
|
108 | } |
||
109 |