CreditCard   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 13

7 Methods

Rating   Name   Duplication   Size   Complexity  
A month() 0 3 1
A isSame() 0 3 1
A toUser() 0 3 1
A expirationIsValid() 0 11 4
A validate() 0 11 4
A toDatabase() 0 3 1
A year() 0 3 1
1
<?php
2
3
namespace Validate;
4
5
use Carbon\Carbon;
6
use Validate\Traits\MaskTrait;
7
8
class CreditCard extends \Faker\Provider\Payment implements \Validate\Contracts\Validate
9
{
10
    use MaskTrait;
11
12
    public static function toDatabase($creditCardNumber)
13
    {
14
        return strtoupper(preg_replace('/[^0-9]/', '', $creditCardNumber));
15
    }
16
17
    public static function toUser($creditCardNumber)
18
    {
19
        return strtoupper(preg_replace('/[^0-9]/', '', $creditCardNumber));
20
    }
21
22
    public static function validate($creditCardNumber)
23
    {
24
        $found = false;
25
        foreach (self::$cardParams as $masks){
26
            foreach ($masks as $mask){
27
                if (self::maskIsValidate($creditCardNumber, $mask)) {
28
                    $found = true;
29
                }
30
            }
31
        }
32
        return $found;
33
    }
34
35
    public static function expirationIsValid($mes, $ano)
36
    {
37
        if ((int) Date::yearToDatabase($ano) < (int) Carbon::now()->year) {
38
            return false;
39
        }
40
        if ((int) Date::yearToDatabase($ano) == (int) Carbon::now()->year) {
41
            if ((int) Date::monthToDatabase($mes) < (int) Carbon::now()->month) {
42
                return false;
43
            }
44
        }
45
        return true;
46
    }
47
48
    public static function month($year)
49
    {
50
        return Date::validateMonth($year);
51
    }
52
53
    public static function year($year)
54
    {
55
        return Date::yearToDatabase($year);
56
    }
57
58
    public static function isSame(string $to, string $from)
59
    {
60
        return (self::toDatabase($to)===self::toDatabase($from));
61
    }
62
63
}
64