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