Conditions | 4 |
Paths | 3 |
Total Lines | 86 |
Code Lines | 64 |
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 |
||
85 | public function updateCMSFields(FieldList $fields) |
||
86 | { |
||
87 | $fields->removeByName([ |
||
88 | 'Animation', |
||
89 | 'Loop', |
||
90 | 'Animate', |
||
91 | 'ThumbnailNav', |
||
92 | 'SliderControlNav', |
||
93 | 'SliderDirectionNav', |
||
94 | 'CarouselControlNav', |
||
95 | 'CarouselDirectionNav', |
||
96 | 'CarouselThumbnailCt', |
||
97 | 'FlexSliderSpeed', |
||
98 | 'Slides', |
||
99 | ]); |
||
100 | |||
101 | // Slides |
||
102 | if ($this->owner->ID) { |
||
103 | $config = GridFieldConfig_RecordEditor::create(); |
||
104 | $config->addComponent(new GridFieldOrderableRows('SortOrder')); |
||
105 | $config->removeComponentsByType([ |
||
106 | GridFieldAddExistingAutocompleter::class, |
||
107 | GridFieldDeleteAction::class, |
||
108 | ]); |
||
109 | $SlidesField = GridField::create( |
||
110 | 'Slides', |
||
111 | _t(__CLASS__ . '.SLIDES', 'Slides'), |
||
112 | $this->owner->Slides()->sort('SortOrder'), |
||
113 | $config |
||
114 | ); |
||
115 | |||
116 | $slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__ . '.SLIDES', 'Slides'); |
||
117 | |||
118 | $animations = []; |
||
119 | $animationOptions = $this->owner->dbObject('Animation')->getEnum(); |
||
120 | foreach ($animationOptions as $value) { |
||
121 | $animations[$value] = _t(__CLASS__ . ".$value", $value); |
||
122 | } |
||
123 | |||
124 | $fields->addFieldsToTab("Root.{$slideTitle}", [ |
||
125 | $SlidesField, |
||
126 | ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [ |
||
127 | DropdownField::create( |
||
128 | 'Animation', |
||
129 | _t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'), |
||
130 | $animations |
||
131 | ), |
||
132 | CheckboxField::create( |
||
133 | 'Animate', |
||
134 | _t(__CLASS__ . '.ANIMATE', 'Animate automatically') |
||
135 | ), |
||
136 | CheckboxField::create( |
||
137 | 'Loop', |
||
138 | _t(__CLASS__ . '.LOOP', 'Loop the carousel') |
||
139 | ), |
||
140 | CheckboxField::create( |
||
141 | 'SliderControlNav', |
||
142 | _t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav') |
||
143 | ), |
||
144 | CheckboxField::create( |
||
145 | 'SliderDirectionNav', |
||
146 | _t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav') |
||
147 | ), |
||
148 | CheckboxField::create( |
||
149 | 'ThumbnailNav', |
||
150 | _t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation') |
||
151 | ), |
||
152 | //DisplayLogicWrapper::create( |
||
153 | CheckboxField::create( |
||
154 | 'CarouselControlNav', |
||
155 | _t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav') |
||
156 | ), |
||
157 | CheckboxField::create( |
||
158 | 'CarouselDirectionNav', |
||
159 | _t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav') |
||
160 | ), |
||
161 | NumericField::create( |
||
162 | 'CarouselThumbnailCt', |
||
163 | _t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails') |
||
164 | ), |
||
165 | NumericField::create( |
||
166 | 'FlexSliderSpeed', |
||
167 | _t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed') |
||
168 | ) |
||
169 | ->setDescription('In Seconds') |
||
170 | ->setScale(2), |
||
171 | ]), |
||
304 |