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

HasIban::getIban()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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