HasIban   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 10
c 0
b 0
f 0
dl 0
loc 26
ccs 8
cts 8
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
    #[ORM\Column(type: 'string', length: 34, options: ['default' => ''])]
17
    private string $iban = '';
18
19
    /**
20
     * Set the IBAN (international bank account number).
21
     */
22 2
    public function setIban(string $iban): void
23
    {
24 2
        $iban = str_replace(' ', '', mb_strtoupper($iban));
25
26 2
        $validator = new Iban(['allow_non_sepa' => false]);
27 2
        if (empty($iban) || $validator->isValid($iban)) {
28 2
            $this->iban = $iban;
29
        } else {
30 1
            throw new Exception('Invalid IBAN number');
31
        }
32
    }
33
34
    /**
35
     * Get the IBAN (international bank account number).
36
     */
37 1
    public function getIban(): string
38
    {
39 1
        return $this->iban;
40
    }
41
}
42