Passed
Push — master ( 4541b1...3f3f73 )
by Tim
01:48
created

Server::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 9.4285
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
use \SimpleSAML\Module\monitor\TestResult as TestResult;
8
9
final class Server extends \SimpleSAML\Module\monitor\TestCaseFactory
10
{
11
    /**
12
     * @var array|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) {
0 ignored issues
show
introduced by
The condition $this->serverStats === false is always false. If $this->serverStats === false can have other possible types, add them to lib/TestCase/Store/Memcache/Server.php:12
Loading history...
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