RunLevelExtension::init()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace whm\Smoke\Extensions\SmokeRunLevel;
4
5
use phmLabs\Components\Annovent\Event\Event;
6
use whm\Smoke\Config\Configuration;
7
8
class RunLevelExtension
9
{
10
    private $runLevels = array();
11
12
    private $currentRunLevel;
13
14
    public function init(Configuration $_configuration, $runLevel)
15
    {
16
        $configArray = $_configuration->getConfigArray();
17
        $rulesArray = $configArray['rules'];
18
        $this->currentRunLevel = $runLevel;
19
20
        foreach ($rulesArray as $key => $ruleElement) {
21
            if (array_key_exists('runLevel', $ruleElement)) {
22
                $this->runLevels[$key] = (int) ($ruleElement['runLevel']);
23
            } else {
24
                $this->runLevels[$key] = 0;
25
            }
26
        }
27
    }
28
29
    public function setRunLevel($runLevel)
30
    {
31
        $this->currentRunLevel = (int) $runLevel;
32
    }
33
34
    /**
35
     * @Event("Scanner.CheckResponse.isFiltered")
36
     */
37
    public function isStopped(Event $event, $ruleName)
38
    {
39
        if ($this->runLevels[$ruleName] > $this->currentRunLevel) {
40
            $event->setProcessed();
41
42
            return true;
43
        }
44
45
        return false;
46
    }
47
}
48