Completed
Push — master ( f76706...507944 )
by Rob
02:03
created

Wrapper   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 184
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 72.62%

Importance

Changes 0
Metric Value
wmc 33
lcom 1
cbo 1
dl 0
loc 184
ccs 61
cts 84
cp 0.7262
rs 9.76
c 0
b 0
f 0

27 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getRealScore() 0 8 2
A hasRealScore() 0 4 1
A setOptions() 0 6 1
A inParams() 0 7 2
A getParams() 0 4 1
A setParams() 0 5 1
A getRuleOption() 0 8 2
A hasRuleOption() 0 4 1
A getResult() 0 4 1
A pushResult() 0 4 1
A sanitizeReference() 0 4 1
A getReference() 0 4 1
A setReference() 0 5 1
A initWrapper() 0 5 1
A setName() 0 5 1
A setRules() 0 8 1
A getOption() 0 8 2
A hasOption() 0 4 1
A getName() 0 4 1
A setRealScore() 0 4 1
A setActive() 0 4 1
A setResult() 0 10 2
A getActive() 0 4 1
A getScore() 0 8 2
A setScore() 0 4 1
A hasScore() 0 4 1
1
<?php
2
3
namespace devtoolboxuk\cerberus\Wrappers;
4
5
use devtoolboxuk\soteria\SoteriaService;
6
7
abstract class Wrapper
8
{
9
10
    protected $soteria;
11
    private $options = [];
12
    private $results = null;
13
    private $score = 0;
14
    private $realScore = 0;
15
    private $params = [];
16
    private $name;
17
    private $active;
18
    private $reference;
19
20 4
    public function __construct()
21
    {
22 4
        $this->soteria = new SoteriaService();
23 4
    }
24
25 2
    public function getRealScore()
26
    {
27 2
        if (!$this->hasRealScore()) {
28
            return 0;
29
        }
30
31 2
        return $this->realScore;
32
    }
33
34 2
    private function hasRealScore()
35
    {
36 2
        return isset($this->realScore);
37
    }
38
39 4
    function setOptions($reference, $options = [])
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for setOptions.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
40
    {
41 4
        $this->reference = $reference;
42 4
        $this->options = $options;
43 4
        return $this;
44
    }
45
46
    public function inParams($name)
47
    {
48
        if (in_array($name, $this->getParams())) {
49
            return true;
50
        }
51
        return false;
52
    }
53
54
    protected function getParams()
55
    {
56
        return $this->params;
57
    }
58
59 4
    protected function setParams($params)
60
    {
61 4
        $this->params = explode("|", $params);
62 4
        return $this;
63
    }
64
65
    public function getRuleOption($name, $score)
66
    {
67
        if (!$this->hasRuleOption($name)) {
68
            return $score;
69
        }
70
71
        return $this->options[$this->name][$name];
72
    }
73
74
    public function hasRuleOption($name)
75
    {
76
        return isset($this->options[$this->name][$name]);
77
    }
78
79 4
    public function getResult()
80
    {
81 4
        return $this->results;
82
    }
83
84
    protected function pushResult($result)
85
    {
86
        array_unshift($this->results, $result);
87
    }
88
89
    protected function sanitizeReference()
90
    {
91
        return str_replace(" ", "", strip_tags(trim($this->getReference())));
92
    }
93
94 4
    protected function getReference()
95
    {
96 4
        return $this->reference;
97
    }
98
99
    protected function setReference($reference)
100
    {
101
        $this->reference = $reference;
102
        return $this;
103
    }
104
105 4
    protected function initWrapper($name)
106
    {
107 4
        $this->setName($name);
108 4
        $this->setRules();
109 4
    }
110
111 4
    protected function setName($name)
112
    {
113 4
        $this->name = $name;
114 4
        return $this;
115
    }
116
117 4
    private function setRules()
118
    {
119 4
        $this->options = $this->getOption($this->getName());
120
121 4
        $this->setRealScore($this->getOption('score'));
122 4
        $this->setActive($this->getOption('active'));
123 4
        $this->setParams($this->getOption('params'));
124 4
    }
125
126 4
    public function getOption($name)
127
    {
128 4
        if (!$this->hasOption($name)) {
129 2
            return null;
130
        }
131
132 4
        return $this->options[$name];
133
    }
134
135 4
    public function hasOption($name)
136
    {
137 4
        return isset($this->options[$name]);
138
    }
139
140 4
    private function getName()
141
    {
142 4
        return $this->name;
143
    }
144
145 4
    private function setRealScore($score)
146
    {
147 4
        $this->realScore = $score;
148 4
    }
149
150 4
    private function setActive($active)
151
    {
152 4
        $this->active = $active;
153 4
    }
154
155 2
    protected function setResult()
156
    {
157 2
        if ($this->getActive()) {
158 2
            $this->results[$this->getName()] = $this->getScore();
159 2
            $this->score = $this->getScore();
160
        } else {
0 ignored issues
show
Coding Style introduced by
The method setResult uses an else expression. Else is never necessary and you can simplify the code to work without else.
Loading history...
161
            $this->score = 0;
162
        }
163 2
        return $this;
164
    }
165
166 2
    private function getActive()
167
    {
168 2
        return $this->active;
169
    }
170
171 4
    public function getScore()
172
    {
173 4
        if (!$this->hasScore()) {
174
            return 0;
175
        }
176
177 4
        return $this->score;
178
    }
179
180 2
    protected function setScore($score)
181
    {
182 2
        $this->score = $score;
183 2
    }
184
185 4
    private function hasScore()
186
    {
187 4
        return isset($this->score);
188
    }
189
190
}