Completed
Push — master ( 02b308...987bda )
by Darius
01:28
created

CardExpirationYear::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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