CompositeHealthIndicator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A addHealthIndicator() 0 4 1
A health() 0 9 2
1
<?php
2
3
namespace Actuator\Health\Indicator;
4
5
use Actuator\Health\Health;
6
use Actuator\Health\HealthAggregatorInterface;
7
8
/**
9
 * HealthIndicator that returns health indications from all registered delegates.
10
 */
11
class CompositeHealthIndicator implements HealthIndicatorInterface
12
{
13
    /**
14
     * @var HealthIndicatorInterface[]
15
     */
16
    private $indicators;
17
18
    /**
19
     * @var HealthAggregatorInterface
20
     */
21
    private $healthAggregator;
22
23
    /**
24
     * Create a new CompositeHealthIndicator from the specified indicators.
25
     *
26
     * @param HealthAggregatorInterface  $healthAggregator
27
     * @param HealthIndicatorInterface[] $indicators
28
     */
29
    public function __construct(HealthAggregatorInterface $healthAggregator, array $indicators = [])
30
    {
31 15
        assert(!is_null($healthAggregator), 'HealthAggregator must not be null');
32
33 15
        $this->indicators = $indicators;
34
        $this->healthAggregator = $healthAggregator;
35 15
    }
36 15
37 15
    /**
38
     * @param string                   $name
39
     * @param HealthIndicatorInterface $indicator
40
     */
41
    public function addHealthIndicator($name, HealthIndicatorInterface $indicator)
42
    {
43 12
        $this->indicators[$name] = $indicator;
44
    }
45 12
46 12
    /**
47
     * Return an indication of health.
48
     *
49
     * @return Health
50
     */
51
    public function health()
52
    {
53 15
        $healths = [];
54
        foreach ($this->indicators as $key => $indicator) {
55 15
            $healths[$key] = $indicator->health();
56 15
        }
57 15
58 15
        return $this->healthAggregator->aggregate($healths);
59
    }
60
}
61