Completed
Push — master ( 2bf4df...fd374a )
by Tim
11:35 queued 09:40
created

TestSuiteFactory::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
abstract class TestSuiteFactory extends TestFactory
6
{
7
    /**
8
     * @var array|null
9
     */
10
    private $tests = null;
11
12
    /**
13
     * @param Configuration $configuration
0 ignored issues
show
Documentation introduced by
Should the type for parameter $configuration not be Configuration|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
14
     * @param TestData|null $testData
15
     */
16
    public function __construct($configuration = null, $testData = null)
17
    {
18
        assert($configuration instanceof Configuration || is_null($configuration));
19
        assert($testData instanceof TestData || is_null($configuration));
20
21
        $this->setConfiguration($configuration);
0 ignored issues
show
Bug introduced by
It seems like $configuration defined by parameter $configuration on line 16 can be null; however, SimpleSAML\Module\monito...ory::setConfiguration() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
22
        $this->setTestData($testData);
23
        $this->initialize();
24
        $this->invokeTestSuite();
25
    }
26
27
    /**
28
     * @return void
29
     */
30
    protected function initialize() {}
31
32
    /**
33
     * @param TestFactory $test
34
     *
35
     * @return void
36
     */
37
    protected function addTest($test)
38
    {
39
        assert($test instanceof TestFactory);
40
        $this->tests[] = $test;
41
    }
42
43
    /**
44
     * @return array
45
     */
46
    public function getTests()
47
    {
48
        assert(is_array($this->tests));
49
        return $this->tests;
50
    }
51
52
    /**
53
     * @return void
54
     */
55
    protected function calculateState()
56
    {
57
        $tests = $this->getTests();
58
59
        if (!empty($tests)) {
60
            $overall = array();
61
            foreach ($tests as $test) {
62
                $overall[] = $test->getState();
63
            }
64
            $this->setState(min($overall));
65
        }
66
    }
67
68
    /**
69
     * @return void
70
     */
71
    abstract protected function invokeTestSuite();
72
}
73