RegexRule   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
wmc 3
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 13 3
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