CardCvc   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 2
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 Illuminate\Contracts\Validation\Rule;
6
7
class CardCvc implements Rule
8
{
9
    const MSG_CARD_CVC_INVALID = 'validation.credit_card.card_cvc_invalid';
10
11
    protected $message;
12
13
    /**
14
     * Credit card number.
15
     *
16
     * @var string
17
     */
18
    protected $card_number;
19
20
    public function __construct($card_number)
21 1
    {
22
        $this->message = static::MSG_CARD_CVC_INVALID;
23 1
        $this->card_number = $card_number;
24 1
    }
25 1
26
    /**
27
     * Determine if the validation rule passes.
28
     *
29
     * @param  string $attribute
30
     * @param  mixed $value
31
     *
32
     * @return bool
33
     */
34
    public function passes($attribute, $value)
35 1
    {
36
        try {
37
            return Factory::makeFromNumber($this->card_number)->isValidCvc($value);
38 1
        } catch (\Exception $ex) {
39 1
            return false;
40 1
        }
41
    }
42
43
    /**
44
     * Get the validation error message.
45
     *
46
     * @return string
47
     */
48
    public function message()
49 1
    {
50
        return trans($this->message);
0 ignored issues
show
Bug Compatibility introduced by
The expression trans($this->message); of type Illuminate\Contracts\Tra...lator|string|array|null adds the type Illuminate\Contracts\Translation\Translator to the return on line 50 which is incompatible with the return type declared by the interface Illuminate\Contracts\Validation\Rule::message of type string|array.
Loading history...
51 1
    }
52
}
53