Failed Conditions
Push — master ( 01a1d9...02424a )
by Adrien
08:45
created

HasIban::setIban()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 10
cc 3
nc 2
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Traits;
6
7
use Doctrine\ORM\Mapping as ORM;
8
use Ecodev\Felix\Api\Exception;
9
use Laminas\Validator\Iban;
10
11
/**
12
 * Trait for all objects with an IBAN (international bank account number)
13
 */
14
trait HasIban
15
{
16
    /**
17
     * @ORM\Column(type="string", length=34, options={"default" = ""})
18
     */
19
    private string $iban = '';
20
21
    /**
22
     * Set the IBAN (international bank account number)
23
     */
24 1
    public function setIban(string $iban): void
25
    {
26 1
        $iban = str_replace(' ', '', mb_strtoupper($iban));
27
28 1
        $validator = new Iban(['allow_non_sepa' => false]);
29 1
        if (empty($iban) || $validator->isValid($iban)) {
30 1
            $this->iban = $iban;
31
        } else {
32 1
            throw new Exception('Invalid IBAN number');
33
        }
34 1
    }
35
36
    /**
37
     * Get the IBAN (international bank account number)
38
     */
39 1
    public function getIban(): string
40
    {
41 1
        return (string) $this->iban;
42
    }
43
}
44