Rule   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 70.59%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 84
ccs 12
cts 17
cp 0.7059
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getOptions() 0 4 1
A getOption() 0 4 1
A setOption() 0 6 1
A getMessage() 0 4 1
A setMessage() 0 6 1
A validatedBy() 0 4 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