Passed
Branch feature-unit-tests (b7e185)
by Tim
02:31
created

Monitor::setConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
class Monitor
6
{
7
    /**
8
     * @var TestConfiguration
9
     */
10
    private $configuration;
11
12
    /**
13
     * @var array
14
     */
15
    private $results = array();
16
17
    /**
18
     * @var array
19
     */
20
    private $state = array();
21
22
    /**
23
     * @param TestConfiguration $testConfiguration
24
     */
25
    public function __construct($testConfiguration)
26
    {
27
        $this->setTestConfiguration($testConfiguration);
0 ignored issues
show
Bug introduced by
The method setTestConfiguration() does not exist on SimpleSAML\Module\monitor\Monitor. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        $this->/** @scrutinizer ignore-call */ 
28
               setTestConfiguration($testConfiguration);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
    }
29
30
    /**
31
     * @return void
32
     */
33
    public function invokeTestSuites()
34
    {
35
        $this->invokeModuleCheck();
36
        $this->invokeConfigurationCheck();
37
        $this->invokeStoreCheck();
38
        $this->invokeAuthSourceCheck();
39
        $this->invokeMetadataCheck();
40
    }
41
42
    /**
43
     * @return TestConfiguration
44
     */
45
    public function getConfiguration()
46
    {
47
        assert($this->configuration instanceof TestConfiguration);
48
        return $this->configuration;
49
    }
50
51
    /**
52
     * @param TestConfiguration $testConfiguration
53
     */
54
    private function setConfiguration($testConfiguration)
0 ignored issues
show
Unused Code introduced by
The method setConfiguration() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
55
    {
56
        assert($testConfiguration instanceof TestConfiguration);
57
        $this->configuration = $testConfiguration;
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function getResults()
64
    {
65
        return $this->results;
66
    }
67
68
    /**
69
     * @return integer
70
     */
71
    public function getState()
72
    {
73
        $filtered = array_diff($this->state, array(State::SKIPPED));
74
        return empty($filtered) ? State::NOSTATE : min($filtered);
75
    }
76
77
    /**
78
     * @return void
79
     */
80
    private function invokeModuleCheck()
81
    {
82
        $testsuite = new TestSuite\Modules($this->configuration);
83
        $this->results['modules'] = $testsuite->getArrayizeTestResults();
84
        $this->state[] = $testsuite->calculateState();
85
    }
86
87
    /**
88
     * @return void
89
     */
90
    private function invokeConfigurationCheck()
91
    {
92
        $testsuite = new TestSuite\Configuration($this->configuration);
93
        $this->results['configuration'] = $testsuite->getArrayizeTestResults();
94
        $this->state[] = $testsuite->calculateState();
95
    }
96
97
    /**
98
     * @return void
99
     */
100
    private function invokeStoreCheck()
101
    {
102
        $testsuite = new TestSuite\Store($this->configuration);
103
        $this->results['store'] = $testsuite->getArrayizeTestResults();
104
        $this->state[] = $testsuite->calculateState();
105
    }
106
107
    /**
108
     * @return void
109
     */
110
    private function invokeAuthSourceCheck()
111
    {
112
        $testsuite = new TestSuite\AuthSources($this->configuration);
113
        $testResult = $testsuite->getTestResult();
114
        $this->state[] = $testsuite->calculateState();
115
        $this->results['authsources'] = $testResult->getOutput();
116
    }
117
118
    /**
119
     * @return void
120
     */
121
    private function invokeMetadataCheck()
122
    {
123
        $testsuite = new TestSuite\Metadata($this->configuration);
124
        $testResult = $testsuite->getTestResult();
125
        $this->state[] = $testsuite->calculateState();
126
        $this->results['metadata'] = $testResult->getOutput();
127
    }
128
}
129