Passed
Push — master ( 683828...ff7ee8 )
by
unknown
07:41
created

HasIban   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 36
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIban() 0 3 1
A setIban() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Traits;
6
7
use Doctrine\DBAL\Exception\InvalidArgumentException;
8
use Doctrine\ORM\Mapping as ORM;
9
10
/**
11
 * Trait for all objects with an IBAN (international bank account number)
12
 */
13
trait HasIban
14
{
15
    /**
16
     * @var string
17
     *
18
     * @ORM\Column(type="string", length=34, unique=true, nullable=true)
19
     */
20
    private $iban;
21
22
    /**
23
     * Set the IBAN (international bank account number)
24
     *
25
     * @param string $iban
26
     *
27
     * @throws InvalidArgumentException
28
     */
29 1
    public function setIban(string $iban): void
30
    {
31 1
        $validator = new \Zend\Validator\Iban(['country_code' => 'CH']);
32 1
        if (empty($iban)) {
33
            $this->iban = null;
34 1
        } elseif ($validator->isValid($iban)) {
35 1
            $this->iban = $iban;
36
        } else {
37 1
            throw new InvalidArgumentException('Invalid IBAN number');
38
        }
39 1
    }
40
41
    /**
42
     * Get the IBAN (international bank account number)
43
     *
44
     * @return string
45
     */
46 1
    public function getIban(): string
47
    {
48 1
        return (string) $this->iban;
49
    }
50
}
51