AbstractValidator::getMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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