| Conditions | 7 |
| Paths | 26 |
| Total Lines | 63 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | 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 | $projectConfig = Craft::$app->getProjectConfig(); |
||
| 18 | $schemaVersion = $projectConfig->get('plugins.spoon.schemaVersion', true); |
||
| 19 | $oldSchema = version_compare($schemaVersion, '3.4.0', '<'); |
||
| 20 | |||
| 21 | $fields = Craft::$app->getFields(); |
||
| 22 | $configData = []; |
||
| 23 | |||
| 24 | $selectArray = [ |
||
| 25 | 'b.uid', |
||
| 26 | 'b.fieldId', |
||
| 27 | 'b.matrixBlockTypeId', |
||
| 28 | 'b.fieldLayoutId', |
||
| 29 | 'b.groupName', |
||
| 30 | 'b.context', |
||
| 31 | 'b.uid', |
||
| 32 | 'f.uid AS fieldUid', |
||
| 33 | 'mbt.uid AS matrixBlockUid', |
||
| 34 | ]; |
||
| 35 | |||
| 36 | if (!$oldSchema) { |
||
| 37 | $selectArray[] = 'b.groupSortOrder'; |
||
| 38 | $selectArray[] = 'b.sortOrder'; |
||
| 39 | } |
||
| 40 | |||
| 41 | $blockTypes = (new Query()) |
||
| 42 | ->select($selectArray) |
||
| 43 | ->from(['{{%spoon_blocktypes}} b']) |
||
| 44 | ->innerJoin('{{%fields}} f', '[[b.fieldId]] = [[f.id]]') |
||
| 45 | ->innerJoin('{{%matrixblocktypes}} mbt', '[[b.matrixBlockTypeId]] = [[mbt.id]]') |
||
| 46 | ->all(); |
||
| 47 | |||
| 48 | foreach ($blockTypes as $blockType) { |
||
| 49 | |||
| 50 | $data = [ |
||
| 51 | 'groupName' => $blockType['groupName'], |
||
| 52 | 'context' => $blockType['context'], |
||
| 53 | 'groupSortOrder' => $oldSchema ? null : $blockType['groupSortOrder'], |
||
| 54 | 'sortOrder' => $oldSchema ? null : $blockType['sortOrder'], |
||
| 55 | 'field' => $blockType['fieldUid'], |
||
| 56 | 'matrixBlockType' => $blockType['matrixBlockUid'], |
||
| 57 | ]; |
||
| 58 | |||
| 59 | if ($blockType['fieldLayoutId']) { |
||
| 60 | |||
| 61 | $layout = $fields->getLayoutById($blockType['fieldLayoutId']); |
||
| 62 | |||
| 63 | if ($layout) { |
||
| 64 | $layoutConfig = $layout->getConfig(); |
||
| 65 | |||
| 66 | $layoutUid = $layout->uid; |
||
| 67 | |||
| 68 | $data['fieldLayout'] = [ |
||
| 69 | $layoutUid => $layoutConfig |
||
| 70 | ]; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | $configData[$blockType['uid']] = $data; |
||
| 75 | } |
||
| 76 | |||
| 77 | return $configData; |
||
| 78 | } |
||
| 79 | } |