RegexFieldValidator::describeObject()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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