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 string $year |
||
33 | * @param string $month |
||
34 | * |
||
35 | * @return mixed |
||
36 | */ |
||
37 | 1 | public static function validate(string $year, string $month) |
|
38 | { |
||
39 | 1 | return (new static($year, $month))->isValid(); |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @return bool |
||
44 | */ |
||
45 | 5 | public function isValid() |
|
46 | { |
||
47 | 5 | return $this->isValidYear() |
|
48 | 5 | && $this->isValidMonth() |
|
49 | 5 | && $this->isFeatureDate(); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param $year |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | 5 | protected function setYear($year) |
|
58 | { |
||
59 | 5 | $year = trim($year); |
|
60 | |||
61 | 5 | if (strlen($year) == 2) { |
|
62 | 2 | $year = substr(date('Y'), 0, 2).$year; |
|
63 | } |
||
64 | |||
65 | 5 | $this->year = $year; |
|
66 | |||
67 | 5 | return $this; |
|
68 | } |
||
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 |