Test Failed
Push — master ( f47101...348e9e )
by Ricardo
02:03
created

Date::validateYearPresentOrFuturo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Validate;
4
5
use Carbon\Carbon;
6
7
use Validate\Traits\FakeNameTrait;
8
9
class Date implements \Validate\Contracts\Validate
10
{
11
    use FakeNameTrait;
12
13
    public static function toDatabase($dataOriginal)
14
    {
15
        $data = explode('/', $dataOriginal);
16
        if (isset($data[2])){
17
            if($data[1]>12){
18
                return $data[2] .'-'. $data[0] .'-'. $data[1];
19
            }            
20
            return $data[2] .'-'. $data[1] .'-'. $data[0];
21
        }
22
        return $dataOriginal;
23
    }
24
25
    public static function toUser($data)
26
    {
27
        return $data;
28
    }
29
30
    public static function validate($dataOriginal)
31
    {
32
        $data = self::toDatabase($dataOriginal);
33
        if (Carbon::createFromFormat('Y-m-d', $data) !== false) {
0 ignored issues
show
introduced by
The condition Carbon\Carbon::createFro...-m-d', $data) !== false is always true.
Loading history...
34
            return true;
35
        }
36
        return true;
37
    }
38
39
40
    public static function validateYear($year)
0 ignored issues
show
Unused Code introduced by
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 ignore-unused  annotation

40
    public static function validateYear(/** @scrutinizer ignore-unused */ $year)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
41
    {
42
        return true;
43
    }
44
45
    public static function validateYearPresentOrFuturo($year)
0 ignored issues
show
Unused Code introduced by
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 ignore-unused  annotation

45
    public static function validateYearPresentOrFuturo(/** @scrutinizer ignore-unused */ $year)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46
    {
47
        return true;
48
    }
49
50
    public static function validateMonth($month)
51
    {
52
        $month = (int) $month;
53
        if ($month>12) {
54
            return false;
55
        }
56
        return true;
57
    }
58
59
    public static function yearToDatabase($year)
60
    {
61
        $year = (int) $year;
62
        
63
        if ($year>99) {
64
            return $year;
65
        }
66
        if ($year>50){
67
            return 1900+$year;
68
        }
69
        return 2000+$year;
70
    }
71
72
    public static function isSame(string $to, string $from)
73
    {
74
        return (self::toDatabase($to)===self::toDatabase($from));
75
    }
76
77
}
78