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

CardCvc   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 46
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A passes() 0 8 2
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 CardCvc implements Rule
9
{
10
    const MSG_CARD_CVC_INVALID = 'validation.credit_card.card_cvc_invalid';
11
12
    protected $message;
13
14
    /**
15
     * Credit card number.
16
     *
17
     * @var string
18
     */
19
    protected $card_number;
20
21 1
    public function __construct(string $card_number)
22
    {
23 1
        $this->message = static::MSG_CARD_CVC_INVALID;
24 1
        $this->card_number = $card_number;
25 1
    }
26
27
    /**
28
     * Determine if the validation rule passes.
29
     *
30
     * @param  string $attribute
31
     * @param  mixed $value
32
     *
33
     * @return bool
34
     */
35 1
    public function passes($attribute, $value)
36
    {
37
        try {
38 1
            return Factory::makeFromNumber($this->card_number)->isValidCvc($value);
39 1
        } catch (\Exception $ex) {
40 1
            return false;
41
        }
42
    }
43
44
    /**
45
     * Get the validation error message.
46
     *
47
     * @return string
48
     */
49 1
    public function message()
50
    {
51 1
        return $this->message;
52
    }
53
}
54