Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
Code Lines | 41 |
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 |
||
21 | public function getCMSFields() |
||
22 | { |
||
23 | $fields = parent::getCMSFields(); |
||
24 | |||
25 | $fields->push( |
||
26 | DropdownField::create('Layout') |
||
27 | ->setSource( |
||
28 | singleton('ContentBlock_ColumnLayout') |
||
29 | ->dbObject('Layout') |
||
30 | ->enumValues() |
||
31 | ) |
||
32 | ); |
||
33 | |||
34 | $colourSource = Config::inst()->get('ContentBlock_ColumnLayout', 'colour_options'); |
||
35 | |||
36 | //Column One ------- |
||
37 | $columnOne = DisplayLogicWrapper::create(CompositeField::create([ |
||
38 | HeaderField::create('ColumnOne', 'Column One'), |
||
39 | DropdownField::create( |
||
40 | 'ColumnOneColour', |
||
41 | 'Colour', |
||
42 | $colourSource |
||
43 | ), |
||
44 | HTMLEditorField::create('ColumnOneContent', 'Content'), |
||
45 | ])); |
||
46 | //Display if One Column || Two Column || Three Column |
||
47 | $columnOne->displayIf('Layout')->isEqualTo('One Column') |
||
48 | ->orIf('Layout')->isEqualTo('Two Column') |
||
49 | ->orIf('Layout')->isEqualTo('Three Column'); |
||
50 | $fields->push($columnOne); |
||
51 | |||
52 | //Column Two ------- |
||
53 | //Display if Two Column |
||
54 | $columnTwo = DisplayLogicWrapper::create(CompositeField::create([ |
||
55 | HeaderField::create('ColumnTwo', 'Column Two'), |
||
56 | DropdownField::create( |
||
57 | 'ColumnTwoColour', |
||
58 | 'Colour', |
||
59 | $colourSource |
||
60 | ), |
||
61 | HTMLEditorField::create('ColumnTwoContent', 'Content'), |
||
62 | ])); |
||
63 | $columnTwo->displayIf('Layout')->isEqualTo('Two Column') |
||
64 | ->orIf('Layout')->isEqualTo('Three Column'); |
||
65 | $fields->push($columnTwo); |
||
66 | |||
67 | //Column Three ------- |
||
68 | $columnThree = DisplayLogicWrapper::create(CompositeField::create([ |
||
69 | HeaderField::create('ColumnThree', 'Column Three'), |
||
70 | DropdownField::create( |
||
71 | 'ColumnThreeColour', |
||
72 | 'Colour', |
||
73 | $colourSource |
||
74 | ), |
||
75 | HTMLEditorField::create('ColumnThreeContent', 'Content'), |
||
76 | ])); |
||
77 | $columnThree->displayIf('Layout')->isEqualTo('Three Column'); |
||
78 | $fields->push($columnThree); |
||
79 | |||
80 | $this->extend('updateCMSFields', $fields); |
||
81 | |||
82 | return $fields; |
||
83 | } |
||
84 | |||
151 |
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.