JsonSerializableTrait::jsonSerialize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cushon\HealthBundle\Message\Result\Traits;
6
7
use Cushon\HealthBundle\ApplicationHealth\HealthReport\DependencyStatus;
8
use Cushon\HealthBundle\Message\Result\HealthCheck;
9
10
trait JsonSerializableTrait
11
{
12
    /**
13
     * @return (DependencyStatus[]|string)[]
14
     *
15
     * @psalm-return array{status: string, dependencies: list<DependencyStatus>}
16
     */
17
    public function jsonSerialize(): array
18
    {
19
        $dependencies = [];
20
21
        foreach ($this->dependencies() as $dependency) {
22
            $dependencies[] = $dependency;
23
        }
24
25
        return [
26
            HealthCheck::KEY_STATUS => $this->getStatus(),
27
            HealthCheck::KEY_DEPENDENCIES => $dependencies,
28
        ];
29
    }
30
31
    /**
32
     * @return iterable<DependencyStatus>
33
     */
34
    abstract public function dependencies(): iterable;
35
36
    /**
37
     * @return string
38
     */
39
    abstract private function getStatus(): string;
40
}
41