FieldLengthValidator::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 1
nop 5
1
<?php
2
3
namespace fieldwork\validators;
4
5
class FieldLengthValidator extends RegexFieldValidator
6
{
7
8
    /**
9
     * @param int    $min          The minimum number of allowed characters
10
     * @param int    $max          The maximum number of allowed characters
11
     * @param string $allowed      The allowed characters as a regex sequence
12
     * @param string $error        The string to display if the field does not pass validation
13
     * @param bool   $requireInput If false, the user can also leave the field empty
14
     */
15
    public function __construct ($min, $max, $allowed = ".", $error = "Input must consist of at least %d and no more than %d characters", $requireInput = true)
16
    {
17
        parent::__construct("/^(" . $allowed . "{" . $min . "," . $max . "})" . ($requireInput ? "" : "?") . "$/", sprintf($error, $min, $max));
18
    }
19
20
}