AbstractValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 35
c 0
b 0
f 0
ccs 11
cts 14
cp 0.7856
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A setSkipOnEmpty() 0 5 1
A setMessage() 0 5 1
A getMessage() 0 4 1
validate() 0 1 ?
1
<?php declare(strict_types=1);
2
3
namespace indigerd\scenarios\validation\validator;
4
5
abstract class AbstractValidator implements ValidatorInterface
6
{
7
    protected $skipOnEmpty = true;
8
9
    protected $message = 'Validation failed';
10
11 7
    public function __construct(array $params = [])
12
    {
13 7
        foreach ($params as $name => $value) {
14 4
            $accessor = 'set' . \ucfirst($name);
15 4
            if (\method_exists($this, $accessor)) {
16 4
                $this->$accessor($value);
17
            }
18
        }
19 7
    }
20
21
    public function setSkipOnEmpty($value) : self
22
    {
23
        $this->skipOnEmpty = (bool)$value;
24
        return $this;
25
    }
26
27 4
    public function setMessage($message) : self
28
    {
29 4
        $this->message = (string)$message;
30 4
        return $this;
31
    }
32
33 3
    public function getMessage() : string
34
    {
35 3
        return $this->message;
36
    }
37
38
    public abstract function validate($value, array $context = []) : bool;
39
}
40