DiskSpace::call()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 21
rs 9.8333
cc 2
nc 2
nop 0
1
<?php
2
namespace Health\Checks\Filesystem;
3
4
use Health\Checks\BaseCheck;
5
use Health\Checks\HealthCheckInterface;
6
use Health\Checks\Traits\FormatTrait;
7
8
class DiskSpace extends BaseCheck implements HealthCheckInterface
9
{
10
11
    use FormatTrait;
12
13
    /**
14
     * Default disk space threshold of 100 MB
15
     *
16
     * @var integer
17
     */
18
    const DEFAULT_THRESHOLD = 100000000;
19
20
    /**
21
     * Default Path
22
     *
23
     * @var string
24
     */
25
    const DEFAULT_PATH = '/';
26
27
    /**
28
     *
29
     * {@inheritdoc}
30
     * @see \Health\Checks\HealthCheckInterface::call()
31
     */
32
    public function call()
33
    {
34
        $builder = $this->getBuilder();
35
36
        $path = $this->getParam('path', self::DEFAULT_PATH);
37
        $threshold = $this->getParam('threshold', self::DEFAULT_THRESHOLD);
38
39
        $free = disk_free_space($path);
40
41
        if ($free >= $threshold) {
42
            $builder->up();
43
        } else {
44
            $builder->down();
45
        }
46
47
        $builder->withData('free_bytes', $free)
48
            ->withData('free_human', $this->formatBytes($free))
49
            ->withData('path', $path)
50
            ->withData('threshold', $threshold);
51
52
        return $builder->build();
53
    }
54
}
55