Passed
Push — master ( e0f7b0...4354d2 )
by Vladimir
05:39 queued 20s
created

Check   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
rs 10
c 0
b 0
f 0
ccs 8
cts 10
cp 0.8
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 17 3
1
<?php
2
/**
3
 * This file is part of the `tvi/monitor-bundle` project.
4
 *
5
 * (c) https://github.com/turnaev/monitor-bundle/graphs/contributors
6
 *
7
 * For the full copyright and license information, please view the LICENSE.md
8
 * file that was distributed with this source code.
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
10
11
namespace Tvi\MonitorBundle\Check\fs\DiskUsage;
12
13
use ZendDiagnostics\Result\Failure;
14
use ZendDiagnostics\Result\Success;
15
use ZendDiagnostics\Result\Warning;
16
17
use Tvi\MonitorBundle\Check\CheckInterface;
18
use Tvi\MonitorBundle\Check\CheckTrait;
19
20
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
21
 * @author Vladimir Turnaev <[email protected]>
22
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
23
class Check extends \ZendDiagnostics\Check\DiskUsage implements CheckInterface
24
{
25
    use CheckTrait;
26
27
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
28
     * @inheritdoc
29
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
30 2
    public function check()
31
    {
32 2
        $df = disk_free_space($this->path);
33 2
        $dt = disk_total_space($this->path);
34
35 2
        $du = $dt - $df;
36 2
        $dp = round(($du / $dt) * 100, 2);
37
38 2
        if ($dp >= $this->criticalThreshold) {
39
            return new Failure(sprintf('Disk usage too high: %.2f %%.', $dp), $dp);
40
        }
41
42 2
        if ($dp >= $this->warningThreshold) {
43
            return new Warning(sprintf('Disk usage high: %.2f %%.', $dp), $dp);
44
        }
45
46 2
        return new Success(sprintf('Disk usage is %.5f %%.', $dp), $dp);
47
    }
48
}
49