StatusSection::getHealthy()   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 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cushon\HealthBundle\Formatter\Console\StyledOutput\ApplicationStatus;
6
7
use Cushon\HealthBundle\Formatter\Console\StyledOutput\ApplicationStatus;
8
use Cushon\HealthBundle\Message\Result\HealthCheck;
9
use Symfony\Component\Console\Style\SymfonyStyle;
10
11
final class StatusSection implements ApplicationStatus
12
{
13
    public const DEFAULT_HEALTHY = 'Status: %s';
14
    public const DEFAULT_UNHEALTHY = 'Status: %s!';
15
16
    private string $healthy;
17
    private string $unhealthy;
18
19
    /**
20
     * @param string $healthy
21
     * @param string $unhealthy
22
     */
23
    public function __construct(
24
        string $healthy = self::DEFAULT_HEALTHY,
25
        string $unhealthy = self::DEFAULT_UNHEALTHY
26
    ) {
27
        $this->healthy = $healthy;
28
        $this->unhealthy = $unhealthy;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34
    public function format(HealthCheck $healthCheck, SymfonyStyle $styler): void
35
    {
36
        $styler->section('Application Health');
37
        if ($healthCheck->isHealthy()) {
38
            $styler->success($this->getHealthy());
39
        } else {
40
            $styler->warning($this->getUnhealthy());
41
        }
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    private function getHealthy(): string
48
    {
49
        return sprintf($this->healthy, self::STATUS_HEALTHY);
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    private function getUnhealthy(): string
56
    {
57
        return sprintf($this->unhealthy, self::STATUS_UNHEALTHY);
58
    }
59
}
60