| Conditions | 14 |
| Paths | 2 |
| Total Lines | 50 |
| Code Lines | 28 |
| 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 |
||
| 10 | public function decorateCMSFields(FieldList $fields) |
||
| 11 | { |
||
| 12 | //right titles ... |
||
| 13 | $list = $fields->dataFields(); |
||
| 14 | |||
| 15 | $rightFieldDescriptions = Config::inst()->get($this->owner->ClassName, 'field_labels_right'); |
||
| 16 | if (is_array($rightFieldDescriptions) && count($rightFieldDescriptions)) { |
||
| 17 | foreach ($list as $formField) { |
||
| 18 | |||
| 19 | // right titles ... |
||
| 20 | $desc = ''; |
||
| 21 | $fieldName = $formField->getName(); |
||
| 22 | if (isset($rightFieldDescriptions[$fieldName])) { |
||
| 23 | $desc = $rightFieldDescriptions[$fieldName]; |
||
| 24 | } |
||
| 25 | if (!$desc) { |
||
| 26 | if (isset($rightFieldDescriptions[$fieldName.'ID'])) { |
||
| 27 | $desc = $rightFieldDescriptions[$fieldName]; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | if (!$desc) { |
||
| 31 | if (substr($fieldName, -2) === 'ID') { |
||
| 32 | $fieldName = substr($fieldName, -2); |
||
| 33 | if (isset($rightFieldDescriptions[$fieldName])) { |
||
| 34 | $desc = $rightFieldDescriptions[$fieldName]; |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | if ($desc) { |
||
| 39 | if ($formField->hasMethod('setDescription')) { |
||
| 40 | $formField->setDescription($desc); |
||
| 41 | } else { |
||
| 42 | $formField->setRightTitle($desc); |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | |||
| 47 | //HTML Editor fields |
||
| 48 | //HTML |
||
| 49 | if ($formField instanceof HTMLEditorField) { |
||
| 50 | $formField->setRows(12) |
||
| 51 | ->setRightTitle('Need more room? Use the FULL SCREEN button (last button above).'); |
||
| 52 | } |
||
| 53 | if ($formField instanceof DateField) { |
||
| 54 | $formField->setConfig('showcalendar', true); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | return $fields; |
||
| 59 | } |
||
| 60 | |||
| 63 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.