SimpleHealthReport   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isHealthy() 0 3 1
A __construct() 0 8 2
A dependencies() 0 4 2
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