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 |
||
148 | private function extendPostsController() |
||
149 | { |
||
150 | PostsController::extendFormFields(function ($form, $model) { |
||
151 | if (!$model instanceof PostModel) { |
||
|
|||
152 | return; |
||
153 | } |
||
154 | |||
155 | /* |
||
156 | * When extending the form, you should check to see if $formWidget->isNested === false |
||
157 | * as the Repeater FormWidget includes nested Form widgets which can cause your changes |
||
158 | * to be made in unexpected places. |
||
159 | * |
||
160 | * @link https://octobercms.com/docs/plugin/extending#extending-backend-form |
||
161 | */ |
||
162 | if (!empty($form->isNested)) { |
||
163 | return; |
||
164 | } |
||
165 | |||
166 | $tab = self::LOCALIZATION_KEY . 'navigation.taxonomy'; |
||
167 | |||
168 | $categoriesConfig = $form->getField('categories')->config; |
||
169 | $categoriesConfig['tab'] = $tab; |
||
170 | $categoriesConfig['mode'] = 'relation'; |
||
171 | $categoriesConfig['type'] = 'taglist'; |
||
172 | $categoriesConfig['label'] = 'rainlab.blog::lang.post.tab_categories'; |
||
173 | $categoriesConfig['comment'] = "rainlab.blog::lang.post.categories_comment"; |
||
174 | $categoriesConfig['placeholder'] = self::LOCALIZATION_KEY . 'placeholders.categories'; |
||
175 | unset($categoriesConfig['commentAbove']); |
||
176 | |||
177 | $form->removeField('categories'); |
||
178 | |||
179 | $form->addSecondaryTabFields([ |
||
180 | 'categories' => $categoriesConfig, |
||
181 | 'tags' => [ |
||
182 | 'label' => self::LOCALIZATION_KEY . 'form.tags.label', |
||
183 | 'comment' => self::LOCALIZATION_KEY . 'form.tags.comment_post', |
||
184 | 'mode' => 'relation', |
||
185 | 'tab' => $tab, |
||
186 | 'type' => 'taglist', |
||
187 | 'placeholder' => self::LOCALIZATION_KEY . 'placeholders.tags', |
||
188 | ], |
||
189 | 'series' => [ |
||
190 | 'label' => self::LOCALIZATION_KEY . 'form.series.label', |
||
191 | 'tab' => $tab, |
||
192 | 'type' => 'relation', |
||
193 | 'nameFrom' => 'title', |
||
194 | 'comment' => self::LOCALIZATION_KEY . 'form.series.comment', |
||
195 | // October CMS has a bug with displaying of placeholders without an explicit empty option |
||
196 | // https://github.com/octobercms/october/pull/4060 |
||
197 | 'placeholder' => self::LOCALIZATION_KEY . 'placeholders.series', |
||
198 | 'emptyOption' => self::LOCALIZATION_KEY . 'placeholders.series' |
||
199 | ], |
||
200 | ]); |
||
201 | }); |
||
202 | } |
||
203 | |||
235 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.