Completed
Push — master ( 9e5c40...779621 )
by Tim
07:19 queued 05:52
created

TestSuite::getMonitor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
abstract class TestSuite extends TestFactory
0 ignored issues
show
Coding Style introduced by
TestSuite does not seem to conform to the naming convention (^sspmod_monitor_([A-Z][a-zA-Z0-9_]+)+$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
TestSuite does not seem to conform to the naming convention (^Abstract|Factory$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
6
{
7
    private $monitor = null;
8
    private $tests = null;
9
10
    /**
11
     * @param sspmod_monitor_Monitor $monitor
12
     */
13
    public function __construct($monitor, $input)
14
    {
15
        assert($monitor instanceof sspmod_monitor_Monitor);
0 ignored issues
show
Bug introduced by
The class SimpleSAML\Module\monitor\sspmod_monitor_Monitor does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
16
        assert(is_array($input));
17
18
        $this->setMonitor($monitor);
19
        $this->setInput($input);
20
        $this->initialize();
21
        $this->setInput(null);
22
        $this->invokeTestSuite();
23
    }
24
25
    /*
26
     * @return void
27
     */
28
    abstract protected function initialize();
29
30
    /*
31
     * @param sspmod_monitor_Monitor $monitor
32
     *
33
     * @return void
34
     */
35
    private function setMonitor($monitor)
36
    {
37
        assert($monitor instanceof Monitor);
38
        $this->monitor = $monitor;
39
    }
40
41
    /*
42
     * @return sspmod_monitor_Monitor
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use NoType.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
43
     */
44
    public function getMonitor()
45
    {
46
        assert(is_a($this->monitor, 'sspmod_monitor_Monitor'));
47
        return $this->monitor;
48
    }
49
50
    /*
51
     * @return void
52
     */
53
    protected function addTest($test)
54
    {
55
        assert(is_a($test, 'sspmod_monitor_Test'));
56
        $this->tests[] = $test;
57
    }
58
59
    /*
60
     * @return array
61
     */
62
    public function getTests()
63
    {
64
        assert(is_array($this->tests));
65
        return $this->tests;
66
    }
67
68
    /*
69
     * @return void
70
     */
71
    protected function calculateState()
72
    {
73
        $tests = $this->getTests();
74
75
        if (!empty($tests)) {
76
            $overall = array();
77
            foreach ($tests as $test) {
78
                $overall[] = $test->getState();
79
            }
80
            $this->setState(min($overall));
81
        }
82
    }
83
84
    /*
85
     * @return void
86
     */
87
    abstract protected function invokeTestSuite();
88
}
89