Passed
Branch monitor-2.5.x (8b654c)
by Tim
01:31
created

Server   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 6 1
A invokeTest() 0 18 2
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 Server extends \SimpleSAML\Modules\Monitor\TestCaseFactory
10
{
11
    /**
12
     * @var array|false|null
13
     */
14
    private $serverStats;
15
16
    /**
17
     * @var string|null
18
     */
19
    private $host;
20
21
22
    /**
23
     * @param TestData $testData
24
     *
25
     * @return void
26
     */
27
    protected function initialize($testData)
28
    {
29
        $this->serverStats = $testData->getInputItem('serverStats');
30
        $this->host = $testData->getInputItem('host');
31
32
        parent::initialize($testData);
33
    }
34
35
36
    /**
37
     * @return void
38
     */
39
    public function invokeTest()
40
    {
41
        $testResult = new TestResult('Memcache Server Health', $this->host);
42
43
        if ($this->serverStats === false) {
44
            $testResult->setState(State::ERROR);
45
            $testResult->setMessage('Host is down');
46
        } else {
47
            $bytesUsed = $this->serverStats['bytes'];
48
            $bytesLimit = $this->serverStats['limit_maxbytes'];
49
            $free = round(100.0 - (($bytesUsed / $bytesLimit) * 100));
50
            $testResult->addOutput($free, 'freePercentage');
51
52
            $testResult->setState(State::OK);
53
            $testResult->setMessage($free . '% free space');
54
        }
55
56
        $this->setTestResult($testResult);
57
    }
58
}
59