| Conditions | 3 |
| Paths | 4 |
| Total Lines | 114 |
| Code Lines | 78 |
| 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 |
||
| 149 | public function edit($view, $id = null, $object = null) |
||
| 150 | {
|
||
| 151 | $App = $this->App(); |
||
| 152 | $W = bab_Widgets(); |
||
| 153 | |||
| 154 | $customSectionSet = $App->CustomSectionSet(); |
||
| 155 | if (isset($id)) {
|
||
| 156 | $record = $customSectionSet->request($id); |
||
| 157 | } else {
|
||
| 158 | $record = $customSectionSet->newRecord(); |
||
| 159 | $record->object = $object; |
||
| 160 | } |
||
| 161 | |||
| 162 | $page = $App->Ui()->Page(); |
||
| 163 | |||
| 164 | $page->setTitle($App->translate('Section'));
|
||
| 165 | $page->addClass('app-page-editor');
|
||
| 166 | |||
| 167 | $editor = new app_Editor($App); |
||
| 168 | $editor->setHiddenValue('tg', $App->controllerTg);
|
||
| 169 | $editor->setHiddenValue('data[view]', $view);
|
||
| 170 | if ($record->id) {
|
||
| 171 | $editor->setHiddenValue('data[id]', $record->id);
|
||
| 172 | } |
||
| 173 | $editor->setName('data');
|
||
| 174 | $editor->addItem( |
||
| 175 | $W->Hidden()->setName('object')
|
||
| 176 | ); |
||
| 177 | |||
| 178 | $editor->addItem( |
||
| 179 | $W->LabelledWidget( |
||
| 180 | $App->translate('Name'),
|
||
| 181 | $W->LineEdit()->setName('name')
|
||
| 182 | ) |
||
| 183 | ); |
||
| 184 | |||
| 185 | $sizePolicyClassnames = array( |
||
| 186 | 'col-md-1' => '1', |
||
| 187 | 'col-md-2' => '2', |
||
| 188 | 'col-md-3' => '3', |
||
| 189 | 'col-md-4' => '4', |
||
| 190 | 'col-md-5' => '5', |
||
| 191 | 'col-md-6' => '6', |
||
| 192 | 'col-md-7' => '7', |
||
| 193 | 'col-md-8' => '8', |
||
| 194 | 'col-md-9' => '9', |
||
| 195 | 'col-md-10' => '10', |
||
| 196 | 'col-md-11' => '11', |
||
| 197 | 'col-md-12' => '12', |
||
| 198 | ); |
||
| 199 | |||
| 200 | |||
| 201 | $editor->addItem( |
||
| 202 | $W->LabelledWidget( |
||
| 203 | $App->translate('Size policy'),
|
||
| 204 | $W->Select() |
||
| 205 | ->addOptions($sizePolicyClassnames) |
||
| 206 | ->setName('sizePolicy')
|
||
| 207 | ) |
||
| 208 | ); |
||
| 209 | $editor->addItem( |
||
| 210 | $W->LabelledWidget( |
||
| 211 | $App->translate('Fields layout'),
|
||
| 212 | $W->Select() |
||
| 213 | ->addOptions(app_CustomSection::getFieldsLayouts()) |
||
| 214 | ->setName('fieldsLayout')
|
||
| 215 | ) |
||
| 216 | ); |
||
| 217 | $editor->addItem( |
||
| 218 | $W->LabelledWidget( |
||
| 219 | $App->translate('Foldable'),
|
||
| 220 | $foldableCheckBox = $W->CheckBox()->setName('foldable')
|
||
| 221 | ) |
||
| 222 | ); |
||
| 223 | $editor->addItem( |
||
| 224 | $foldedWidget = $W->LabelledWidget( |
||
| 225 | $App->translate('Folded'),
|
||
| 226 | $W->CheckBox()->setName('folded')
|
||
| 227 | ) |
||
| 228 | ); |
||
| 229 | $editor->addItem( |
||
| 230 | $W->LabelledWidget( |
||
| 231 | $App->translate('Editable'),
|
||
| 232 | $W->CheckBox()->setName('editable')
|
||
| 233 | ) |
||
| 234 | ); |
||
| 235 | $editor->addItem( |
||
| 236 | $W->LabelledWidget( |
||
| 237 | $App->translate('Class'),
|
||
| 238 | $W->LineEdit()->setName('classname')
|
||
| 239 | ) |
||
| 240 | ); |
||
| 241 | |||
| 242 | $foldableCheckBox->setAssociatedDisplayable($foldedWidget, array(true)); |
||
| 243 | |||
| 244 | $editor->setValues($record->getFormOutputValues(), array('data'));
|
||
| 245 | |||
| 246 | $editor->addButton( |
||
| 247 | $W->SubmitButton(/*'save'*/) |
||
| 248 | ->validate(true) |
||
| 249 | ->setAction($this->proxy()->save()) |
||
| 250 | ->setAjaxAction() |
||
| 251 | ->setLabel($App->translate('Save'))
|
||
| 252 | ); |
||
| 253 | |||
| 254 | $editor->addButton( |
||
| 255 | $W->SubmitButton(/*'cancel'*/) |
||
| 256 | ->addClass('widget-close-dialog')
|
||
| 257 | ->setLabel($App->translate('Cancel'))
|
||
| 258 | ); |
||
| 259 | |||
| 260 | $page->addItem($editor); |
||
| 261 | |||
| 262 | return $page; |
||
| 263 | } |
||
| 384 |