Completed
Push — master ( 71a222...c936d6 )
by Darius
06:35
created

CardExpirationYear::passes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 3
cts 5
cp 0.6
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2.2559
1
<?php
2
3
namespace LVR\CreditCard;
4
5
use Illuminate\Contracts\Validation\Rule;
6
7
class CardExpirationYear implements Rule
8
{
9
    const MSG_CARD_EXPIRATION_YEAR_INVALID = 'validation.credit_card.card_expiation_year_invalid';
10
11
    /**
12
     * Month field name.
13
     *
14
     * @var string
15
     */
16
    protected $month;
17
18
    /**
19
     * CardExpirationYear constructor.
20
     *
21
     * @param string $month
22
     */
23 1
    public function __construct(string $month)
24
    {
25 1
        $this->month = $month;
26 1
    }
27
28
    /**
29
     * Determine if the validation rule passes.
30
     *
31
     * @param  string $attribute
32
     * @param  mixed $value
33
     *
34
     * @return bool
35
     */
36 1
    public function passes($attribute, $value)
37
    {
38
        try {
39 1
            return (new ExpirationDateValidator($value, $this->month))
40 1
                ->isValid();
41
        } catch (\Exception $e) {
42
            return false;
43
        }
44
    }
45
46
    /**
47
     * Get the validation error message.
48
     *
49
     * @return string
50
     */
51 1
    public function message()
52
    {
53 1
        return static::MSG_CARD_EXPIRATION_YEAR_INVALID;
54
    }
55
}
56