| Conditions | 7 |
| Paths | 9 |
| Total Lines | 58 |
| Code Lines | 32 |
| 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 |
||
| 119 | protected function doIt() |
||
| 120 | { |
||
| 121 | |||
| 122 | $request = Craft::$app->getRequest(); |
||
| 123 | |||
| 124 | if ($request->getIsAjax()) { |
||
| 125 | |||
| 126 | if (!$request->getIsPost()) { |
||
| 127 | return false; |
||
| 128 | } |
||
| 129 | |||
| 130 | $segments = $request->segments; |
||
| 131 | $actionSegment = $segments[count($segments) - 1]; |
||
| 132 | |||
| 133 | if ($actionSegment !== 'get-editor-html') { |
||
| 134 | return false; |
||
| 135 | } |
||
| 136 | |||
| 137 | Craft::$app->getView()->registerJs('Craft.CpFieldInspectPlugin.initElementEditor();'); |
||
| 138 | |||
| 139 | } else { |
||
| 140 | |||
| 141 | $data = array( |
||
| 142 | 'redirectUrl' => Craft::$app->getSecurity()->hashData(implode('/', $request->segments)), |
||
| 143 | 'fields' => array(), |
||
| 144 | 'entryTypeIds' => array(), |
||
| 145 | 'baseEditFieldUrl' => rtrim(UrlHelper::cpUrl('settings/fields/edit'), '/'), |
||
| 146 | 'baseEditEntryTypeUrl' => rtrim(UrlHelper::cpUrl('settings/sections/sectionId/entrytypes'), '/'), |
||
| 147 | 'baseEditGlobalSetUrl' => rtrim(UrlHelper::cpUrl('settings/globals'), '/'), |
||
| 148 | 'baseEditCategoryGroupUrl' => rtrim(UrlHelper::cpUrl('settings/categories'), '/'), |
||
| 149 | 'baseEditCommerceProductTypeUrl' => rtrim(UrlHelper::cpUrl('commerce/settings/producttypes'), '/'), |
||
| 150 | ); |
||
| 151 | |||
| 152 | $sectionIds = Craft::$app->getSections()->getAllSectionIds(); |
||
| 153 | foreach ($sectionIds as $sectionId) |
||
| 154 | { |
||
| 155 | $entryTypes = Craft::$app->getSections()->getEntryTypesBySectionId($sectionId); |
||
| 156 | $data['entryTypeIds']['' . $sectionId] = array(); |
||
| 157 | foreach ($entryTypes as $entryType) |
||
| 158 | { |
||
| 159 | $data['entryTypeIds']['' . $sectionId][] = $entryType->id; |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | |||
| 164 | $fields = Craft::$app->getFields()->getAllFields(); |
||
| 165 | |||
| 166 | foreach ($fields as $field) |
||
| 167 | { |
||
| 168 | |||
| 169 | $data['fields'][$field->handle] = array( |
||
| 170 | 'id' => $field->id, |
||
| 171 | 'handle' => $field->handle, |
||
| 172 | ); |
||
| 173 | } |
||
| 174 | |||
| 175 | Craft::$app->getView()->registerAssetBundle(CpFieldInspectBundle::class); |
||
| 176 | Craft::$app->getView()->registerJs('Craft.CpFieldInspectPlugin.init('.json_encode($data).');'); |
||
| 177 | } |
||
| 181 |