| Conditions | 10 |
| Paths | 2 |
| Total Lines | 65 |
| 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 |
||
| 129 | public function getSettingsResponse() |
||
| 130 | { |
||
| 131 | $variables['matrixFields'] = Spoon::$plugin->fields->getMatrixFields(); |
||
|
|
|||
| 132 | |||
| 133 | $variables['globalSpoonedBlockTypes'] = Spoon::$plugin->blockTypes->getByContext('global', 'fieldId', true); |
||
| 134 | |||
| 135 | // If Super Table is installed get all of the ST fields and store by child field context |
||
| 136 | $superTablePlugin = \Craft::$app->plugins->getPlugin('super-table'); |
||
| 137 | if ($superTablePlugin && $variables['matrixFields']) { |
||
| 138 | $superTableService = new \verbb\supertable\services\SuperTableService(); |
||
| 139 | |||
| 140 | foreach ($variables['matrixFields'] as $matrixField) { |
||
| 141 | if (strpos($matrixField->context, 'superTableBlockType') === 0) { |
||
| 142 | $parts = explode(':', $matrixField->context); |
||
| 143 | if (isset($parts[1])) { |
||
| 144 | |||
| 145 | $superTableBlockTypeId = Db::idByUid('{{%supertableblocktypes}}', $parts[1]); |
||
| 146 | |||
| 147 | if ($superTableBlockTypeId) { |
||
| 148 | /** @var \verbb\supertable\models\SuperTableBlockTypeModel $superTableBlockType */ |
||
| 149 | $superTableBlockType = $superTableService->getBlockTypeById($superTableBlockTypeId); |
||
| 150 | |||
| 151 | /** @var \verbb\supertable\fields\SuperTableField $superTableField */ |
||
| 152 | $superTableField = \Craft::$app->fields->getFieldById($superTableBlockType->fieldId); |
||
| 153 | |||
| 154 | $variables['superTableFields'][$matrixField->context] = [ |
||
| 155 | 'kind' => 'Super Table', |
||
| 156 | 'field' => $superTableField, |
||
| 157 | 'child' => false |
||
| 158 | ]; |
||
| 159 | |||
| 160 | // If the context of _this_ field is inside a Matrix block ... then we need to do more inception |
||
| 161 | if (strpos($superTableField->context, 'matrixBlockType') === 0) { |
||
| 162 | $nestedParts = explode(':', $superTableField->context); |
||
| 163 | if (isset($nestedParts[1])) { |
||
| 164 | |||
| 165 | $matrixBlockTypeId = Db::idByUid('{{%matrixblocktypes}}', $nestedParts[1]); |
||
| 166 | |||
| 167 | if ($matrixBlockTypeId) { |
||
| 168 | /** @var craft\models\MatrixBlockType $matrixBlockType */ |
||
| 169 | $matrixBlockType = \Craft::$app->matrix->getBlockTypeById($matrixBlockTypeId); |
||
| 170 | |||
| 171 | /** @var craft\fields\Matrix $globalField */ |
||
| 172 | $globalField = \Craft::$app->fields->getFieldById($matrixBlockType->fieldId); |
||
| 173 | |||
| 174 | $variables['superTableFields'][$matrixField->context] = [ |
||
| 175 | 'kind' => 'Matrix', |
||
| 176 | 'field' => $globalField, |
||
| 177 | 'child' => [ |
||
| 178 | 'kind' => 'Super Table', |
||
| 179 | 'field' => $superTableField |
||
| 180 | ] |
||
| 181 | ]; |
||
| 182 | } |
||
| 183 | } |
||
| 184 | } |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 | } |
||
| 189 | } |
||
| 190 | |||
| 191 | Spoon::$plugin->loader->configurator('#spoon-global-context-table', 'global'); |
||
| 192 | |||
| 193 | return Craft::$app->controller->renderTemplate('spoon/edit-global-context', $variables); |
||
| 194 | } |
||
| 208 |