| Conditions | 4 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 32 |
| 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 |
||
| 15 | public static function rebuildProjectConfig(): array |
||
| 16 | { |
||
| 17 | $fields = Craft::$app->getFields(); |
||
| 18 | $configData = []; |
||
| 19 | |||
| 20 | $blockTypes = (new Query()) |
||
| 21 | ->select([ |
||
| 22 | 'b.uid', |
||
| 23 | 'b.fieldId', |
||
| 24 | 'b.matrixBlockTypeId', |
||
| 25 | 'b.fieldLayoutId', |
||
| 26 | 'b.groupName', |
||
| 27 | 'b.context', |
||
| 28 | 'b.uid', |
||
| 29 | 'f.uid AS fieldUid', |
||
| 30 | 'mbt.uid AS matrixBlockUid', |
||
| 31 | ]) |
||
| 32 | ->from(['{{%spoon_blocktypes}} b']) |
||
| 33 | ->innerJoin('{{%fields}} f', '[[b.fieldId]] = [[f.id]]') |
||
| 34 | ->innerJoin('{{%matrixblocktypes}} mbt', '[[b.matrixBlockTypeId]] = [[mbt.id]]') |
||
| 35 | ->all(); |
||
| 36 | |||
| 37 | foreach ($blockTypes as $blockType) { |
||
| 38 | |||
| 39 | $data = [ |
||
| 40 | 'groupName' => $blockType['groupName'], |
||
| 41 | 'context' => $blockType['context'], |
||
| 42 | 'field' => $blockType['fieldUid'], |
||
| 43 | 'matrixBlockType' => $blockType['matrixBlockUid'], |
||
| 44 | ]; |
||
| 45 | |||
| 46 | if ($blockType['fieldLayoutId']) { |
||
| 47 | |||
| 48 | $layout = $fields->getLayoutById($blockType['fieldLayoutId']); |
||
| 49 | |||
| 50 | if ($layout) { |
||
| 51 | |||
| 52 | |||
| 53 | $layoutConfig = $layout->getConfig(); |
||
| 54 | |||
| 55 | $layoutUid = $layout->uid; |
||
| 56 | |||
| 57 | $data['fieldLayout'] = [ |
||
| 58 | $layoutUid => $layoutConfig |
||
| 59 | ]; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | $configData[$blockType['uid']] = $data; |
||
| 64 | } |
||
| 65 | |||
| 66 | return $configData; |
||
| 67 | } |
||
| 68 | } |