RunLevelExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 14 3
A setRunLevel() 0 4 1
A isStopped() 0 10 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