DiskSpaceHealthIndicator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 1
cbo 3
dl 0
loc 43
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A doHealthCheck() 0 13 2
1
<?php
2
3
namespace Actuator\Health\Indicator;
4
5
use Actuator\Health\HealthBuilder;
6
7
/**
8
 * A HealthIndicator that checks available disk space and reports a status of
9
 * Status::DOWN when it drops below a configurable threshold.
10
 */
11
class DiskSpaceHealthIndicator extends AbstractHealthIndicator
12
{
13
    /**
14
     * @var DiskSpaceHealthIndicatorProperties
15
     */
16
    private $properties;
17
18
    /**
19
     * Create a new DiskSpaceHealthIndicator.
20
     *
21
     * @param DiskSpaceHealthIndicatorProperties $properties
22
     */
23
    public function __construct(DiskSpaceHealthIndicatorProperties $properties = null)
24
    {
25 9
        if (is_null($properties)) {
26
            $properties = new DiskSpaceHealthIndicatorProperties();
27 9
        }
28 3
29 3
        $this->properties = $properties;
30
    }
31 9
32 9
    /**
33
     * Actual health check logic.
34
     *
35
     * @param HealthBuilder $builder
36
     *
37
     * @throws \Exception any Exception that should create a Status::DOWN
38
     *                    system status.
39
     */
40
    protected function doHealthCheck(HealthBuilder $builder)
41 9
    {
42
        $directoryPath = $this->properties->getDirectory();
43 9
        $diskFreeInBytes = disk_free_space($directoryPath);
44 9
        if ($diskFreeInBytes >= $this->properties->getThreshold()) {
45 9
            $builder->up();
46 3
        } else {
47 3
            $builder->down();
48 6
        }
49
        $builder->withDetail('total', disk_total_space($directoryPath));
50 9
        $builder->withDetail('free', $diskFreeInBytes);
51 9
        $builder->withDetail('threshold', $this->properties->getThreshold());
52 9
    }
53
}
54