| Conditions | 7 |
| Paths | 8 |
| Total Lines | 65 |
| Code Lines | 40 |
| 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 |
||
| 72 | public function getEditForm($id = null, $fields = null) |
||
| 73 | { |
||
| 74 | $siteConfig = SiteConfig::current_site_config(); |
||
| 75 | $fields = $siteConfig->getCMSFields(); |
||
| 76 | |||
| 77 | // Tell the CMS what URL the preview should show |
||
| 78 | $home = Director::absoluteBaseURL(); |
||
| 79 | $fields->push(new HiddenField('PreviewURL', 'Preview URL', $home)); |
||
| 80 | |||
| 81 | // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load |
||
| 82 | /** @skipUpgrade */ |
||
| 83 | $fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator())); |
||
| 84 | $navField->setAllowHTML(true); |
||
| 85 | |||
| 86 | // Retrieve validator, if one has been setup (e.g. via data extensions). |
||
| 87 | if ($siteConfig->hasMethod("getCMSValidator")) { |
||
| 88 | $validator = $siteConfig->getCMSValidator(); |
||
| 89 | } else { |
||
| 90 | $validator = null; |
||
| 91 | } |
||
| 92 | |||
| 93 | $actions = $siteConfig->getCMSActions(); |
||
| 94 | $negotiator = $this->getResponseNegotiator(); |
||
| 95 | /** @var Form $form */ |
||
| 96 | $form = Form::create( |
||
| 97 | $this, |
||
| 98 | 'EditForm', |
||
| 99 | $fields, |
||
| 100 | $actions, |
||
| 101 | $validator |
||
| 102 | )->setHTMLID('Form_EditForm'); |
||
| 103 | $form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { |
||
| 104 | $request = $this->getRequest(); |
||
| 105 | if ($request->isAjax() && $negotiator) { |
||
| 106 | $result = $form->forTemplate(); |
||
| 107 | return $negotiator->respond($request, array( |
||
| 108 | 'CurrentForm' => function () use ($result) { |
||
| 109 | return $result; |
||
| 110 | } |
||
| 111 | )); |
||
| 112 | } |
||
| 113 | }); |
||
| 114 | $form->addExtraClass('flexbox-area-grow fill-height cms-content cms-edit-form'); |
||
| 115 | $form->setAttribute('data-pjax-fragment', 'CurrentForm'); |
||
| 116 | |||
| 117 | if ($form->Fields()->hasTabSet()) { |
||
| 118 | $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); |
||
| 119 | } |
||
| 120 | $form->setHTMLID('Form_EditForm'); |
||
| 121 | $form->loadDataFrom($siteConfig); |
||
| 122 | $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
||
| 123 | |||
| 124 | // Use <button> to allow full jQuery UI styling |
||
| 125 | $actions = $actions->dataFields(); |
||
| 126 | if ($actions) { |
||
| 127 | /** @var FormAction $action */ |
||
| 128 | foreach ($actions as $action) { |
||
| 129 | $action->setUseButtonTag(true); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | $this->extend('updateEditForm', $form); |
||
| 134 | |||
| 135 | return $form; |
||
| 136 | } |
||
| 137 | |||
| 166 |