Total Complexity | 10 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class ConfigHelper |
||
8 | { |
||
9 | /** |
||
10 | * Get config. |
||
11 | * |
||
12 | * @param string|null $generatorName |
||
13 | * @return array |
||
14 | * |
||
15 | * @throws LaravelGeneratorException |
||
16 | */ |
||
17 | public function generatorConfig(?string $generatorName = null): array |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Merge config. |
||
35 | * |
||
36 | * @param array $defaults |
||
37 | * @param array $generatorName |
||
38 | * @return array |
||
39 | */ |
||
40 | private function mergeConfig(array $defaults, array $generatorName): array |
||
41 | { |
||
42 | $merged = $defaults; |
||
43 | |||
44 | foreach ($generatorName as $key => &$value) { |
||
45 | if (isset($defaults[$key]) |
||
46 | && $this->isAssociativeArray($defaults[$key]) |
||
47 | && $this->isAssociativeArray($value) |
||
48 | ) { |
||
49 | $merged[$key] = $this->mergeConfig($defaults[$key], $value); |
||
50 | continue; |
||
51 | } |
||
52 | |||
53 | $merged[$key] = $value; |
||
54 | } |
||
55 | |||
56 | return $merged; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Check is associative key array. |
||
61 | * |
||
62 | * @param mixed $key |
||
63 | * @return bool |
||
64 | */ |
||
65 | private function isAssociativeArray(mixed $key): bool |
||
68 | } |
||
69 | } |
||
70 |