HealthBuilder   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A build() 0 17 3
A detailsAreEnabled() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nwidart\Actuator\Health;
6
7
class HealthBuilder
8
{
9
    /**
10
     * @var HealthContributorRegistry
11
     */
12
    private $registry;
13
14 4
    public function __construct(HealthContributorRegistry $registry)
15
    {
16 4
        $this->registry = $registry;
17 4
    }
18
19 4
    public function build(): Health
20
    {
21 4
        $health = new Health();
22
23
        $this->registry->getAll()->map(function (HealthContributor $contributor, $name) use ($health) {
24 3
            if ($name === 'status') {
25 3
                $health->status = $contributor->run();
26
27 3
                return;
28
            }
29 2
            if ($this->detailsAreEnabled()) {
30 1
                $health->details[$name] = $contributor->run();
31
            }
32 4
        });
33
34 4
        return $health;
35
    }
36
37 2
    private function detailsAreEnabled(): bool
38
    {
39 2
        return (bool) config('actuator.health.show-details', false);
40
    }
41
}
42