DatabaseCompareDry::compare()   D
last analyzed

Complexity

Conditions 11
Paths 768

Size

Total Lines 55
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 132

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 55
ccs 0
cts 40
cp 0
rs 4.375
cc 11
eloc 30
nc 768
nop 1
crap 132

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
namespace Etobi\CoreAPI\Service;
4
5
/**
6
 * This file is part of the TYPO3 CMS project.
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17
use InvalidArgumentException;
18
19
/**
20
 * Class DatabaseDryCompare
21
 * 
22
 * @package Etobi\CoreAPI\Service
23
 * @author Georg Ringer <[email protected]>
24
 * @author Stefano Kowalke <[email protected]>
25
 */
26
class DatabaseCompareDry extends DatabaseComparator {
27
28
	/**
29
	 * Database compare.
30
	 *
31
	 * @param string $actions comma separated list of IDs
32
	 * @throws InvalidArgumentException
33
	 * @return array
34
	 */
35
	public function compare($actions) {
0 ignored issues
show
Complexity introduced by
This operation has 768 execution paths which exceeds the configured maximum of 200.

A high number of execution paths generally suggests many nested conditional statements and make the code less readible. This can usually be fixed by splitting the method into several smaller methods.

You can also find more information in the “Code” section of your repository.

Loading history...
36
		$errors = array();
37
		$results = array();
38
39
		$allowedActions = $this->getAllowedActions($actions);
40
41
		$expectedSchema = $this->sqlExpectedSchemaService->getExpectedDatabaseSchema();
42
		$currentSchema = $this->schemaMigrationService->getFieldDefinitions_database();
43
44
		$addCreateChange = $this->schemaMigrationService->getDatabaseExtra($expectedSchema, $currentSchema);
45
		$addCreateChange = $this->schemaMigrationService->getUpdateSuggestions($addCreateChange);
46
47
		$dropRemove = $this->schemaMigrationService->getDatabaseExtra($currentSchema, $expectedSchema);
48
		$dropRemove = $this->schemaMigrationService->getUpdateSuggestions($dropRemove, 'remove');
49
50
		if ($allowedActions[self::ACTION_UPDATE_CLEAR_TABLE] == 1) {
51
			$results['update_clear_table'] = $addCreateChange['clear_table'];
52
		}
53
54
		if ($allowedActions[self::ACTION_UPDATE_ADD] == 1) {
55
			$results['update_add'] = $addCreateChange['add'];
56
		}
57
58
		if ($allowedActions[self::ACTION_UPDATE_CHANGE] == 1) {
59
			$results['update_change'] = $addCreateChange['change'];
60
		}
61
62
		if ($allowedActions[self::ACTION_UPDATE_CREATE_TABLE] == 1) {
63
			$results['update_create_table'] = $addCreateChange['create_table'];
64
		}
65
66
		if ($allowedActions[self::ACTION_REMOVE_CHANGE] == 1) {
67
			$results['remove_change'] = $dropRemove['change'];
68
		}
69
70
		if ($allowedActions[self::ACTION_REMOVE_DROP] == 1) {
71
			$results['remove_drop'] = $dropRemove['drop'];
72
		}
73
74
		if ($allowedActions[self::ACTION_REMOVE_CHANGE_TABLE] == 1) {
75
			$results['remove_change_table'] = $dropRemove['change_table'];
76
		}
77
78
		if ($allowedActions[self::ACTION_REMOVE_DROP_TABLE] == 1) {
79
			$results['remove_drop_table'] = $dropRemove['drop_table'];
80
		}
81
82
		foreach ($results as $key => $resultSet) {
83
			if (!empty($resultSet)) {
84
				$errors[$key] = $resultSet;
85
			}
86
		}
87
88
		return $errors;
89
	}
90
}
91
92