Completed
Push — master ( 4ee2da...f664ca )
by Tim
12:29
created

Monitor   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 112
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A invokeTestSuites() 0 8 1
A getConfiguration() 0 4 1
A getResults() 0 4 1
A getState() 0 5 2
A invokeModuleCheck() 0 6 1
A invokeConfigurationCheck() 0 6 1
A invokeStoreCheck() 0 6 1
A invokeAuthSourceCheck() 0 6 1
A invokeMetadataCheck() 0 6 1
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
class Monitor
6
{
7
    /**
8
     * @var TestConfiguration|null
9
     */
10
    private $configuration = null;
11
12
    /**
13
     * @var array
14
     */
15
    private $results = array();
16
17
    /**
18
     * @var array
19
     */
20
    private $state = array();
21
22
    /**
23
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
24
     */
25
    public function __construct()
26
    {
27
        $this->configuration = new TestConfiguration();
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
0 ignored issues
show
Documentation introduced by
Should the return type not be TestConfiguration|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
44
     */
45
    public function getConfiguration()
46
    {
47
        return $this->configuration;
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function getResults()
54
    {
55
        return $this->results;
56
    }
57
58
    /**
59
     * @return integer
60
     */
61
    public function getState()
62
    {
63
        $filtered = array_diff($this->state, array(State::SKIPPED));
64
        return empty($filtered) ? State::NOSTATE : min($filtered);
65
    }
66
67
    /**
68
     * @return void
69
     */
70
    private function invokeModuleCheck()
71
    {
72
        $testsuite = new TestSuite\Modules($this->configuration);
73
        $this->results['modules'] = $testsuite->getMessages();
74
        $this->state[] = $testsuite->getState();
75
    }
76
77
    /**
78
     * @return void
79
     */
80
    private function invokeConfigurationCheck()
81
    {
82
        $testsuite = new TestSuite\Configuration($this->configuration);
0 ignored issues
show
Bug introduced by
It seems like $this->configuration can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
83
        $this->results['configuration'] = $testsuite->getMessages();
84
        $this->state[] = $testsuite->getState();
85
    }
86
87
    /**
88
     * @return void
89
     */
90
    private function invokeStoreCheck()
91
    {
92
        $testsuite = new TestSuite\Store($this->configuration);
0 ignored issues
show
Bug introduced by
It seems like $this->configuration can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
93
        $this->results['store'] = $testsuite->getMessages();
94
        $this->state[] = $testsuite->getState();
95
    }
96
97
    /**
98
     * @return void
99
     */
100
    private function invokeAuthSourceCheck()
101
    {
102
        $testsuite = new TestSuite\AuthSources($this->configuration);
0 ignored issues
show
Bug introduced by
It seems like $this->configuration can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
103
        $this->results['authsources'] = $testsuite->getMessages();
104
        $this->state[] = $testsuite->getState();
105
    }
106
107
    /**
108
     * @return void
109
     */
110
    private function invokeMetadataCheck()
111
    {
112
        $testsuite = new TestSuite\Metadata($this->configuration);
0 ignored issues
show
Bug introduced by
It seems like $this->configuration can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
113
        $this->results['metadata'] = $testsuite->getMessages();
114
        $this->state[] = $testsuite->getState();
115
    }
116
}
117