Conditions | 5 |
Paths | 5 |
Total Lines | 31 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 11 |
CRAP Score | 5.0909 |
Changes | 0 |
1 | <?php |
||
21 | 22 | public function read(string $absolutePath): array |
|
22 | { |
||
23 | 22 | if (!$this->canRead($absolutePath)) { |
|
24 | 20 | return []; |
|
25 | } |
||
26 | |||
27 | 21 | $this->triggerEvent(new ReadPhpConfigEvent($absolutePath)); |
|
28 | |||
29 | /** |
||
30 | * @psalm-suppress UnresolvableInclude |
||
31 | * |
||
32 | * @var null|string[]|JsonSerializable|mixed $content |
||
33 | */ |
||
34 | 21 | $content = include $absolutePath; |
|
35 | |||
36 | 21 | if ($content === null) { |
|
37 | return []; |
||
38 | } |
||
39 | |||
40 | 21 | if ($content instanceof JsonSerializable) { |
|
41 | /** @var array<string,mixed> $jsonSerialized */ |
||
42 | 1 | $jsonSerialized = $content->jsonSerialize(); |
|
43 | 1 | return $jsonSerialized; |
|
44 | } |
||
45 | |||
46 | 21 | if (!is_array($content)) { |
|
47 | throw new RuntimeException('The PHP config file must return an array or a JsonSerializable object!'); |
||
48 | } |
||
49 | |||
50 | /** @var array<string,mixed> $content */ |
||
51 | 21 | return $content; |
|
52 | } |
||
66 |