IbanFieldValidator::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 1
nop 2
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