Passed
Branch master (4b23d6)
by Tim
04:40
created

ServerGroup::invokeTest()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 23
rs 9.4555
c 0
b 0
f 0
cc 5
nc 12
nop 0
1
<?php
2
3
namespace SimpleSAML\Module\Monitor\TestCase\Store\Memcache;
4
5
use SimpleSAML\Module\Monitor\State;
6
use SimpleSAML\Module\Monitor\TestData;
7
use SimpleSAML\Module\Monitor\TestResult;
8
9
final class ServerGroup extends \SimpleSAML\Module\Monitor\TestCaseFactory
10
{
11
    /** @var array */
12
    private $results = [];
13
14
    /** @var string */
15
    private $group;
16
17
18
    /**
19
     * @param \SimpleSAML\Module\Monitor\TestData $testData
20
     *
21
     * @return void
22
     */
23
    protected function initialize(TestData $testData): void
24
    {
25
        $this->results = $testData->getInputItem('results');
26
        $this->group = $testData->getInputItem('group');
27
28
        parent::initialize($testData);
29
    }
30
31
32
    /**
33
     * @return void
34
     */
35
    public function invokeTest(): void
36
    {
37
        $testResult = new TestResult('Memcache Server Group Health', 'Group ' . $this->group);
38
39
        $states = [];
40
        foreach ($this->results as $result) {
41
            $states[] = $result->getState();
42
        }
43
        $state = min($states);
44
        if ($state !== max($states)) {
45
            $state = State::WARNING;
46
        }
47
        $testResult->setState($state);
48
49
        if ($state === State::OK) {
50
            $testResult->setMessage('Group is healthy');
51
        } elseif ($state === State::WARNING) {
52
            $testResult->setMessage('Group is crippled');
53
        } else {
54
            $testResult->setMessage('Group is down');
55
        }
56
57
        $this->setTestResult($testResult);
58
    }
59
}
60