Test Failed
Push — master ( d459cc...07a257 )
by Rob
03:07
created

CountryWrapper::setRealScore()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 1
dl 0
loc 13
ccs 0
cts 0
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace devtoolboxuk\cerberus\Wrappers;
4
5
class CountryWrapper extends Wrapper
6
{
7
8
    private $detected = 0;
9
    private $score = 0;
10
11
    public function process()
12
    {
13
        $this->initWrapper($this->setLocalName());
14
        $this->detect();
15
16
        if ($this->detected > 0) {
17
            $this->setScore($this->score);
18
            $this->setResult();
19
        }
20
    }
21
22
    private function setLocalName()
23
    {
24
        $name = str_replace(__NAMESPACE__ . '\\', '', __CLASS__);
25
        return str_replace('Wrapper', '', $name);
26
    }
27
28
    private function detect()
29
    {
30
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
31
32
        $params = $this->getParams();
33
        if (empty($params)) {
34
            return;
35
        }
36
37
        foreach ($params as $param) {
38
            if ($param != '') {
39
                $data = explode(":", $param);
40
                if (strpos(strtolower($this->sanitizeReference()), strtolower($data[0])) !== false) {
41
                    $this->setRealScore($data[1]);
0 ignored issues
show
Bug introduced by
$data[1] of type string is incompatible with the type array expected by parameter $data of devtoolboxuk\cerberus\Wr...Wrapper::setRealScore(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

41
                    $this->setRealScore(/** @scrutinizer ignore-type */ $data[1]);
Loading history...
42
                }
43
            }
44
        }
45
    }
46
47
    /**
48
     * @param array $data
49
     */
50
    private function setRealScore($data = [])
51
    {
52
53
        $sanitise = $this->soteria->sanitise(true);
54
        $this->score = $this->getRealScore();
55
56
        if (isset($data[1])) {
57
            $sanitise->disinfect($data[1], 'int');
58
            $this->score = (int)$sanitise->result()->getOutput();
59
        }
60
61
        if ($this->score > 0) {
62
            $this->detected++;
63
        }
64
    }
65
66
}