Passed
Branch monitor-2.5.x (32aff2)
by Tim
01:33
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
cc 5
eloc 15
nc 12
nop 0
dl 0
loc 23
rs 9.4555
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\TestCase\Store\Memcache;
4
5
use \SimpleSAML\Modules\Monitor\State as State;
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