Conditions | 9 |
Paths | 2 |
Total Lines | 164 |
Code Lines | 101 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
173 | public function getCMSFields() |
||
174 | { |
||
175 | Requirements::css('silverstripe/userforms:client/dist/styles/userforms-cms.css'); |
||
176 | |||
177 | $this->beforeUpdateCMSFields(function ($fields) { |
||
178 | |||
179 | // remove |
||
180 | $fields->removeByName('OnCompleteMessageLabel'); |
||
181 | $fields->removeByName('OnCompleteMessage'); |
||
182 | $fields->removeByName('Fields'); |
||
183 | $fields->removeByName('EmailRecipients'); |
||
184 | |||
185 | // define tabs |
||
186 | $fields->findOrMakeTab('Root.FormOptions', _t(__CLASS__.'.CONFIGURATION', 'Configuration')); |
||
187 | $fields->findOrMakeTab('Root.Recipients', _t(__CLASS__.'.RECIPIENTS', 'Recipients')); |
||
188 | $fields->findOrMakeTab('Root.Submissions', _t(__CLASS__.'.SUBMISSIONS', 'Submissions')); |
||
189 | |||
190 | |||
191 | // text to show on complete |
||
192 | $onCompleteFieldSet = CompositeField::create( |
||
193 | $label = LabelField::create( |
||
194 | 'OnCompleteMessageLabel', |
||
195 | _t(__CLASS__.'.ONCOMPLETELABEL', 'Show on completion') |
||
196 | ), |
||
197 | $editor = HTMLEditorField::create( |
||
198 | 'OnCompleteMessage', |
||
199 | '', |
||
200 | $this->OnCompleteMessage |
||
201 | ) |
||
202 | ); |
||
203 | |||
204 | $onCompleteFieldSet->addExtraClass('field'); |
||
205 | |||
206 | $editor->setRows(3); |
||
207 | $label->addExtraClass('left'); |
||
208 | |||
209 | // Define config for email recipients |
||
210 | $emailRecipientsConfig = GridFieldConfig_RecordEditor::create(10); |
||
211 | $emailRecipientsConfig->getComponentByType(GridFieldAddNewButton::class) |
||
212 | ->setButtonName( |
||
213 | _t(__CLASS__.'.ADDEMAILRECIPIENT', 'Add Email Recipient') |
||
214 | ); |
||
215 | |||
216 | // who do we email on submission |
||
217 | $emailRecipients = GridField::create( |
||
218 | 'EmailRecipients', |
||
219 | '', |
||
220 | $this->EmailRecipients(), |
||
221 | $emailRecipientsConfig |
||
222 | ); |
||
223 | $emailRecipients |
||
224 | ->getConfig() |
||
225 | ->getComponentByType(GridFieldDetailForm::class) |
||
226 | ->setItemRequestClass(UserFormRecipientItemRequest::class); |
||
227 | |||
228 | $fields->addFieldsToTab('Root.FormOptions', $onCompleteFieldSet); |
||
229 | $fields->addFieldToTab('Root.Recipients', $emailRecipients); |
||
230 | $fields->addFieldsToTab('Root.FormOptions', $this->getFormOptions()); |
||
231 | |||
232 | |||
233 | // view the submissions |
||
234 | // make sure a numeric not a empty string is checked against this int column for SQL server |
||
235 | $parentID = (!empty($this->ID)) ? (int) $this->ID : 0; |
||
236 | |||
237 | // get a list of all field names and values used for print and export CSV views of the GridField below. |
||
238 | $columnSQL = <<<SQL |
||
239 | SELECT "SubmittedFormField"."Name" as "Name", COALESCE("EditableFormField"."Title", "SubmittedFormField"."Title") as "Title", COALESCE("EditableFormField"."Sort", 999) AS "Sort" |
||
240 | FROM "SubmittedFormField" |
||
241 | LEFT JOIN "SubmittedForm" ON "SubmittedForm"."ID" = "SubmittedFormField"."ParentID" |
||
242 | LEFT JOIN "EditableFormField" ON "EditableFormField"."Name" = "SubmittedFormField"."Name" AND "EditableFormField"."ParentID" = '$parentID' |
||
243 | WHERE "SubmittedForm"."ParentID" = '$parentID' |
||
244 | ORDER BY "Sort", "Title" |
||
245 | SQL; |
||
246 | // Sanitise periods in title |
||
247 | $columns = array(); |
||
248 | |||
249 | foreach (DB::query($columnSQL)->map() as $name => $title) { |
||
250 | $columns[$name] = trim(strtr($title, '.', ' ')); |
||
251 | } |
||
252 | |||
253 | $config = GridFieldConfig::create(); |
||
254 | $config->addComponent(new GridFieldToolbarHeader()); |
||
255 | $config->addComponent($sort = new GridFieldSortableHeader()); |
||
256 | $config->addComponent($filter = new UserFormsGridFieldFilterHeader()); |
||
257 | $config->addComponent(new GridFieldDataColumns()); |
||
258 | $config->addComponent(new GridFieldEditButton()); |
||
259 | $config->addComponent(new GridFieldDeleteAction()); |
||
260 | $config->addComponent(new GridFieldPageCount('toolbar-header-right')); |
||
261 | $config->addComponent($pagination = new GridFieldPaginator(25)); |
||
262 | $config->addComponent(new GridFieldDetailForm(null, true, false)); |
||
263 | $config->addComponent(new GridFieldButtonRow('after')); |
||
264 | $config->addComponent($export = new GridFieldExportButton('buttons-after-left')); |
||
265 | $config->addComponent($print = new GridFieldPrintButton('buttons-after-left')); |
||
266 | |||
267 | // show user form items in the summary tab |
||
268 | $summaryarray = array( |
||
269 | 'ID' => 'ID', |
||
270 | 'Created' => 'Created', |
||
271 | 'LastEdited' => 'Last Edited' |
||
272 | ); |
||
273 | |||
274 | foreach (EditableFormField::get()->filter(array('ParentID' => $parentID)) as $eff) { |
||
275 | if ($eff->ShowInSummary) { |
||
276 | $summaryarray[$eff->Name] = $eff->Title ?: $eff->Name; |
||
277 | } |
||
278 | } |
||
279 | |||
280 | $config->getComponentByType(GridFieldDataColumns::class)->setDisplayFields($summaryarray); |
||
281 | |||
282 | /** |
||
283 | * Support for {@link https://github.com/colymba/GridFieldBulkEditingTools} |
||
284 | */ |
||
285 | if (class_exists(BulkManager::class)) { |
||
286 | $config->addComponent(new BulkManager); |
||
287 | } |
||
288 | |||
289 | $sort->setThrowExceptionOnBadDataType(false); |
||
290 | $filter->setThrowExceptionOnBadDataType(false); |
||
291 | $pagination->setThrowExceptionOnBadDataType(false); |
||
292 | |||
293 | // attach every column to the print view form |
||
294 | $columns['Created'] = 'Created'; |
||
295 | $columns['SubmittedBy.Email'] = 'Submitter'; |
||
296 | $filter->setColumns($columns); |
||
297 | |||
298 | // print configuration |
||
299 | |||
300 | $print->setPrintHasHeader(true); |
||
301 | $print->setPrintColumns($columns); |
||
302 | |||
303 | // export configuration |
||
304 | $export->setCsvHasHeader(true); |
||
305 | $export->setExportColumns($columns); |
||
306 | |||
307 | $submissions = GridField::create( |
||
308 | 'Submissions', |
||
309 | '', |
||
310 | $this->Submissions()->sort('Created', 'DESC'), |
||
311 | $config |
||
312 | ); |
||
313 | $fields->addFieldToTab('Root.Submissions', $submissions); |
||
314 | $fields->addFieldToTab( |
||
315 | 'Root.FormOptions', |
||
316 | CheckboxField::create( |
||
317 | 'DisableSaveSubmissions', |
||
318 | _t(__CLASS__.'.SAVESUBMISSIONS', 'Disable Saving Submissions to Server') |
||
319 | ) |
||
320 | ); |
||
321 | }); |
||
322 | |||
323 | $fields = parent::getCMSFields(); |
||
324 | |||
325 | if ($this->EmailRecipients()->Count() == 0 && static::config()->recipients_warning_enabled) { |
||
326 | $fields->addFieldToTab('Root.Main', LiteralField::create( |
||
327 | 'EmailRecipientsWarning', |
||
328 | '<p class="message warning">' . _t( |
||
329 | __CLASS__.'.NORECIPIENTS', |
||
330 | 'Warning: You have not configured any recipients. Form submissions may be missed.' |
||
331 | ) |
||
332 | . '</p>' |
||
333 | ), 'Title'); |
||
334 | } |
||
335 | |||
336 | return $fields; |
||
337 | } |
||
406 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths