JsonSerializableTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 11 2
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