Completed
Push — master ( 5e307a...7e0fd9 )
by Tim
01:45
created

ModuleSet::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestSuite\Modules;
4
5
use \SimpleSAML\Module\monitor\State as State;
6
use \SimpleSAML\Module\monitor\TestCase as TestCase;
7
use \SimpleSAML\Module\monitor\TestData as TestData;
8
9
final class ModuleSet extends \SimpleSAML\Module\monitor\TestSuiteFactory
10
{
11
    /**
12
     * @var array
13
     */
14
    private $required = array();
15
16
    /**
17
     * @var array
18
     */
19
    private $available = array();
20
 
21
    /**
22
     * @var array
23
     */
24
    private $dependencies = array();
25
26
    /**
27
     * @var string
28
     */
29
    private $type;
30
31
    /**
32
     * @var TestCase
33
     */
34
    private $testCase;
35
36
    /**
37
     * @param TestData $testData
38
     *
39
     * @return void
40
     */
41
    protected function initialize($testData)
42
    {
43
        $this->required = $testData->getInput('required');
0 ignored issues
show
Documentation Bug introduced by
It seems like $testData->getInput('required') of type * is incompatible with the declared type array of property $required.

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...
44
        $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...
45
        $this->dependencies = $testData->getInput('dependencies');
0 ignored issues
show
Documentation Bug introduced by
It seems like $testData->getInput('dependencies') of type * is incompatible with the declared type array of property $dependencies.

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...
46
        $this->type = $testData->getInput('type');
47
        $this->testCase = $testData->getInput('testCase');
48
    }
49
    /**
50
     * @return void
51
     */
52
    protected function invokeTestSuite()
53
    {
54
        $testResult = new TestResult($this->type, implode(', ', $this->required));
55
        if (is_null($this->available)) {
56
            $testResult->setState(State::SKIPPED);
57
            $testResult->setMessage('Unable to verify installed modules');
58
            $this->addTestResult($testResult);
59
        } else {
60
            foreach ($this->required as $module) {
61
                $testData = new TestData([
62
                    'required' => $module,
63
                    'available' => $this->available
64
                ]);
65
        
66
                $moduleTest = new $this->testCase($this, $testData);
67
                $moduleTestResult = $moduleTest->getTestResult();
68
                if ($moduleTestResult->getState() != State::OK) {
69
                    $missing = array();
70
                    while ($dependency = array_search($this->required, $this->dependencies)) {
71
                        if (\SimpleSAML\Module::isModuleEnabled($dependency)) {
72
                            $missing[] = $dependency;
73
                        }
74
                        unset($dependencies[$dependency]);
75
                    }
76
                    if (!empty($missing)) {
77
                        $moduleTestResult->setSubject($moduleTest->getModuleName());
78
                        $moduleTestResult->setMessage('Module not loaded; dependency for ' . implode(', ', $missing));
79
                    }
80
                    $this->addTestResult($moduleTestResult);
81
                }
82
            }
83
        }
84
        $this->calculateState();
85
    }
86
}
87