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

CardExpirationMonth   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 49
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

3 Methods

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