| 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 |
||
| 74 | public function executeUpdate(): bool |
||
| 75 | { |
||
| 76 | $table = 'tx_calendarize_domain_model_configuration'; |
||
| 77 | |||
| 78 | $q = HelperUtility::getDatabaseConnection($table)->createQueryBuilder(); |
||
| 79 | $q->update($table) |
||
| 80 | ->where( |
||
| 81 | $q->expr()->eq('type', $q->quote('timeExclude')) |
||
| 82 | ) |
||
| 83 | ->set('type', ConfigurationInterface::TYPE_TIME) |
||
| 84 | ->set('handling', ConfigurationInterface::HANDLING_INCLUDE); |
||
| 85 | |||
| 86 | $dbQueries[] = $q->getSQL(); |
||
|
|
|||
| 87 | $q->execute(); |
||
| 88 | |||
| 89 | $q->resetQueryParts(); |
||
| 90 | |||
| 91 | $q->update($table) |
||
| 92 | ->where( |
||
| 93 | $q->expr()->eq('type', $q->quote('include')) |
||
| 94 | ) |
||
| 95 | ->set('type', ConfigurationInterface::TYPE_GROUP) |
||
| 96 | ->set('handling', ConfigurationInterface::HANDLING_INCLUDE); |
||
| 97 | |||
| 98 | $dbQueries[] = $q->getSQL(); |
||
| 99 | $q->execute(); |
||
| 100 | |||
| 101 | $q->resetQueryParts(); |
||
| 102 | |||
| 103 | $q->update($table) |
||
| 104 | ->where( |
||
| 105 | $q->expr()->eq('type', $q->quote('exclude')) |
||
| 106 | ) |
||
| 107 | ->set('type', ConfigurationInterface::TYPE_GROUP) |
||
| 108 | ->set('handling', ConfigurationInterface::HANDLING_EXCLUDE); |
||
| 109 | |||
| 110 | $dbQueries[] = $q->getSQL(); |
||
| 111 | $q->execute(); |
||
| 112 | |||
| 113 | $q->resetQueryParts(); |
||
| 114 | |||
| 115 | $q->update($table) |
||
| 116 | ->where( |
||
| 117 | $q->expr()->orX( |
||
| 118 | $q->expr()->eq('handling', $q->quote('')), |
||
| 119 | $q->expr()->isNull('handling') |
||
| 120 | ) |
||
| 121 | ) |
||
| 122 | ->set('handling', ConfigurationInterface::HANDLING_INCLUDE); |
||
| 123 | |||
| 124 | $dbQueries[] = $q->getSQL(); |
||
| 125 | $q->execute(); |
||
| 126 | |||
| 127 | $customMessages = 'All queries are done! :)'; |
||
| 128 | |||
| 129 | return true; |
||
| 130 | } |
||
| 131 | |||
| 144 |
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
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey 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.