| Conditions | 3 |
| Paths | 1 |
| Total Lines | 60 |
| Code Lines | 39 |
| Lines | 8 |
| Ratio | 13.33 % |
| 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 |
||
| 137 | private function extendPostsController() |
||
| 138 | { |
||
| 139 | PostsController::extendFormFields(function ($form, $model) { |
||
| 140 | if (!$model instanceof PostModel) { |
||
| 141 | return; |
||
| 142 | } |
||
| 143 | |||
| 144 | $tab = self::LOCALIZATION_KEY . 'navigation.taxonomy'; |
||
| 145 | |||
| 146 | $categoriesConfig = $form->getField('categories')->config; |
||
| 147 | $categoriesConfig['tab'] = $tab; |
||
| 148 | $categoriesConfig['mode'] = 'relation'; |
||
| 149 | $categoriesConfig['type'] = 'taglist'; |
||
| 150 | $categoriesConfig['label'] = 'Categories'; |
||
| 151 | $categoriesConfig['comment'] = "rainlab.blog::lang.post.categories_comment"; |
||
| 152 | $categoriesConfig['placeholder'] = self::LOCALIZATION_KEY . 'placeholders.tags'; |
||
| 153 | unset($categoriesConfig['commentAbove']); |
||
| 154 | |||
| 155 | $form->removeField('categories'); |
||
| 156 | |||
| 157 | $form->addSecondaryTabFields([ |
||
| 158 | 'categories' => $categoriesConfig, |
||
| 159 | 'tags' => [ |
||
| 160 | 'label' => self::LOCALIZATION_KEY . 'form.tags.label', |
||
| 161 | 'comment' => self::LOCALIZATION_KEY . 'form.tags.comment', |
||
| 162 | 'mode' => 'relation', |
||
| 163 | 'tab' => $tab, |
||
| 164 | 'type' => 'taglist', |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Placeholders are not supported yet by the core. |
||
| 168 | * PR is waiting: https://github.com/octobercms/october/pull/3453 |
||
| 169 | */ |
||
| 170 | 'placeholder' => self::LOCALIZATION_KEY . 'placeholders.tags', |
||
| 171 | ], |
||
| 172 | 'series' => [ |
||
| 173 | 'label' => self::LOCALIZATION_KEY . 'form.series.label', |
||
| 174 | 'tab' => $tab, |
||
| 175 | 'type' => 'relation', |
||
| 176 | 'nameFrom' => 'title', |
||
| 177 | 'comment' => self::LOCALIZATION_KEY . 'form.series.comment', |
||
| 178 | 'emptyOption' => self::LOCALIZATION_KEY . 'placeholders.series' |
||
| 179 | ], |
||
| 180 | ]); |
||
| 181 | }); |
||
| 182 | |||
| 183 | PostsController::extend(function (Controller $controller) { |
||
| 184 | $controller->implement[] = RelationController::class; |
||
| 185 | $relationConfig = '$/' . self::DIRECTORY_KEY . '/controllers/series/config_posts_relation.yaml'; |
||
| 186 | |||
| 187 | View Code Duplication | if (property_exists($controller, 'relationConfig')) { |
|
| 188 | $controller->relationConfig = $controller->mergeConfig( |
||
| 189 | $controller->relationConfig, |
||
| 190 | $relationConfig |
||
| 191 | ); |
||
| 192 | } else { |
||
| 193 | $controller->addDynamicProperty('relationConfig', $relationConfig); |
||
| 194 | } |
||
| 195 | }); |
||
| 196 | } |
||
| 197 | |||
| 229 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.