Completed
Push — master ( 5d18c7...cabcf3 )
by Hannes
16s queued 13s
created

UndefinedAccount::equals()   B

Complexity

Conditions 10
Paths 49

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 10

Importance

Changes 0
Metric Value
cc 10
eloc 12
nc 49
nop 2
dl 0
loc 17
rs 7.2765
c 0
b 0
f 0
ccs 11
cts 11
cp 1
crap 10

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types = 1);
4
5
namespace byrokrat\banking;
6
7
/**
8
 * Account number implementation for accounts not belonging to a bank
9
 */
10
class UndefinedAccount implements AccountNumber
11
{
12
    use Formatter\FormattableTrait;
13
14
    /**
15
     * @var string
16
     */
17
    private $raw;
18
19
    /**
20
     * @var string Account clearing number
21
     */
22
    private $clearing;
23
24
    /**
25
     * @var string Check digit of the clearing number
26
     */
27
    private $clearingCheckDigit;
28
29
    /**
30
     * @var string Account serial number
31
     */
32
    private $serial;
33
34
    /**
35
     * @var string Check digit
36
     */
37
    private $checkDigit;
38
39 231
    public function __construct(string $raw, string $clearing, string $clearingCheck, string $serial, string $check)
40
    {
41 231
        $this->raw = $raw;
42 231
        $this->clearing = $clearing;
43 231
        $this->clearingCheckDigit = $clearingCheck;
44 231
        $this->serial = $serial;
45 231
        $this->checkDigit = $check;
46 231
    }
47
48 89
    public function getBankName(): string
49
    {
50 89
        return '';
51
    }
52
53 139
    public function getRawNumber(): string
54
    {
55 139
        return $this->raw;
56
    }
57
58 230
    public function getClearingNumber(): string
59
    {
60 230
        return $this->clearing;
61
    }
62
63 189
    public function getClearingCheckDigit(): string
64
    {
65 189
        return $this->clearingCheckDigit;
66
    }
67
68 191
    public function getSerialNumber(): string
69
    {
70 191
        return $this->serial;
71
    }
72
73 189
    public function getCheckDigit(): string
74
    {
75 189
        return $this->checkDigit;
76
    }
77
78
    public function equals(AccountNumber $account, bool $strict = false): bool
79
    {
80 88
        $has = function (string $number): bool {
81 88
            return $number !== '';
82 88
        };
83
84 88
        return (!$this->getBankName() || $this->getBankName() == $account->getBankName())
85 88
            && $this->getClearingNumber() == $account->getClearingNumber()
86 88
            && $this->getSerialNumber() == $account->getSerialNumber()
87 88
            && $this->getCheckDigit() == $account->getCheckDigit()
88 88
            && !(($has($this->getClearingCheckDigit()) xor $has($account->getClearingCheckDigit())) && $strict)
89
            && (
90 87
                !$has($this->getClearingCheckDigit())
91 5
                || !$has($account->getClearingCheckDigit())
92 88
                || $this->getClearingCheckDigit() == $account->getClearingCheckDigit()
93
            );
94
    }
95
96 6
    protected function getFormattable(): AccountNumber
97
    {
98 6
        return $this;
99
    }
100
}
101