| Conditions | 18 |
| Paths | 40 |
| Total Lines | 72 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 75 | protected function recursiveConfigurationFetching(array $sections, array $sectionsFromCurrentConfiguration, array $descriptions, array $path = []): array |
||
| 76 | { |
||
| 77 | $data = []; |
||
| 78 | |||
| 79 | foreach ($sections as $key => $value) { |
||
| 80 | if (!isset($descriptions['items'][$key])) { |
||
| 81 | // @todo should we do something here? |
||
| 82 | continue; |
||
| 83 | } |
||
| 84 | |||
| 85 | $descriptionInfo = $descriptions['items'][$key]; |
||
| 86 | $descriptionType = $descriptionInfo['type']; |
||
| 87 | |||
| 88 | $newPath = $path; |
||
| 89 | $newPath[] = $key; |
||
| 90 | |||
| 91 | if ($descriptionType === 'container') { |
||
| 92 | $valueFromCurrentConfiguration = $sectionsFromCurrentConfiguration[$key] ?? null; |
||
| 93 | $data = array_merge($data, $this->recursiveConfigurationFetching($value, $valueFromCurrentConfiguration, $descriptionInfo, $newPath)); |
||
| 94 | } elseif (!preg_match('/[' . LF . CR . ']/', (string)(is_array($value) ? '' : $value)) || $descriptionType === 'multiline') { |
||
| 95 | $itemData = []; |
||
| 96 | $itemData['key'] = implode('/', $newPath); |
||
| 97 | $itemData['path'] = '[' . implode('][', $newPath) . ']'; |
||
| 98 | $itemData['fieldType'] = $descriptionInfo['type']; |
||
| 99 | $itemData['description'] = $descriptionInfo['description'] ?? ''; |
||
| 100 | $itemData['allowedValues'] = $descriptionInfo['allowedValues'] ?? []; |
||
| 101 | $itemData['differentValueInCurrentConfiguration'] = (!isset($descriptionInfo['compareValuesWithCurrentConfiguration']) || |
||
| 102 | $descriptionInfo['compareValuesWithCurrentConfiguration']) && |
||
| 103 | isset($sectionsFromCurrentConfiguration[$key]) && |
||
| 104 | $value !== $sectionsFromCurrentConfiguration[$key]; |
||
| 105 | switch ($descriptionType) { |
||
| 106 | case 'multiline': |
||
| 107 | $itemData['type'] = 'textarea'; |
||
| 108 | $itemData['value'] = str_replace(['\' . LF . \'', '\' . LF . \''], [LF, LF], $value); |
||
| 109 | break; |
||
| 110 | case 'bool': |
||
| 111 | $itemData['type'] = 'checkbox'; |
||
| 112 | $itemData['value'] = $value ? '1' : '0'; |
||
| 113 | $itemData['checked'] = (bool)$value; |
||
| 114 | break; |
||
| 115 | case 'int': |
||
| 116 | $itemData['type'] = 'number'; |
||
| 117 | $itemData['value'] = (int)$value; |
||
| 118 | break; |
||
| 119 | case 'array': |
||
| 120 | $itemData['type'] = 'input'; |
||
| 121 | // @todo The line below should be improved when the array handling is introduced in the global settings manager. |
||
| 122 | $itemData['value'] = is_array($value) |
||
| 123 | ? implode(',', $value) |
||
| 124 | : (string)$value; |
||
| 125 | break; |
||
| 126 | // Check if the setting is a PHP error code, will trigger a view helper in fluid |
||
| 127 | case 'errors': |
||
| 128 | $itemData['type'] = 'input'; |
||
| 129 | $itemData['value'] = $value; |
||
| 130 | $itemData['phpErrorCode'] = true; |
||
| 131 | break; |
||
| 132 | case 'password': |
||
| 133 | $itemData['type'] = 'password'; |
||
| 134 | $itemData['value'] = $value; |
||
| 135 | $itemData['hideValue'] = true; |
||
| 136 | break; |
||
| 137 | default: |
||
| 138 | $itemData['type'] = 'input'; |
||
| 139 | $itemData['value'] = $value; |
||
| 140 | } |
||
| 141 | |||
| 142 | $data[] = $itemData; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | return $data; |
||
| 147 | } |
||
| 235 |