Conditions | 7 |
Paths | 8 |
Total Lines | 57 |
Code Lines | 41 |
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 |
||
77 | public function getEditForm($id = null, $fields = null) |
||
78 | { |
||
79 | $config = Setting::current_foxy_setting(); |
||
80 | $fields = $config->getCMSFields(); |
||
81 | // Tell the CMS what URL the preview should show |
||
82 | $home = Director::absoluteBaseURL(); |
||
83 | $fields->push(new HiddenField('PreviewURL', 'Preview URL', $home)); |
||
84 | // Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load |
||
85 | $fields->push($navField = new LiteralField( |
||
86 | 'SilverStripeNavigator', |
||
87 | $this->getSilverStripeNavigator() |
||
88 | )); |
||
89 | $navField->setAllowHTML(true); |
||
90 | // Retrieve validator, if one has been setup (e.g. via data extensions). |
||
91 | if ($config->hasMethod('getCMSValidator')) { |
||
92 | $validator = $config->getCMSValidator(); |
||
93 | } else { |
||
94 | $validator = null; |
||
95 | } |
||
96 | $actions = $config->getCMSActions(); |
||
97 | $negotiator = $this->getResponseNegotiator(); |
||
98 | $form = Form::create( |
||
99 | $this, |
||
100 | 'EditForm', |
||
101 | $fields, |
||
102 | $actions, |
||
103 | $validator |
||
104 | )->setHTMLID('Form_EditForm'); |
||
105 | $form->setValidationResponseCallback(function (ValidationResult $errors) use ($negotiator, $form) { |
||
106 | $request = $this->getRequest(); |
||
107 | if ($request->isAjax() && $negotiator) { |
||
108 | $result = $form->forTemplate(); |
||
109 | return $negotiator->respond($request, array( |
||
110 | 'CurrentForm' => function () use ($result) { |
||
111 | return $result; |
||
112 | }, |
||
113 | )); |
||
114 | } |
||
115 | }); |
||
116 | $form->addExtraClass('flexbox-area-grow fill-height cms-content cms-edit-form'); |
||
117 | $form->setAttribute('data-pjax-fragment', 'CurrentForm'); |
||
118 | if ($form->Fields()->hasTabSet()) { |
||
119 | $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); |
||
120 | } |
||
121 | $form->setHTMLID('Form_EditForm'); |
||
122 | $form->loadDataFrom($config); |
||
123 | $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
||
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 | $this->extend('updateEditForm', $form); |
||
133 | return $form; |
||
134 | } |
||
175 |