Passed
Push — master ( 6e1d07...ee61c0 )
by Adrien
04:17
created

Iban   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 4
b 0
f 0
dl 0
loc 31
ccs 10
cts 12
cp 0.8333
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A equals() 0 3 1
A __toString() 0 3 1
A getIban() 0 3 1
1
<?php
2
namespace Genkgo\Camt;
3
4
use Iban\Validation\Validator;
5
use Iban\Validation\Iban as IbanDetails;
6
7
/**
8
 * Class Iban
9
 * @package Genkgo\Camt
10
 */
11
class Iban
12
{
13
    /**
14
     * @var string
15
     */
16
    private $iban;
17
18 26
    public function __construct(string $iban)
19
    {
20 26
        $iban = new IbanDetails($iban);
21
22 26
        if (!(new Validator)->validate($iban)) {
23 1
            throw new \InvalidArgumentException("Unknown IBAN {$iban}");
24
        }
25
26 25
        $this->iban = $iban->getNormalizedIban();
27 25
    }
28
29 2
    public function getIban(): string
30
    {
31 2
        return $this->iban;
32
    }
33
34 7
    public function __toString(): string
35
    {
36 7
        return $this->iban;
37
    }
38
39
    public function equals($iban): bool
40
    {
41
        return (new IbanDetails($iban))->getNormalizedIban() === $this->iban;
42
    }
43
}
44