Conditions | 1 |
Paths | 1 |
Total 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 |
||
68 | public function executeUpdate() : bool |
||
69 | { |
||
70 | $table = 'tx_calendarize_domain_model_configuration'; |
||
71 | |||
72 | $q = HelperUtility::getDatabaseConnection($table)->createQueryBuilder(); |
||
73 | $q->update($table) |
||
74 | ->where( |
||
75 | $q->expr()->eq('type', $q->quote('timeExclude')) |
||
76 | ) |
||
77 | ->set('type', ConfigurationInterface::TYPE_TIME) |
||
78 | ->set('handling', ConfigurationInterface::HANDLING_INCLUDE); |
||
79 | |||
80 | $dbQueries[] = $q->getSQL(); |
||
|
|||
81 | $q->execute(); |
||
82 | |||
83 | $q->resetQueryParts(); |
||
84 | |||
85 | $q->update($table) |
||
86 | ->where( |
||
87 | $q->expr()->eq('type', $q->quote('include')) |
||
88 | ) |
||
89 | ->set('type', ConfigurationInterface::TYPE_GROUP) |
||
90 | ->set('handling', ConfigurationInterface::HANDLING_INCLUDE); |
||
91 | |||
92 | $dbQueries[] = $q->getSQL(); |
||
93 | $q->execute(); |
||
94 | |||
95 | $q->resetQueryParts(); |
||
96 | |||
97 | $q->update($table) |
||
98 | ->where( |
||
99 | $q->expr()->eq('type', $q->quote('exclude')) |
||
100 | ) |
||
101 | ->set('type', ConfigurationInterface::TYPE_GROUP) |
||
102 | ->set('handling', ConfigurationInterface::HANDLING_EXCLUDE); |
||
103 | |||
104 | $dbQueries[] = $q->getSQL(); |
||
105 | $q->execute(); |
||
106 | |||
107 | $q->resetQueryParts(); |
||
108 | |||
109 | $q->update($table) |
||
110 | ->where( |
||
111 | $q->expr()->orX( |
||
112 | $q->expr()->eq('handling', $q->quote('')), |
||
113 | $q->expr()->isNull('handling') |
||
114 | ) |
||
115 | ) |
||
116 | ->set('handling', ConfigurationInterface::HANDLING_INCLUDE); |
||
117 | |||
118 | $dbQueries[] = $q->getSQL(); |
||
119 | $q->execute(); |
||
120 | |||
121 | $customMessages = 'All queries are done! :)'; |
||
122 | |||
123 | return true; |
||
124 | } |
||
125 | |||
154 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.