| Conditions | 5 |
| Paths | 8 |
| Total Lines | 59 |
| Code Lines | 29 |
| 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 |
||
| 68 | public function getEditForm($id = null, $fields = null) |
||
| 69 | { |
||
| 70 | $siteConfig = SiteConfig::current_site_config(); |
||
| 71 | $fields = $siteConfig->getCMSFields(); |
||
| 72 | |||
| 73 | // Retrieve validator, if one has been setup (e.g. via data extensions). |
||
| 74 | if ($siteConfig->hasMethod("getCMSValidator")) { |
||
| 75 | $validator = $siteConfig->getCMSValidator(); |
||
| 76 | } else { |
||
| 77 | $validator = null; |
||
| 78 | } |
||
| 79 | |||
| 80 | $actions = $siteConfig->getCMSActions(); |
||
| 81 | $saveAction = $actions->fieldByName("action_save_siteconfig"); |
||
| 82 | if ($saveAction) { |
||
| 83 | $saveAction->removeExtraClass("btn-primary"); |
||
| 84 | $saveAction->addExtraClass("btn-outline-success"); |
||
| 85 | $saveAction->setIcon(MaterialIcons::DONE); |
||
| 86 | } |
||
| 87 | // $negotiator = $this->getResponseNegotiator(); |
||
| 88 | /** @var Form $form */ |
||
| 89 | $form = Form::create( |
||
| 90 | $this, |
||
| 91 | 'EditForm', |
||
| 92 | $fields, |
||
| 93 | $actions, |
||
| 94 | $validator |
||
| 95 | )->setHTMLID('Form_EditForm'); |
||
| 96 | |||
| 97 | /* |
||
| 98 | $form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { |
||
| 99 | $request = $this->getRequest(); |
||
| 100 | if ($request->isAjax() && $negotiator) { |
||
| 101 | $result = $form->forTemplate(); |
||
| 102 | return $negotiator->respond($request, array( |
||
| 103 | 'CurrentForm' => function () use ($result) { |
||
| 104 | return $result; |
||
| 105 | } |
||
| 106 | )); |
||
| 107 | } |
||
| 108 | });*/ |
||
| 109 | |||
| 110 | $this->setCMSTabset($form); |
||
| 111 | |||
| 112 | $form->setHTMLID('Form_EditForm'); |
||
| 113 | $form->loadDataFrom($siteConfig); |
||
| 114 | $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
||
| 115 | |||
| 116 | $actions = $actions->dataFields(); |
||
| 117 | if ($actions) { |
||
| 118 | /** @var FormAction $action */ |
||
| 119 | foreach ($actions as $action) { |
||
| 120 | $action->setUseButtonTag(true); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | $this->extend('updateEditForm', $form); |
||
| 125 | |||
| 126 | return $form; |
||
| 127 | } |
||
| 172 |