IbanFieldValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 8
Bugs 1 Features 0
Metric Value
wmc 3
c 8
b 1
f 0
lcom 0
cbo 1
dl 0
loc 20
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A isValid() 0 5 1
1
<?php
2
3
namespace fieldwork\validators;
4
5
class IbanFieldValidator extends RegexFieldValidator
6
{
7
8
    const PATT      = "/^[A-Z]{2}[0-9]{2} [A-Z0-9]{4} [0-9]{4} [0-9]{4}( [0-9]{4})?( [0-9]{2})?$/";
9
    const PATT_BBAN = "/^([A-Z]{2}[0-9]{2} [A-Z0-9]{4} [0-9]{4} [0-9]{4}( [0-9]{4})?( [0-9]{2})?|[0-9]{1,10})$/";
10
    const ERROR     = "Not a valid IBAN";
11
12
    public function __construct ($convertBban = false, $errorMsg = self::ERROR)
13
    {
14
        parent::__construct(
15
            self::PATT, $errorMsg, $convertBban ? self::PATT_BBAN : self::PATT
16
        );
17
    }
18
19
    public function isValid ($value)
20
    {
21
        $sanitized = preg_replace('/\s/', '', $value);
22
        return verify_iban($sanitized, true);
23
    }
24
}
25