IbanFieldValidator::isValid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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