HealthBuilder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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