| Conditions | 11 |
| Paths | 17 |
| Total Lines | 45 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 133 | public function onProjectConfigRebuild(RebuildConfigEvent $event) |
||
| 134 | { |
||
| 135 | |||
| 136 | Craft::$app->getProjectConfig()->remove('cacheFlags'); |
||
| 137 | |||
| 138 | $rows = (new Query()) |
||
| 139 | ->select(['flags', 'sectionId', 'categoryGroupId', 'tagGroupId', 'userGroupId', 'volumeId', 'globalSetId', 'elementType', 'uid']) |
||
| 140 | ->from(Flags::tableName()) |
||
| 141 | ->all(); |
||
| 142 | |||
| 143 | foreach ($rows as $row) { |
||
| 144 | |||
| 145 | $sourceKey = null; |
||
| 146 | $sourceValue = null; |
||
| 147 | |||
| 148 | if ($row['sectionId']) { |
||
| 149 | $sourceKey = 'section'; |
||
| 150 | $sourceValue = Db::uidById(Table::SECTIONS, $row['sectionId']); |
||
| 151 | } else if ($row['categoryGroupId']) { |
||
| 152 | $sourceKey = 'categoryGroup'; |
||
| 153 | $sourceValue = Db::uidById(Table::CATEGORYGROUPS, $row['categoryGroupId']); |
||
| 154 | } else if ($row['tagGroupId']) { |
||
| 155 | $sourceKey = 'tagGroup'; |
||
| 156 | $sourceValue = Db::uidById(Table::TAGGROUPS, $row['tagGroupId']); |
||
| 157 | } else if ($row['userGroupId']) { |
||
| 158 | $sourceKey = 'userGroup'; |
||
| 159 | $sourceValue = Db::uidById(Table::USERGROUPS, $row['userGroupId']); |
||
| 160 | } else if ($row['volumeId']) { |
||
| 161 | $sourceKey = 'volume'; |
||
| 162 | $sourceValue = Db::uidById(Table::VOLUMES, $row['volumeId']); |
||
| 163 | } else if ($row['globalSetId']) { |
||
| 164 | $sourceKey = 'globalSet'; |
||
| 165 | $sourceValue = Db::uidById(Table::GLOBALSETS, $row['globalSetId']); |
||
| 166 | } else if ($row['elementType']) { |
||
| 167 | $sourceKey = 'elementType'; |
||
| 168 | $sourceValue = $row['elementType']; |
||
| 169 | } |
||
| 170 | |||
| 171 | if (!$sourceKey || !$sourceValue) { |
||
| 172 | return; |
||
| 173 | } |
||
| 174 | |||
| 175 | $event->config['cacheFlags'][$row['uid']] = [ |
||
| 176 | 'source' => "$sourceKey:$sourceValue", |
||
| 177 | 'flags' => $row['flags'], |
||
| 178 | ]; |
||
| 184 |