| Conditions | 2 |
| Paths | 1 |
| Total Lines | 84 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 120 | public function getCMSFields() |
||
| 121 | { |
||
| 122 | $this->beforeUpdateCMSFields(function (FieldList $fields) { |
||
| 123 | |||
| 124 | $fields->addFieldsToTab( |
||
| 125 | 'Root.Main', |
||
| 126 | [ |
||
| 127 | $toggle = FieldGroup::create( |
||
| 128 | 'RecipeStatistics', |
||
| 129 | [ |
||
| 130 | TextField::create('Servings') |
||
| 131 | ->setTitle('Servings'), |
||
| 132 | TextField::create('PrepTime') |
||
| 133 | ->setTitle('Prep Time'), |
||
| 134 | TextField::create('CookTime') |
||
| 135 | ->setTitle('Cook Time'), |
||
| 136 | TextField::create('Difficulty') |
||
| 137 | ->setTitle('Difficulty'), |
||
| 138 | ] |
||
| 139 | )->setTitle('Info'), |
||
| 140 | ], |
||
| 141 | 'Content' |
||
| 142 | ); |
||
| 143 | |||
| 144 | if ($this->exists()) { |
||
| 145 | $fields->addFieldToTab( |
||
| 146 | 'Root.Ingredients', |
||
| 147 | $ingredients = GridField::create( |
||
| 148 | 'Ingredients', |
||
| 149 | 'Ingredients', |
||
| 150 | $this->Ingredients(), |
||
| 151 | $ingredientsConfig = GridFieldConfig_RelationEditor::create() |
||
| 152 | ) |
||
| 153 | ); |
||
| 154 | |||
| 155 | $fields->addFieldToTab( |
||
| 156 | 'Root.Directions', |
||
| 157 | $directions = GridField::create( |
||
| 158 | 'Directions', |
||
| 159 | 'Directions', |
||
| 160 | $this->Directions(), |
||
| 161 | $directionsConfig = GridFieldConfig_RelationEditor::create() |
||
| 162 | ) |
||
| 163 | ); |
||
| 164 | |||
| 165 | $fields->addFieldsToTab( |
||
| 166 | 'Root.Categories', |
||
| 167 | [ |
||
| 168 | ReadonlyField::create('PrimaryCategoryDisplay') |
||
| 169 | ->setTitle('Primary Category') |
||
| 170 | ->setValue($this->getPrimaryCategory()->Title), |
||
| 171 | $categories = GridField::create( |
||
| 172 | 'Categories', |
||
| 173 | 'Additional Categories', |
||
| 174 | $this->Categories()->exclude('ID', $this->ParentID)->sort('SortOrder'), |
||
| 175 | $catConfig = GridFieldConfig_RelationEditor::create() |
||
| 176 | ), |
||
| 177 | ] |
||
| 178 | ); |
||
| 179 | |||
| 180 | $ingredientsConfig |
||
| 181 | ->addComponent(new GridFieldOrderableRows('Sort')) |
||
| 182 | ->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
||
| 183 | |||
| 184 | $directionsConfig |
||
| 185 | ->addComponent(new GridFieldOrderableRows('Sort')) |
||
| 186 | ->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
||
| 187 | |||
| 188 | $catConfig |
||
| 189 | ->removeComponentsByType([ |
||
| 190 | GridFieldAddExistingAutocompleter::class, |
||
| 191 | GridFieldArchiveAction::class, |
||
| 192 | GridFieldEditButton::class, |
||
| 193 | ]) |
||
| 194 | ->addComponents( |
||
| 195 | new GridFieldOrderableRows('SortOrder'), |
||
| 196 | $list = new GridFieldAddExistingSearchButton() |
||
| 197 | ); |
||
| 198 | |||
| 199 | $list->setSearchList(RecipeCategoryPage::get()->exclude('ID', $this->ParentID)); |
||
| 200 | } |
||
| 201 | }); |
||
| 202 | |||
| 203 | return parent::getCMSFields(); |
||
| 204 | } |
||
| 251 |