Passed
Branch monitor-2.5.x (8b654c)
by Tim
01:31
created

Module   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAvailable() 0 4 1
A invokeTest() 0 22 4
A initialize() 0 8 1
A getModule() 0 4 1
A getModuleName() 0 11 3
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\TestCase;
4
5
use \SimpleSAML\Modules\Monitor\State as State;
6
use \SimpleSAML\Modules\Monitor\TestData as TestData;
7
use \SimpleSAML\Modules\Monitor\TestResult as TestResult;
8
9
class Module extends \SimpleSAML\Modules\Monitor\TestCaseFactory
10
{
11
    /**
12
     * @var array
13
     */
14
    private $parsed;
15
16
    /**
17
     * @var array
18
     */
19
    private $available;
20
21
    /**
22
     * @var string
23
     */
24
    private $module;
25
26
    /**
27
     * @param TestData $testData
28
     *
29
     * @return void
30
     */
31
    protected function initialize($testData)
32
    {
33
        $this->module = $testData->getInputItem('required');
34
        $this->available = $testData->getInputItem('available');
35
        $this->parsed = explode('|', $this->module);
36
37
        $this->setCategory($testData->getInputItem('type'));
38
        parent::initialize($testData);
39
    }
40
41
    /**
42
     * @return void
43
     */
44
    public function invokeTest()
45
    {
46
        $testResult = new TestResult($this->getCategory(), $this->getModuleName());
47
48
        $state = State::ERROR;
49
        $available = $this->getAvailable();
50
51
        foreach ($this->parsed as $module) {
52
            if (in_array($module, $available)) {
53
                $state = State::OK;
54
                break 1;
55
            }
56
        }
57
58
        if ($state == State::OK) {
59
            $testResult->setMessage('Module loaded');
60
        } else {
61
            $testResult->setMessage('Module not loaded');
62
        }
63
64
        $testResult->setState($state);
65
        $this->setTestResult($testResult);
66
    }
67
68
    /**
69
     * @return array|null
70
     */
71
    private function getAvailable()
72
    {
73
        assert(is_array($this->available));
74
        return $this->available;
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    private function getModule()
81
    {
82
        assert(is_string($this->module));
83
        return $this->module;
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getModuleName()
90
    {
91
        $available = $this->available;
92
93
        foreach ($this->parsed as $module) {
94
            if (in_array($module, $available)) {
95
                return $module;
96
            }
97
        }
98
99
        return $this->getModule();
100
    }
101
}
102