| Conditions | 3 | 
| Paths | 1 | 
| Total Lines | 55 | 
| 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  | 
            ||
| 139 | private function extendPostsController()  | 
            ||
| 140 |     { | 
            ||
| 141 |         PostsController::extendFormFields(function ($form, $model) { | 
            ||
| 142 |             if (!$model instanceof PostModel) { | 
            ||
| 143 | return;  | 
            ||
| 144 | }  | 
            ||
| 145 | |||
| 146 | /*  | 
            ||
| 147 | * When extending the form, you should check to see if $formWidget->isNested === false  | 
            ||
| 148 | * as the Repeater FormWidget includes nested Form widgets which can cause your changes  | 
            ||
| 149 | * to be made in unexpected places.  | 
            ||
| 150 | *  | 
            ||
| 151 | * @link https://octobercms.com/docs/plugin/extending#extending-backend-form  | 
            ||
| 152 | */  | 
            ||
| 153 |             if (!empty($form->isNested)) { | 
            ||
| 154 | return;  | 
            ||
| 155 | }  | 
            ||
| 156 | |||
| 157 | $tab = self::LOCALIZATION_KEY . 'navigation.taxonomy';  | 
            ||
| 158 | |||
| 159 |             $categoriesConfig = $form->getField('categories')->config; | 
            ||
| 160 | $categoriesConfig['tab'] = $tab;  | 
            ||
| 161 | $categoriesConfig['mode'] = 'relation';  | 
            ||
| 162 | $categoriesConfig['type'] = 'taglist';  | 
            ||
| 163 | $categoriesConfig['label'] = 'rainlab.blog::lang.post.tab_categories';  | 
            ||
| 164 | $categoriesConfig['comment'] = "rainlab.blog::lang.post.categories_comment";  | 
            ||
| 165 | $categoriesConfig['placeholder'] = self::LOCALIZATION_KEY . 'placeholders.categories';  | 
            ||
| 166 | unset($categoriesConfig['commentAbove']);  | 
            ||
| 167 | |||
| 168 |             $form->removeField('categories'); | 
            ||
| 169 | |||
| 170 | $form->addSecondaryTabFields([  | 
            ||
| 171 | 'categories' => $categoriesConfig,  | 
            ||
| 172 | 'tags' => [  | 
            ||
| 173 | 'label' => self::LOCALIZATION_KEY . 'form.tags.label',  | 
            ||
| 174 | 'comment' => self::LOCALIZATION_KEY . 'form.tags.comment',  | 
            ||
| 175 | 'mode' => 'relation',  | 
            ||
| 176 | 'tab' => $tab,  | 
            ||
| 177 | 'type' => 'taglist',  | 
            ||
| 178 | 'placeholder' => self::LOCALIZATION_KEY . 'placeholders.tags',  | 
            ||
| 179 | ],  | 
            ||
| 180 | 'series' => [  | 
            ||
| 181 | 'label' => self::LOCALIZATION_KEY . 'form.series.label',  | 
            ||
| 182 | 'tab' => $tab,  | 
            ||
| 183 | 'type' => 'relation',  | 
            ||
| 184 | 'nameFrom' => 'title',  | 
            ||
| 185 | 'comment' => self::LOCALIZATION_KEY . 'form.series.comment',  | 
            ||
| 186 | // October CMS has a bug with displaying of placeholders without an explicit empty option  | 
            ||
| 187 | // https://github.com/octobercms/october/pull/4060  | 
            ||
| 188 | 'placeholder' => self::LOCALIZATION_KEY . 'placeholders.series',  | 
            ||
| 189 | 'emptyOption' => self::LOCALIZATION_KEY . 'placeholders.series'  | 
            ||
| 190 | ],  | 
            ||
| 191 | ]);  | 
            ||
| 192 | });  | 
            ||
| 193 | }  | 
            ||
| 194 | |||
| 226 | 
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.