| Conditions | 15 |
| Paths | 170 |
| Total Lines | 65 |
| Code Lines | 46 |
| 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 |
||
| 155 | public function updateLocalConfigurationValues(array $valueList): FlashMessageQueue |
||
| 156 | { |
||
| 157 | $messageQueue = new FlashMessageQueue('install'); |
||
| 158 | $configurationPathValuePairs = []; |
||
| 159 | $commentArray = $this->getDefaultConfigArrayComments(); |
||
| 160 | $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); |
||
| 161 | foreach ($valueList as $path => $value) { |
||
| 162 | $oldValue = $configurationManager->getConfigurationValueByPath($path); |
||
| 163 | $pathParts = explode('/', $path); |
||
| 164 | $descriptionData = $commentArray[$pathParts[0]]; |
||
| 165 | |||
| 166 | while ($part = next($pathParts)) { |
||
| 167 | $descriptionData = $descriptionData['items'][$part]; |
||
| 168 | } |
||
| 169 | |||
| 170 | $dataType = $descriptionData['type']; |
||
| 171 | |||
| 172 | if ($dataType === 'multiline') { |
||
| 173 | $value = str_replace(CR, '', $value); |
||
| 174 | $valueHasChanged = (string)$oldValue !== (string)$value; |
||
| 175 | } elseif ($dataType === 'bool') { |
||
| 176 | // When submitting settings in the Install Tool, values that default to "FALSE" or "TRUE" |
||
| 177 | // in EXT:core/Configuration/DefaultConfiguration.php will be sent as "0" resp. "1". |
||
| 178 | $value = $value === '1'; |
||
| 179 | $valueHasChanged = (bool)$oldValue !== $value; |
||
| 180 | } elseif ($dataType === 'int') { |
||
| 181 | // Cast integer values to integers (but only for values that can not contain a string as well) |
||
| 182 | $value = (int)$value; |
||
| 183 | $valueHasChanged = (int)$oldValue !== $value; |
||
| 184 | } elseif ($dataType === 'array') { |
||
| 185 | $oldValueAsString = is_array($oldValue) |
||
| 186 | ? implode(',', $oldValue) |
||
| 187 | : (string)$oldValue; |
||
| 188 | $valueHasChanged = $oldValueAsString !== $value; |
||
| 189 | $value = GeneralUtility::trimExplode(',', $value, true); |
||
| 190 | } else { |
||
| 191 | $valueHasChanged = (string)$oldValue !== (string)$value; |
||
| 192 | } |
||
| 193 | |||
| 194 | // Save if value changed |
||
| 195 | if ($valueHasChanged) { |
||
| 196 | $configurationPathValuePairs[$path] = $value; |
||
| 197 | |||
| 198 | if (is_bool($value)) { |
||
| 199 | $messageBody = 'New value = ' . ($value ? 'true' : 'false'); |
||
| 200 | } elseif (empty($value)) { |
||
| 201 | $messageBody = 'New value = none'; |
||
| 202 | } elseif (is_array($value)) { |
||
| 203 | $messageBody = "New value = ['" . implode("', '", $value) . "']"; |
||
| 204 | } elseif ($dataType === 'password') { |
||
| 205 | $messageBody = 'New value is set'; |
||
| 206 | } else { |
||
| 207 | $messageBody = 'New value = ' . $value; |
||
| 208 | } |
||
| 209 | |||
| 210 | $messageQueue->enqueue(new FlashMessage( |
||
| 211 | $messageBody, |
||
| 212 | $path |
||
| 213 | )); |
||
| 214 | } |
||
| 215 | } |
||
| 216 | if ($messageQueue->count() > 0) { |
||
| 217 | $configurationManager->setLocalConfigurationValuesByPathValuePairs($configurationPathValuePairs); |
||
| 218 | } |
||
| 219 | return $messageQueue; |
||
| 220 | } |
||
| 235 |