IbanField::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 0
Metric Value
c 5
b 1
f 0
dl 0
loc 7
rs 9.4285
cc 3
eloc 5
nc 1
nop 7
1
<?php
2
3
namespace fieldwork\components;
4
5
use fieldwork\sanitizers;
6
use fieldwork\validators;
7
8
class IbanField extends TextField
9
{
10
11
    /**
12
     * Creates a new text field and adds IBAN sanitizer and validator
13
     *
14
     * @param string     $slug
15
     * @param string     $label
16
     * @param string     $value
17
     * @param int|string $errorMsg         The error message to show if the field value is not valid
18
     * @param bool       $convertBban      Whether to permit input of bban number (will be converted using openiban API)
19
     * @param string     $openIbanUsername openiban API username
20
     * @param string     $openIbanPassword openiban API password
21
     */
22
    public function __construct ($slug, $label, $value = '', $errorMsg = validators\IbanFieldValidator::ERROR, $convertBban = false, $openIbanUsername = null, $openIbanPassword = null)
23
    {
24
        parent::__construct($slug, $label, $value, 0);
25
        $this->addSanitizer(new sanitizers\FieldUppercaser());
26
        $this->addSanitizer(new sanitizers\IbanSanitizer($convertBban ? $openIbanUsername : null, $convertBban ? $openIbanPassword : null));
27
        $this->addValidator(new validators\IbanFieldValidator($convertBban, $errorMsg));
28
    }
29
}