RegexRule::isValid()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 9
c 1
b 0
f 1
nc 2
nop 0
dl 0
loc 13
ccs 9
cts 9
cp 1
crap 3
rs 9.4285
1
<?php
2
namespace JayaCode\Framework\Core\Validator\Rule;
3
4
use JayaCode\Framework\Core\Lang\Lang;
5
6
/**
7
 * Class RegexRule
8
 * @package JayaCode\Framework\Core\Validator\Rule
9
 */
10
class RegexRule extends Rule
11
{
12
    /**
13
     * @var bool
14
     */
15
    protected $requireAttribute = true;
16
17
    /**
18
     * @return bool
19
     */
20 6
    public function isValid()
21
    {
22 6
        if ($this->data !== null && !preg_match("/".$this->attributes['arg']."/", $this->data)) {
23 6
            $this->setErrorMessage($this->attributes["validatorName"], Lang::get("validator.regex", [
24 6
                'format' => $this->attributes['arg'],
25 6
                'name' => $this->attributes["name"],
26 6
                'value' => $this->data
27 6
            ], "{name} ({value}) is not in the expected format {format}."));
28
29 6
            return false;
30
        }
31 6
        return true;
32
    }
33
}
34