AbstractHealthAggregator::aggregateStatus()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 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