RegexFieldValidator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getJsonData() 0 6 1
A isValid() 0 4 1
A describeObject() 0 4 1
1
<?php
2
3
namespace fieldwork\validators;
4
5
class RegexFieldValidator extends FieldValidator
6
{
7
8
    private $pattern,
9
        $localPattern;
10
11
    public function __construct ($pattern, $errorMsg, $localPattern = null)
12
    {
13
        parent::__construct($errorMsg);
14
        $this->pattern      = $pattern;
15
        $this->localPattern = $localPattern !== null ? $localPattern : $pattern;
16
    }
17
18
    public function getJsonData ()
19
    {
20
        return array_merge(parent::getJsonData(), array(
21
            'pattern' => $this->localPattern
22
        ));
23
    }
24
25
    public function isValid ($value)
26
    {
27
        return !!preg_match($this->pattern, $value);
28
    }
29
30
    public function describeObject ()
31
    {
32
        return 'regex';
33
    }
34
35
}