FieldLengthValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 2
c 4
b 0
f 1
lcom 0
cbo 1
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
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
}