Completed
Push — master ( 43e282...5c8489 )
by Tim
01:37
created

Module   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 92
rs 10
wmc 10
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 8 1
B invokeTest() 0 23 4
A getAvailable() 0 5 1
A getModule() 0 5 1
A getModuleName() 0 12 3
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestCase;
4
5
use \SimpleSAML\Module\monitor\State as State;
6
use \SimpleSAML\Module\monitor\TestData as TestData;
7
8
class Module extends \SimpleSAML\Module\monitor\TestCaseFactory
9
{
10
    /**
11
     * @var array
12
     */
13
    private $parsed = array();
14
15
    /**
16
     * @var array
17
     */
18
    private $available = array();
19
20
    /**
21
     * @var string
22
     */
23
    private $module;
24
25
    /**
26
     * @var TestData $testData
27
     *
28
     * @return void
29
     */
30
    protected function initialize($testData = null)
31
    {
32
        $this->module = $testData->getInput('required');
33
        $this->available = $testData->getInput('available');
0 ignored issues
show
Documentation Bug introduced by
It seems like $testData->getInput('available') of type * is incompatible with the declared type array of property $available.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
        $this->parsed = explode('|', $this->module);
35
36
        parent::initialize($testData);
37
    }
38
39
    /**
40
     * @return void
41
     */
42
    protected function invokeTest()
43
    {
44
        $testResult = new TestResult($this->getCategory(), $this->getModuleName());
45
46
        $state = State::ERROR;
47
        $available = $this->getAvailable();
48
49
        foreach ($this->parsed as $module) {
50
            if (in_array($module, $available)) {
51
                $state = State::OK;
52
                break 1;
53
            }
54
        }
55
56
        if ($state == State::OK) {
57
            $msg = 'Module loaded';
0 ignored issues
show
Unused Code introduced by
$msg is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
        } else {
59
            $msg = 'Module not loaded';
0 ignored issues
show
Unused Code introduced by
$msg is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
60
        }
61
62
        $testResult->setState($state);
63
        $this->setTestResult($state);
64
    }
65
66
    /**
67
     * @return array|null
68
     */
69
    private function getAvailable()
70
    {
71
        assert(is_array($this->available));
72
        return $this->available;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    private function getModule()
79
    {
80
        assert(is_string($this->module));
81
        return $this->module;
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function getModuleName()
88
    {
89
        $available = $this->available;
90
91
        foreach ($this->parsed as $module) {
92
            if (in_array($module, $available)) {
93
                return $module;
94
            }
95
        }
96
97
        return $this->getModule();
98
    }
99
}
100