Completed
Push — master ( 1972af...cf5cf8 )
by Rob
02:06
created

CountryWrapper::detect()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 8
nc 5
nop 0
dl 0
loc 13
ccs 0
cts 12
cp 0
crap 30
rs 9.6111
c 0
b 0
f 0
1
<?php
2
3
namespace devtoolboxuk\cerberus\Wrappers;
4
5
class CountryWrapper extends Base
6
{
7
8
    private $detected = 0;
9
10
    public function process()
11
    {
12
        $this->initWrapper($this->setLocalName());
13
        $this->detect();
14
15
        if ($this->detected > 0) {
16
            $this->setScore($this->score);
17
            $this->setResult();
18
        }
19
    }
20
21
    private function setLocalName()
22
    {
23
        $name = str_replace(__NAMESPACE__ . '\\', '', __CLASS__);
24
        return str_replace('Wrapper', '', $name);
25
    }
26
27
    private function detect()
28
    {
29
        $params = $this->getParams();
30
31
        if (empty($params)) {
32
            return;
33
        }
34
35
        foreach ($params as $param) {
36
            if ($param != '') {
37
                $data = explode(":", $param);
38
                if (strpos(strtolower($this->sanitizeReference()), strtolower($data[0])) !== false) {
39
                    $this->setRealScore($data);
40
                }
41
            }
42
        }
43
    }
44
45
    /**
46
     * @param array $data
47
     */
48
    private function setRealScore($data = [])
49
    {
50
        $this->overRideScore($data);
51
52
        if ($this->score > 0) {
53
            $this->detected++;
54
        }
55
    }
56
57
}