Passed
Push — master ( bb5c60...87d27f )
by Tim
01:35
created

ServerGroup   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invokeTest() 0 23 5
A initialize() 0 6 1
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\TestCase\Store\Memcache;
4
5
use \SimpleSAML\Modules\Monitor\State as State;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Modules\Monitor\State was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use \SimpleSAML\Modules\Monitor\TestData as TestData;
7
use \SimpleSAML\Modules\Monitor\TestResult as TestResult;
8
9
final class ServerGroup extends \SimpleSAML\Modules\Monitor\TestCaseFactory
10
{
11
    /**
12
     * @var array
13
     */
14
    private $results = array();
15
16
    /**
17
     * @var string|null
18
     */
19
    private $group = null;
20
21
    /**
22
     * @param TestData $testData
23
     *
24
     * @return void
25
     */
26
    protected function initialize($testData)
27
    {
28
        $this->results = $testData->getInputItem('results');
29
        $this->group = $testData->getInputItem('group');
30
31
        parent::initialize($testData);
32
    }
33
34
    /**
35
     * @return void
36
     */
37
    public function invokeTest()
38
    {
39
        $testResult = new TestResult('Memcache Server Group Health', 'Group ' . $this->group);
40
41
        $states = array();
42
        foreach ($this->results as $result) {
43
            $states[] = $result->getState();
44
        }
45
        $state = min($states);
46
        if ($state !== max($states)) {
47
            $state = State::WARNING;
48
        }
49
        $testResult->setState($state);
50
51
        if ($state === State::OK) {
52
            $testResult->setMessage('Group is healthy');
53
        } elseif ($state === State::WARNING) {
54
            $testResult->setMessage('Group is crippled');
55
        } else {
56
            $testResult->setMessage('Group is down');
57
        }
58
59
        $this->setTestResult($testResult);
60
    }
61
}
62