Passed
Push — master ( bb5c60...87d27f )
by Tim
01:35
created

FreeSpace   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A invokeTest() 0 22 3
A initialize() 0 5 1
A getPath() 0 4 1
A setPath() 0 4 1
1
<?php
2
3
namespace SimpleSAML\Modules\Monitor\TestCase\FileSystem;
4
5
use \SimpleSAML\Modules\Monitor\State as State;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\Modules\Monitor\State was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use \SimpleSAML\Modules\Monitor\TestData as TestData;
7
use \SimpleSAML\Modules\Monitor\TestResult as TestResult;
8
9
final class FreeSpace extends \SimpleSAML\Modules\Monitor\TestCaseFactory
10
{
11
    /**
12
     * @var string|null
13
     */
14
    private $path = null;
15
16
    /**
17
     * @var TestData $testData
18
     *
19
     * @return void
20
     */
21
    protected function initialize($testData)
22
    {
23
        $this->setPath($testData->getInputItem('path'));
24
        $this->setCategory($testData->getInputItem('category'));
25
        parent::initialize($testData);
26
    }
27
28
    /**
29
     * @return void
30
     */
31
    private function setPath($path)
32
    {
33
        assert(is_string($path));
34
        $this->path = $path;
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    private function getPath()
41
    {
42
        assert(is_string($this->path));
43
        return $this->path;
44
    }
45
46
    /**
47
     * @return void
48
     */
49
    public function invokeTest()
50
    {
51
        $path = $this->getPath();
52
        $testResult = new TestResult($this->getCategory(), $path);
53
54
        $size = disk_total_space($path);
55
        $used = $size - disk_free_space($path);
56
        $free = round(100 - (($used / $size) * 100));
57
58
        if ($free >= 15) {
59
            $testResult->setMessage($free . '% free space');
60
            $testResult->setState(State::OK);
61
        } else if ($free < 5) {
62
            $testResult->setMessage('Critical: ' . $free . '% free space');
63
            $testResult->setState(State::ERROR);
64
        } else {
65
            $testResult->setMessage($free . '% free space');
66
            $testResult->setState(State::WARNING);
67
        }
68
69
        $testResult->addOutput($free, 'free_percentage');
70
        $this->setTestResult($testResult);
71
    }
72
}
73