Card   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A validate() 0 10 2
A toArray() 0 8 1
1
<?php
2
3
namespace PHPieces\ANZGateway\models;
4
5
use PHPieces\ANZGateway\enums\FormFields\CardFields;
6
use PHPieces\ANZGateway\exceptions\CardExpiredException;
7
use DateTime;
8
9
class Card extends Model
10
{
11
    protected static $fields = CardFields::class;
12
13
    /**
14
     * Card number
15
     *
16
     * @var int
17
     */
18
    private $cardNumber;
19
20
    /**
21
     * Card expiry date in the format mm/YY
22
     *
23
     * @var int
24
     */
25
    private $expiryDate;
26
27
    /**
28
     * Security code from back of card
29
     *
30
     * @var int
31
     */
32
    private $securityCode;
33
34
    /**
35
     * Card type, eg. Mastercard, Visa...
36
     * @var string
37
     */
38
    private $cardType;
39
40
    /**
41
     *
42
     * @param int $cardNumber
43
     * @param int $expiryDate
44
     * @param int $securityCode
45
     * @param string $cardType
46
     */
47 15
    public function __construct(int $cardNumber, int $expiryDate, int $securityCode, string $cardType
48
    = '')
49
    {
50 15
        $this->cardType = (string) $cardType;
51
52 15
        $this->cardNumber = (int) $cardNumber;
53
54 15
        $this->expiryDate = (int) $expiryDate;
55
56 15
        $this->securityCode = (int) $securityCode;
57
58 15
        $this->validate();
59 12
    }
60
61 15
    public function validate() : void
62
    {
63 15
        $currentDate = new DateTime();
64
65 15
        $cardDate = DateTime::createFromFormat('ym', $this->expiryDate);
66
67 15
        if ($currentDate > $cardDate) {
68 3
            throw new CardExpiredException("This card has expired");
69
        }
70 12
    }
71
72 6
    public function toArray() : array
73
    {
74
        return [
75 6
            CardFields::CARD_NUMBER        => $this->cardNumber,
76 6
            CardFields::CARD_EXPIRY_DATE   => $this->expiryDate,
77 6
            CardFields::CARD_SECURITY_CODE => $this->securityCode,
78
        ];
79
    }
80
}
81