Completed
Push — master ( db029f...19202d )
by Restu
16:00
created

RegexRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 24
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
    public function isValid()
21
    {
22
        if ($this->data !== null && !preg_match("/".$this->attributes['arg']."/", $this->data)) {
23
            $this->setErrorMessage($this->attributes["validatorName"], Lang::get("validator.regex", [
24
                'format' => $this->attributes['arg'],
25
                'name' => $this->attributes["name"],
26
                'value' => $this->data
27
            ], "{name} ({value}) is not in the expected format {format}."));
28
29
            return false;
30
        }
31
        return true;
32
    }
33
}
34