Completed
Branch master (ed2a4c)
by Tim
01:51
created

ServerGroup::invokeTest()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 15
c 1
b 0
f 0
nc 12
nop 0
dl 0
loc 22
rs 8.6737
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestCase\Store\Memcache;
4
5
use \SimpleSAML\Module\monitor\State as State;
6
use \SimpleSAML\Module\monitor\TestData as TestData;
7
8
final class ServerGroup extends \SimpleSAML\Module\monitor\TestCaseFactory
9
{
10
    /**
11
     * @var array
12
     */
13
    private $tests = array();
14
15
    /**
16
     * @var string|null
17
     */
18
    private $group = null;
19
20
    /**
21
     * @param TestData $testData
22
     *
23
     * @return void
24
     */
25
    protected function initialize($testData)
26
    {
27
        $this->tests = \SimpleSAML\Utils\Array::Arrayize($testData->getInput('tests'));
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_STRING
Loading history...
28
        $this->group = $testData->getInput('group');
29
30
        parent::initialize($testData);
31
    }
32
33
    /**
34
     * @return void
35
     */
36
    protected function invokeTest()
37
    {
38
        $states = array();
39
        foreach ($this->tests as $server) {
40
            $states[] = $server->getState();
41
        }
42
        $state = min($states);
43
        $this->setState($state);
44
45
        if ($state === State::OK) {
46
            $this->addMessage(State::OK, 'Memcache Server Group Health', 'Group ' . $this->group, 'Group is healthy');
47
        } elseif ($state === State::WARNING) {
48
            $this->addMessage(State::WARNING, 'Memcache Server Group Health', 'Group ' . $this->group, 'Group is crippled');
49
        } else {
50
            $this->addMessage(State::ERROR, 'Memcache Server Group Health', 'Group ' . $this->group, 'Group is down');
51
        }
52
53
        foreach ($this->tests as $server) {
54
            $this->addOutput($server->getOutput());
55
            $this->setMessages(array_merge($this->getMessages(), $server->getMessages()));
56
        }
57
    }
58
}
59