Completed
Branch master (f2efac)
by John
02:31
created

AbstractHealthIndicator::health()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Actuator\Health\Indicator;
4
5
use Actuator\Health\HealthBuilder;
6
7
/**
8
 * Base HealthIndicator implementations that encapsulates creation of
9
 * Health instance and error handling.
10
 *
11
 * @package Actuator\Health\Indicator
12
 */
13
abstract class AbstractHealthIndicator implements HealthIndicatorInterface
14
{
15 36
    public function health()
16
    {
17 36
        $builder = new HealthBuilder();
18
        try {
19 36
            $this->doHealthCheck($builder);
20 36
        } catch (\Exception $e) {
21 3
            $builder->down($e);
22
        }
23
24 36
        return $builder->build();
25 3
    }
26
27
    /**
28
     * Actual health check logic.
29
     *
30
     * @param HealthBuilder $builder
31
     * @throws \Exception any Exception that should create a Status::DOWN
32
     * system status.
33
     */
34
    abstract protected function doHealthCheck(HealthBuilder $builder);
35
}
36