Test Failed
Push — master ( 12df28...ec2761 )
by Ricardo
03:17
created

Date::toUser()   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
use Validate\Traits\FakeNameTrait;
7
8
class Date implements \Validate\Contracts\Validate
9
{
10
    use FakeNameTrait;
11
12
    public static function toDatabase($dataOriginal)
13
    {
14
        $data = explode('/', $dataOriginal);
15
        if (isset($data[2])){
16
            if($data[1]>12){
17
                return $data[2] .'-'. $data[0] .'-'. $data[1];
18
            }            
19
            return $data[2] .'-'. $data[1] .'-'. $data[0];
20
        }
21
        return $dataOriginal;
22
    }
23
24
    public static function toUser($data)
25
    {
26
        return $data;
27
    }
28
29
    public static function validate($dataOriginal)
30
    {
31
        $data = self::toDatabase($dataOriginal);
32
        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...
33
            return true;
34
        }
35
        return true;
36
    }
37
38
39
    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

39
    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...
40
    {
41
        return true;
42
    }
43
44
    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

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