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

HasIban   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10

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\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