Completed
Branch master (2e2c40)
by Rob
01:16
created

Wrapper::pushResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace devtoolboxuk\cerberus\Wrappers;
4
5
use devtoolboxuk\soteria\SoteriaService;
6
7
abstract class Wrapper
8
{
9
10
    private $options = [];
11
    private $results = null;
12
    private $score = 0;
13
    private $realScore = 0;
14
    private $params = [];
15
    private $name;
16
    private $active;
17
    private $reference;
18
19
    protected $soteria;
20
21 4
    function __construct()
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 __construct.

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...
22
    {
23 4
        $this->soteria = new SoteriaService();
24 4
    }
25
26
    function pushResult($result)
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 pushResult.

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...
27
    {
28
        array_unshift($this->results, $result);
29
    }
30
31 4
    function getResult()
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 getResult.

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...
32
    {
33 4
        return $this->results;
34
    }
35
36 2
    public function getRealScore()
37
    {
38 2
        if (!$this->hasRealScore()) {
39
            return 0;
40
        }
41
42 2
        return $this->realScore;
43
    }
44
45 2
    private function hasRealScore()
46
    {
47 2
        return isset($this->realScore);
48
    }
49
50 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...
51
    {
52 4
        $this->reference = $reference;
53 4
        $this->options = $options;
54 4
        return $this;
55
    }
56
57
    function sanitizeReference()
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 sanitizeReference.

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...
58
    {
59
        return str_replace(" ", "", strip_tags(trim($this->getReference())));
60
    }
61
62
63 4
    function getReference()
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 getReference.

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...
64
    {
65 4
        return $this->reference;
66
    }
67
68
    protected function setReference($reference)
69
    {
70
        $this->reference = $reference;
71
        return $this;
72
    }
73
74
    public function inParams($name)
75
    {
76
        if (in_array($name, $this->getParams())) {
77
            return true;
78
        }
79
        return false;
80
    }
81
82
    protected function getParams()
83
    {
84
        return $this->params;
85
    }
86
87 4
    protected function setParams($params)
88
    {
89 4
        $this->params = explode("|", $params);
90 4
        return $this;
91
    }
92
93
    public function getRuleOption($name, $score)
94
    {
95
        if (!$this->hasRuleOption($name)) {
96
            return $score;
97
        }
98
99
        return $this->options[$this->name][$name];
100
    }
101
102
    public function hasRuleOption($name)
103
    {
104
        return isset($this->options[$this->name][$name]);
105
    }
106
107 4
    protected function initWrapper($name)
108
    {
109 4
        $this->setName($name);
110 4
        $this->setRules();
111 4
    }
112
113 4
    function setRules()
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 setRules.

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...
114
    {
115 4
        $this->options = $this->getOption($this->getName());
116
117 4
        $this->setRealScore($this->getOption('score'));
118 4
        $this->setActive($this->getOption('active'));
119 4
        $this->setParams($this->getOption('params'));
120 4
    }
121
122 4
    public function getOption($name)
123
    {
124 4
        if (!$this->hasOption($name)) {
125 2
            return null;
126
        }
127
128 4
        return $this->options[$name];
129
    }
130
131 4
    public function hasOption($name)
132
    {
133 4
        return isset($this->options[$name]);
134
    }
135
136 4
    function getName()
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 getName.

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...
137
    {
138 4
        return $this->name;
139
    }
140
141 4
    protected function setName($name)
142
    {
143 4
        $this->name = $name;
144 4
        return $this;
145
    }
146
147 4
    private function setRealScore($score)
148
    {
149 4
        $this->realScore = $score;
150 4
    }
151
152 4
    private function setActive($active)
153
    {
154 4
        $this->active = $active;
155 4
    }
156
157 2
    protected function setResult()
158
    {
159 2
        if ($this->getActive()) {
160 2
            $this->results[$this->getName()] = $this->getScore();
161 2
            $this->score = $this->getScore();
162
        } 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...
163
            $this->score = 0;
164
        }
165 2
        return $this;
166
    }
167
168 2
    private function getActive()
169
    {
170 2
        return $this->active;
171
    }
172
173 4
    public function getScore()
174
    {
175 4
        if (!$this->hasScore()) {
176
            return 0;
177
        }
178
179 4
        return $this->score;
180
    }
181
182 2
    protected function setScore($score)
183
    {
184 2
        $this->score = $score;
185 2
    }
186
187 4
    private function hasScore()
188
    {
189 4
        return isset($this->score);
190
    }
191
192
}