| Conditions | 10 |
| Paths | 13 |
| Total Lines | 65 |
| 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 |
||
| 90 | public function setIdsByGeneral(array $indexIds, array $indexTypes, array $additionalSlotArguments) |
||
| 91 | { |
||
| 92 | if (!\in_array($this->getUniqueRegisterKey(), $indexTypes, true)) { |
||
| 93 | return; |
||
| 94 | } |
||
| 95 | |||
| 96 | $table = 'sys_category_record_mm'; |
||
| 97 | $db = HelperUtility::getDatabaseConnection($table); |
||
| 98 | $q = $db->createQueryBuilder(); |
||
| 99 | |||
| 100 | $categoryIds = []; |
||
| 101 | if (isset($additionalSlotArguments['contentRecord']['uid']) && MathUtility::canBeInterpretedAsInteger($additionalSlotArguments['contentRecord']['uid'])) { |
||
| 102 | $rows = $q->select('uid_local') |
||
| 103 | ->from($table) |
||
| 104 | ->where( |
||
| 105 | $q->expr()->andX( |
||
| 106 | $q->expr()->eq('tablenames', $q->quote('tt_content')), |
||
| 107 | $q->expr()->eq('fieldname', $q->quote('categories')), |
||
| 108 | $q->expr()->eq('uid_foreign', $q->createNamedParameter($additionalSlotArguments['contentRecord']['uid'])) |
||
| 109 | ) |
||
| 110 | ) |
||
| 111 | ->execute() |
||
| 112 | ->fetchAll(); |
||
| 113 | |||
| 114 | foreach ($rows as $row) { |
||
| 115 | $categoryIds[] = (int)$row['uid_local']; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | if (isset($additionalSlotArguments['settings']['pluginConfiguration']) && $additionalSlotArguments['settings']['pluginConfiguration'] instanceof PluginConfiguration) { |
||
| 120 | /** @var PluginConfiguration $pluginConfiguration */ |
||
| 121 | $pluginConfiguration = $additionalSlotArguments['settings']['pluginConfiguration']; |
||
| 122 | $categories = $pluginConfiguration->getCategories(); |
||
| 123 | foreach ($categories as $category) { |
||
| 124 | $categoryIds[] = $category->getUid(); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | if (empty($categoryIds)) { |
||
| 129 | return; |
||
| 130 | } |
||
| 131 | |||
| 132 | $q->resetQueryParts(); |
||
| 133 | $rows = $q->select('uid_foreign') |
||
| 134 | ->from('sys_category_record_mm') |
||
| 135 | ->where( |
||
| 136 | $q->expr()->in('uid_local', $categoryIds), |
||
| 137 | $q->expr()->eq('tablenames', $q->quote($this->getTableName())), |
||
| 138 | $q->expr()->eq('fieldname', $q->quote('categories')) |
||
| 139 | ) |
||
| 140 | ->execute() |
||
| 141 | ->fetchAll(); |
||
| 142 | |||
| 143 | foreach ($rows as $row) { |
||
| 144 | $indexIds[] = (int)$row['uid_foreign']; |
||
| 145 | } |
||
| 146 | |||
| 147 | $indexIds[] = -1; |
||
| 148 | |||
| 149 | return [ |
||
| 150 | 'indexIds' => $indexIds, |
||
| 151 | 'indexTypes' => $indexTypes, |
||
| 152 | 'additionalSlotArguments' => $additionalSlotArguments, |
||
| 153 | ]; |
||
| 154 | } |
||
| 155 | |||
| 186 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.