1 | <?php |
||||
2 | |||||
3 | namespace Validate; |
||||
4 | |||||
5 | use Carbon\Carbon; |
||||
6 | |||||
7 | class Date implements \Validate\Contracts\Validate |
||||
8 | { |
||||
9 | public static function toDatabase($dataOriginal) |
||||
10 | { |
||||
11 | $data = explode('/', $dataOriginal); |
||||
12 | if (isset($data[2])) { |
||||
13 | if($data[1]>12) { |
||||
14 | return $data[2] .'-'. $data[0] .'-'. $data[1]; |
||||
15 | } |
||||
16 | return $data[2] .'-'. $data[1] .'-'. $data[0]; |
||||
17 | } |
||||
18 | return $dataOriginal; |
||||
19 | } |
||||
20 | |||||
21 | public static function toUser($data) |
||||
22 | { |
||||
23 | return $data; |
||||
24 | } |
||||
25 | |||||
26 | public static function validate($dataOriginal) |
||||
27 | { |
||||
28 | $data = self::toDatabase($dataOriginal); |
||||
29 | if (Carbon::createFromFormat('Y-m-d', $data) !== false) { |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
30 | return true; |
||||
31 | } |
||||
32 | return true; |
||||
33 | } |
||||
34 | |||||
35 | |||||
36 | public static function validateYear($year) |
||||
0 ignored issues
–
show
The parameter
$year is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
37 | { |
||||
38 | return true; |
||||
39 | } |
||||
40 | |||||
41 | public static function validateYearPresentOrFuturo($year) |
||||
0 ignored issues
–
show
The parameter
$year is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
42 | { |
||||
43 | return true; |
||||
44 | } |
||||
45 | |||||
46 | public static function validateMonth($month) |
||||
47 | { |
||||
48 | $month = (int) $month; |
||||
49 | if ($month>12) { |
||||
50 | return false; |
||||
51 | } |
||||
52 | return true; |
||||
53 | } |
||||
54 | |||||
55 | public static function yearToDatabase($year) |
||||
56 | { |
||||
57 | $year = (int) $year; |
||||
58 | |||||
59 | if ($year>99) { |
||||
60 | return $year; |
||||
61 | } |
||||
62 | if ($year>50) { |
||||
63 | return 1900+$year; |
||||
64 | } |
||||
65 | return 2000+$year; |
||||
66 | } |
||||
67 | |||||
68 | public static function monthToDatabase($month) |
||||
69 | { |
||||
70 | return $month; |
||||
71 | } |
||||
72 | |||||
73 | public static function isSame(string $to, string $from) |
||||
74 | { |
||||
75 | return (self::toDatabase($to)===self::toDatabase($from)); |
||||
76 | } |
||||
77 | |||||
78 | } |
||||
79 |