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

CardExpirationMonth   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 44
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A passes() 0 4 1
A message() 0 4 1
1
<?php
2
3
namespace LVR\CreditCard;
4
5
use LVR\CreditCard\Cards\Card;
6
use Illuminate\Contracts\Validation\Rule;
7
8
class CardExpirationMonth implements Rule
9
{
10
    const MSG_CARD_EXPIRATION_MONT_INVALID = 'validation.credit_card.card_expiation_month_invalid';
11
12
    /**
13
     * Year field name.
14
     *
15
     * @var string
16
     */
17
    protected $year;
18
19
    /**
20
     * CardExpirationMonth constructor.
21
     *
22
     * @param string $year
23
     */
24 1
    public function __construct(string $year)
25
    {
26 1
        $this->year = $year;
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($this->year, $value);
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_MONT_INVALID;
50
    }
51
}
52