Completed
Push — master ( 20bc61...27627e )
by Tim
01:43
created

Modules::invokeTestSuite()   C

Complexity

Conditions 7
Paths 9

Size

Total Lines 35
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 9
nop 0
dl 0
loc 35
rs 6.7272
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestSuite\Modules;
4
5
use \SimpleSAML\Module\monitor\TestConfiguration as TestConfiguration;
6
use \SimpleSAML\Module\monitor\State as State;
7
use \SimpleSAML\Module\monitor\TestData as TestData;
8
9
final class Modules extends \SimpleSAML\Module\monitor\TestSuiteFactory
10
{
11
    /**
12
     * @var array
13
     */
14
    private $requiredApacheModules = array();
15
16
    /**
17
     * @var array
18
     */
19
    private $availableApacheModules = array();
20
21
    
22
    /**
23
     * @param TestData|null $testData
24
     *
25
     * @return void
26
     */
27
    protected function initialize($testData)
28
    {
29
        $this->requiredApacheModules = $testData->getInput('required');
0 ignored issues
show
Bug introduced by
It seems like $testData is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
30
        $this->availableApacheModules = $testData->getInput('available');
31
        $this->dependencies = $testData->getInput('dependencies');
0 ignored issues
show
Bug introduced by
The property dependencies does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
    }
33
34
35
    /**
36
     * @return void
37
     */
38
    protected function invokeTestSuite()
39
    {
40
        $testResult = new TestResult('Apache', implode(', ', $this->required));
0 ignored issues
show
Bug introduced by
The property required does not seem to exist. Did you mean requiredApacheModules?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
41
        if (is_null($this->available)) {
0 ignored issues
show
Bug introduced by
The property available does not seem to exist. Did you mean availableApacheModules?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
42
            $testResult->setState(State::SKIPPED);
43
            $testResult->setMessage('Unable to verify installed modules');
44
            $this->addTestResult($testResult);
45
        } else {
46
            foreach ($this->required as $module) {
0 ignored issues
show
Bug introduced by
The property required does not seem to exist. Did you mean requiredApacheModules?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
47
                $testData = new TestData([
48
                    'required' => $module,
49
                    'available' => $this->available
0 ignored issues
show
Bug introduced by
The property available does not seem to exist. Did you mean availableApacheModules?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
50
                ]);
51
        
52
                $moduleTest = new TestCase\Module\Apache($this, $testData);
53
                $moduleTestResult = $moduleTest->getTestResult();
54
55
                if ($moduleTestResult->getState() != State::OK) {
56
                    $missing = array();
57
                    while ($dependency = array_search($this->required, $this->dependencies)) {
0 ignored issues
show
Bug introduced by
The property required does not seem to exist. Did you mean requiredApacheModules?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
58
                        if (\SimpleSAML\Module::isModuleEnabled($dependency)) {
59
                            $missing[] = $dependency;
60
                        }
61
                        unset($dependencies[$dependency]);
62
                    }
63
                    if (!empty($missing)) {
64
                        $moduleTestResult->setSubject($moduleTest->getModuleName());
65
                        $moduleTestResult->setMessage('Module not loaded; dependency for ' . implode(', ', $missing));
66
                    }
67
68
                    $this->addTestResult($moduleTestResult);
69
                }
70
            }
71
        }
72
    }
73
}
74