SimpleHealthReport::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cushon\HealthBundle\ApplicationHealth\HealthReport;
6
7
use Cushon\HealthBundle\ApplicationHealth\HealthReport;
8
use Ds\Set;
9
use Generator;
10
11
final class SimpleHealthReport implements HealthReport
12
{
13
    private bool $healthy;
14
15
    /**
16
     * @var Set<DependencyStatus>
17
     */
18
    private Set $dependencyStatuses;
19
20
    /**
21
     * @param bool $healthy
22
     * @param DependencyStatus ...$dependencyStatuses
23
     */
24
    public function __construct(bool $healthy, DependencyStatus ...$dependencyStatuses)
25
    {
26
        if (!count($dependencyStatuses)) {
27
            throw HealthReport\Exception\NoDependencyStatuses::create();
28
        }
29
30
        $this->healthy = $healthy;
31
        $this->dependencyStatuses = new Set($dependencyStatuses);
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public function isHealthy(): bool
38
    {
39
        return $this->healthy;
40
    }
41
42
    /**
43
     * @inheritDoc
44
     *
45
     * @psalm-return Generator<int, DependencyStatus, mixed, void>
46
     */
47
    public function dependencies(): Generator
48
    {
49
        foreach ($this->dependencyStatuses as $dependencyStatus) {
50
            yield $dependencyStatus;
51
        }
52
    }
53
}
54