AbstractHealthAggregator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A aggregate() 0 12 2
aggregateStatus() 0 1 ?
A aggregateDetails() 0 4 1
1
<?php
2
3
namespace Actuator\Health;
4
5
/**
6
 * Base HealthAggregator implementation to allow subclasses to focus on
7
 * aggregating the Status instances and not deal with contextual details etc.
8
 */
9
abstract class AbstractHealthAggregator implements HealthAggregatorInterface
10
{
11
    /**
12
     * Aggregate several given Health instances into one.
13
     *
14
     * @param Health[] $healths
15
     *
16
     * @return Health
17
     */
18
    public function aggregate($healths)
19 30
    {
20
        $statusCandidates = [];
21 30
        foreach ($healths as $key => $health) {
22 30
            $statusCandidates[] = $health->getStatus();
23 30
        }
24 30
        $status = $this->aggregateStatus($statusCandidates);
25 30
        $details = $this->aggregateDetails($healths);
26 30
        $builder = new HealthBuilder($status, $details);
27 30
28 30
        return $builder->build();
29
    }
30
31
    /**
32
     * @param Status[] $candidates
33
     *
34
     * @return Status
35
     */
36
    abstract protected function aggregateStatus($candidates);
37
38
    /**
39
     * Return the map of 'aggregate' details that should be used from the specified
40
     * healths.
41
     *
42
     * @param Health[] $healths
43
     *
44 30
     * @return array
45
     */
46 30
    protected function aggregateDetails($healths)
47
    {
48
        return $healths;
49
    }
50
}
51