DefaultResultFactory::createUnhealthy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cushon\HealthBundle\Handler\CheckHealth\ResultFactory;
6
7
use Cushon\HealthBundle\ApplicationHealth\HealthReport;
8
use Cushon\HealthBundle\ApplicationHealth\HealthReport\DependencyStatus;
9
use Cushon\HealthBundle\Handler\CheckHealth\ResultFactory;
10
use Cushon\HealthBundle\Message\Result\HealthCheck;
11
use Cushon\HealthBundle\Message\Result\HealthCheck\Healthy;
12
use Cushon\HealthBundle\Message\Result\HealthCheck\Unhealthy;
13
14
final class DefaultResultFactory implements ResultFactory
15
{
16
    /**
17
     * @inheritDoc
18
     */
19
    public function fromHealth(HealthReport $health): HealthCheck
20
    {
21
        /** @var DependencyStatus[] $dependencies */
22
        $dependencies = $health->dependencies();
23
24
        if ($health->isHealthy()) {
25
            return $this->createHealthy(...$dependencies);
26
        }
27
28
        return $this->createUnhealthy(...$dependencies);
29
    }
30
31
    /**
32
     * @param DependencyStatus ...$dependencies
33
     * @return Healthy
34
     */
35
    private function createHealthy(DependencyStatus ...$dependencies): Healthy
36
    {
37
        return new Healthy(...$dependencies);
38
    }
39
40
    /**
41
     * @param DependencyStatus ...$dependencies
42
     * @return Unhealthy
43
     */
44
    private function createUnhealthy(DependencyStatus ...$dependencies): Unhealthy
45
    {
46
        return new Unhealthy(...$dependencies);
47
    }
48
}
49