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
05:16
created

AndorraBban::branchCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function accountNumber()
96
    {
97
        return $this->accountNumber;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function __toString()
104
    {
105
        return $this->bankCode . $this->branchCode . $this->accountNumber;
106
    }
107
108
    /**
109
     * @param $bankCode
110
     *
111
     * @throws InvalidArgumentException
112
     */
113
    private static function validateBankCodeFormat($bankCode)
114
    {
115
        if (! preg_match('/^[\d]{4}$/', $bankCode)) {
116
            throw new InvalidArgumentException('Bank code should be 4 numbers');
117
        }
118
    }
119
120
    /**
121
     * @param $branchCode
122
     *
123
     * @throws InvalidArgumentException
124
     */
125
    private static function validateBranchCodeFormat($branchCode)
126
    {
127
        if (! preg_match('/^[\d]{4}$/', $branchCode)) {
128
            throw new InvalidArgumentException('Branch code should be 4 numbers');
129
        }
130
    }
131
132
    /**
133
     * @param $accountNumber
134
     *
135
     * @throws InvalidArgumentException
136
     */
137
    private static function validateAccountNumberFormat($accountNumber)
138
    {
139
        if (! preg_match('/^[\d]{12}$/', $accountNumber)) {
140
            throw new InvalidArgumentException('Account number should be 10 numbers');
141
        }
142
    }
143
}
144