Server   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 45
rs 10
wmc 3

2 Methods

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