GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#12)
by
unknown
04:58
created

AndorraBban::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 0
cts 12
cp 0
rs 9.4285
cc 1
eloc 10
nc 1
nop 3
crap 2
1
<?php
2
3
namespace IbanGenerator\Bban;
4
5
use InvalidArgumentException;
6
7
class AndorraBban implements BbanInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $bankCode;
13
14
    /**
15
     * @var string
16
     */
17
    private $branchCode;
18
19
    /**
20
     * @var string
21
     */
22
    private $accountNumber;
23
24
    /**
25
     * AndorraBban constructor.
26
     *
27
     * @param string $bankCode
28
     * @param string $branchCode
29
     * @param string $accountNumber
30
     *
31
     * @throws InvalidArgumentException
32
     */
33
    public function __construct(
34
        $bankCode,
35
        $branchCode,
36
        $accountNumber
37
    ) {
38
        self::validateBankCodeFormat($bankCode);
39
        self::validateBranchCodeFormat($branchCode);
40
        self::validateAccountNumberFormat($accountNumber);
41
42
        $this->bankCode = $bankCode;
43
        $this->branchCode = $branchCode;
44
        $this->accountNumber = $accountNumber;
45
    }
46
47
    /**
48
     * @param string $bban
49
     *
50
     * @throws InvalidArgumentException
51
     *
52
     * @return static
53
     */
54
    public static function fromString($bban)
55
    {
56
        $bban = preg_replace('/[^0-9a-zA-Z]+/', '', $bban);
57
58
        if (! preg_match('/^[\d]{20}$/', $bban)) {
59
            throw new InvalidArgumentException('Bban should be 20 numbers');
60
        }
61
62
        $bankCode = substr($bban, 0, 4);
63
        $branchCode = substr($bban, 4, 4);
64
        $accountNumber = substr($bban, 8, 12);
65
66
        return new static($bankCode, $branchCode, $accountNumber);
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function bankCode()
73
    {
74
        return $this->bankCode;
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function branchCode()
81
    {
82
        return $this->bankCode;
83
    }
84
85
    /**
86
     * @return string
87
     */
88
    public function checkDigits()
89
    {
90
        return null;
91
    }
92
93
    /**
94
     * @return string
95
     */
96
    public function accountNumber()
97
    {
98
        return $this->accountNumber;
99
    }
100
101
    /**
102
     * @return string
103
     */
104
    public function __toString()
105
    {
106
        return $this->bankCode . $this->branchCode . $this->accountNumber;
107
    }
108
109
    /**
110
     * @param $bankCode
111
     *
112
     * @throws InvalidArgumentException
113
     */
114
    private static function validateBankCodeFormat($bankCode)
115
    {
116
        if (! preg_match('/^[\d]{4}$/', $bankCode)) {
117
            throw new InvalidArgumentException('Bank code should be 4 numbers');
118
        }
119
    }
120
121
    /**
122
     * @param $branchCode
123
     *
124
     * @throws InvalidArgumentException
125
     */
126
    private static function validateBranchCodeFormat($branchCode)
127
    {
128
        if (! preg_match('/^[\d]{4}$/', $branchCode)) {
129
            throw new InvalidArgumentException('Branch code should be 4 numbers');
130
        }
131
    }
132
133
    /**
134
     * @param $accountNumber
135
     *
136
     * @throws InvalidArgumentException
137
     */
138
    private static function validateAccountNumberFormat($accountNumber)
139
    {
140
        if (! preg_match('/^[\d]{12}$/', $accountNumber)) {
141
            throw new InvalidArgumentException('Account number should be 10 numbers');
142
        }
143
    }
144
}