| Conditions | 19 |
| Paths | > 20000 |
| Total Lines | 153 |
| Code Lines | 109 |
| Lines | 117 |
| Ratio | 76.47 % |
| 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 |
||
| 163 | public function databaseAnalyzerAnalyzeAction(): ResponseInterface |
||
| 164 | { |
||
| 165 | $this->loadExtLocalconfDatabaseAndExtTables(); |
||
| 166 | $messageQueue = new FlashMessageQueue('install'); |
||
| 167 | |||
| 168 | $suggestions = []; |
||
| 169 | try { |
||
| 170 | $sqlReader = GeneralUtility::makeInstance(SqlReader::class); |
||
| 171 | $sqlStatements = $sqlReader->getCreateTableStatementArray($sqlReader->getTablesDefinitionString()); |
||
| 172 | $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class); |
||
| 173 | $addCreateChange = $schemaMigrationService->getUpdateSuggestions($sqlStatements); |
||
| 174 | |||
| 175 | // Aggregate the per-connection statements into one flat array |
||
| 176 | $addCreateChange = array_merge_recursive(...array_values($addCreateChange)); |
||
|
|
|||
| 177 | View Code Duplication | if (!empty($addCreateChange['create_table'])) { |
|
| 178 | $suggestion = [ |
||
| 179 | 'key' => 'addTable', |
||
| 180 | 'label' => 'Add tables', |
||
| 181 | 'enabled' => true, |
||
| 182 | 'children' => [], |
||
| 183 | ]; |
||
| 184 | foreach ($addCreateChange['create_table'] as $hash => $statement) { |
||
| 185 | $suggestion['children'][] = [ |
||
| 186 | 'hash' => $hash, |
||
| 187 | 'statement' => $statement, |
||
| 188 | ]; |
||
| 189 | } |
||
| 190 | $suggestions[] = $suggestion; |
||
| 191 | } |
||
| 192 | View Code Duplication | if (!empty($addCreateChange['add'])) { |
|
| 193 | $suggestion = [ |
||
| 194 | 'key' => 'addField', |
||
| 195 | 'label' => 'Add fields to tables', |
||
| 196 | 'enabled' => true, |
||
| 197 | 'children' => [], |
||
| 198 | ]; |
||
| 199 | foreach ($addCreateChange['add'] as $hash => $statement) { |
||
| 200 | $suggestion['children'][] = [ |
||
| 201 | 'hash' => $hash, |
||
| 202 | 'statement' => $statement, |
||
| 203 | ]; |
||
| 204 | } |
||
| 205 | $suggestions[] = $suggestion; |
||
| 206 | } |
||
| 207 | View Code Duplication | if (!empty($addCreateChange['change'])) { |
|
| 208 | $suggestion = [ |
||
| 209 | 'key' => 'change', |
||
| 210 | 'label' => 'Change fields', |
||
| 211 | 'enabled' => false, |
||
| 212 | 'children' => [], |
||
| 213 | ]; |
||
| 214 | foreach ($addCreateChange['change'] as $hash => $statement) { |
||
| 215 | $child = [ |
||
| 216 | 'hash' => $hash, |
||
| 217 | 'statement' => $statement, |
||
| 218 | ]; |
||
| 219 | if (isset($addCreateChange['change_currentValue'][$hash])) { |
||
| 220 | $child['current'] = $addCreateChange['change_currentValue'][$hash]; |
||
| 221 | } |
||
| 222 | $suggestion['children'][] = $child; |
||
| 223 | } |
||
| 224 | $suggestions[] = $suggestion; |
||
| 225 | } |
||
| 226 | |||
| 227 | // Difference from current to expected |
||
| 228 | $dropRename = $schemaMigrationService->getUpdateSuggestions($sqlStatements, true); |
||
| 229 | |||
| 230 | // Aggregate the per-connection statements into one flat array |
||
| 231 | $dropRename = array_merge_recursive(...array_values($dropRename)); |
||
| 232 | View Code Duplication | if (!empty($dropRename['change_table'])) { |
|
| 233 | $suggestion = [ |
||
| 234 | 'key' => 'renameTableToUnused', |
||
| 235 | 'label' => 'Remove tables (rename with prefix)', |
||
| 236 | 'enabled' => false, |
||
| 237 | 'children' => [], |
||
| 238 | ]; |
||
| 239 | foreach ($dropRename['change_table'] as $hash => $statement) { |
||
| 240 | $child = [ |
||
| 241 | 'hash' => $hash, |
||
| 242 | 'statement' => $statement, |
||
| 243 | ]; |
||
| 244 | if (!empty($dropRename['tables_count'][$hash])) { |
||
| 245 | $child['rowCount'] = $dropRename['tables_count'][$hash]; |
||
| 246 | } |
||
| 247 | $suggestion['children'][] = $child; |
||
| 248 | } |
||
| 249 | $suggestions[] = $suggestion; |
||
| 250 | } |
||
| 251 | View Code Duplication | if (!empty($dropRename['change'])) { |
|
| 252 | $suggestion = [ |
||
| 253 | 'key' => 'renameTableFieldToUnused', |
||
| 254 | 'label' => 'Remove unused fields (rename with prefix)', |
||
| 255 | 'enabled' => false, |
||
| 256 | 'children' => [], |
||
| 257 | ]; |
||
| 258 | foreach ($dropRename['change'] as $hash => $statement) { |
||
| 259 | $suggestion['children'][] = [ |
||
| 260 | 'hash' => $hash, |
||
| 261 | 'statement' => $statement, |
||
| 262 | ]; |
||
| 263 | } |
||
| 264 | $suggestions[] = $suggestion; |
||
| 265 | } |
||
| 266 | View Code Duplication | if (!empty($dropRename['drop'])) { |
|
| 267 | $suggestion = [ |
||
| 268 | 'key' => 'deleteField', |
||
| 269 | 'label' => 'Drop fields (really!)', |
||
| 270 | 'enabled' => false, |
||
| 271 | 'children' => [], |
||
| 272 | ]; |
||
| 273 | foreach ($dropRename['drop'] as $hash => $statement) { |
||
| 274 | $suggestion['children'][] = [ |
||
| 275 | 'hash' => $hash, |
||
| 276 | 'statement' => $statement, |
||
| 277 | ]; |
||
| 278 | } |
||
| 279 | $suggestions[] = $suggestion; |
||
| 280 | } |
||
| 281 | View Code Duplication | if (!empty($dropRename['drop_table'])) { |
|
| 282 | $suggestion = [ |
||
| 283 | 'key' => 'deleteTable', |
||
| 284 | 'label' => 'Drop tables (really!)', |
||
| 285 | 'enabled' => false, |
||
| 286 | 'children' => [], |
||
| 287 | ]; |
||
| 288 | foreach ($dropRename['drop_table'] as $hash => $statement) { |
||
| 289 | $child = [ |
||
| 290 | 'hash' => $hash, |
||
| 291 | 'statement' => $statement, |
||
| 292 | ]; |
||
| 293 | if (!empty($dropRename['tables_count'][$hash])) { |
||
| 294 | $child['rowCount'] = $dropRename['tables_count'][$hash]; |
||
| 295 | } |
||
| 296 | $suggestion['children'][] = $child; |
||
| 297 | } |
||
| 298 | $suggestions[] = $suggestion; |
||
| 299 | } |
||
| 300 | |||
| 301 | $messageQueue->enqueue(new FlashMessage( |
||
| 302 | '', |
||
| 303 | 'Analyzed current database' |
||
| 304 | )); |
||
| 305 | } catch (StatementException $e) { |
||
| 306 | $messageQueue->enqueue(new FlashMessage( |
||
| 307 | '', |
||
| 308 | 'Database analysis failed', |
||
| 309 | FlashMessage::ERROR |
||
| 310 | )); |
||
| 311 | } |
||
| 312 | return new JsonResponse([ |
||
| 313 | 'success' => true, |
||
| 314 | 'status' => $messageQueue, |
||
| 315 | 'suggestions' => $suggestions, |
||
| 316 | ]); |
||
| 489 |