Completed
Push — master ( 370f9a...949ee8 )
by Albert
03:21
created

Rule::getOption()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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 13
    public function __construct(array $options = [])
27
    {
28 13
        $this->options = $options;
29 13
    }
30
31
    /**
32
     * @return array
33
     */
34 9
    public function getOptions(): array
35
    {
36 9
        return $this->options;
37
    }
38
39
    /**
40
     * @param string $name
41
     * @param mixed $default
42
     *
43
     * @return mixed
44
     */
45 6
    public function getOption(string $name, $default = null)
46
    {
47 6
        return $this->options[$name] ?? $default;
48
    }
49
50
    /**
51
     * @param string $name
52
     * @param $value
53
     *
54
     * @return Rule
55
     */
56 2
    public function setOption(string $name, $value): self
57
    {
58 2
        $this->options[$name] = $value;
59
60 2
        return $this;
61
    }
62
63
    /**
64
     * @return string
65
     */
66
    public function getMessage(): string
67
    {
68
        return $this->message;
69
    }
70
71
    /**
72
     * @param string $message
73
     *
74
     * @return Rule
75
     */
76
    public function setMessage(string $message): self
77
    {
78
        $this->message = $message;
79
80
        return $this;
81
    }
82
83
    /**
84
     * @return string
85
     */
86 2
    public function validatedBy(): string
87
    {
88 2
        return get_class($this) . 'Validator';
89
    }
90
}
91