Completed
Push — master ( c6c9a7...0c7f9d )
by Albert
08:53
created

Rule::setValidatorAndField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Albert221\Validation;
6
7
abstract class Rule
8
{
9
    use RuleChainTrait;
10
11
    /**
12
     * @var array
13
     */
14
    protected $options;
15
16
    /**
17
     * @var string
18
     */
19
    protected $message;
20
21
    /**
22
     * Rule constructor.
23
     *
24
     * @param array $options
25
     */
26
    public function __construct(array $options = [])
27
    {
28
        $this->options = $options;
29
    }
30
31
    /**
32
     * @return array
33
     */
34 2
    protected function getOptions(): array
35
    {
36 2
        return $this->options;
37 2
    }
38
39
    /**
40
     * @param string $name
41
     * @param $value
42
     *
43
     * @return Rule
44
     */
45
    public function setOption(string $name, $value)
46
    {
47 2
        $this->options[$name] = $value;
48
49 2
        return $this;
50 2
    }
51
52 2
    /**
53
     * @return string
54
     */
55
    public function getMessage(): string
56
    {
57
        return $this->message;
58 2
    }
59
60 2
    /**
61
     * @param string $message
62
     *
63
     * @return Rule
64
     */
65
    public function setMessage(string $message)
66
    {
67
        $this->message = $message;
68
69
        return $this;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function validatedBy(): string
76
    {
77
        return get_class($this) . 'Validator';
78
    }
79
}
80