Test Failed
Push — master ( 1d6b64...a7292a )
by Vladimir
05:19
created

Check::check()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
c 0
b 0
f 0
rs 9.6111
cc 5
nc 3
nop 0
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\DiskFree;
12
13
use ZendDiagnostics\Result\Failure;
14
use ZendDiagnostics\Result\Success;
15
use ZendDiagnostics\Result\SuccessInterface;
16
use ZendDiagnostics\Result\Warning;
17
use ZendDiagnostics\Result\WarningInterface;
18
use ZendDiagnostics\Result\SkipInterface;
19
use ZendDiagnostics\Result\FailureInterface;
20
21
use Tvi\MonitorBundle\Check\CheckInterface;
22
use Tvi\MonitorBundle\Check\CheckTrait;
23
24
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
25
 * @author Vladimir Turnaev <[email protected]>
26
 */
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...
27
class Check extends \ZendDiagnostics\Check\DiskFree implements CheckInterface
28
{
29
    use CheckTrait;
30
31
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
32
     * @inheritdoc
33
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
34
    public function check()
35
    {
36
        // We are using error suppression because the method will trigger a warning
37
        // in case of non-existent paths and other errors. We are more interested in
38
        // the potential return value of FALSE, which will tell us that free space
39
        // could not be obtained and we do not care about the real cause of this.
40
        $free = @ disk_free_space($this->path);
41
42
        if ($free === false || ! is_float($free) || $free < 0) {
43
            return new Warning('Unable to determine free disk space at ' . $this->path .'.');
44
        }
45
46
        $freeHumanReadable = static::bytesToString($free, 2);
0 ignored issues
show
Bug introduced by
$free of type double is incompatible with the type integer expected by parameter $size of ZendDiagnostics\Check\DiskFree::bytesToString(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
        $freeHumanReadable = static::bytesToString(/** @scrutinizer ignore-type */ $free, 2);
Loading history...
47
        $minFreeHumanReadable = static::bytesToString($this->minDiskBytes, 2);
48
        $description = sprintf('Remaining space at %s: %s, requared min: %s.', $this->path, $freeHumanReadable, $minFreeHumanReadable);
49
50
        if (disk_free_space($this->path) < $this->minDiskBytes) {
51
            return new Failure($description, $free);
52
        }
53
54
        return new Success($description, $free);
55
    }
56
}
57