Conditions | 9 |
Paths | 41 |
Total Lines | 57 |
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 |
||
60 | public function ExpandableForm() |
||
61 | { |
||
62 | $record = $this->record; |
||
63 | |||
64 | if (!$record->canView()) { |
||
65 | $controller = $this->getToplevelController(); |
||
66 | return $controller->httpError(403); |
||
67 | } |
||
68 | |||
69 | if ($this->formorfields instanceof FieldList) { |
||
70 | $fields = $this->formorfields; |
||
71 | } elseif ($this->formorfields instanceof ViewableData) { |
||
72 | $form = $this->formorfields; |
||
73 | } elseif ($this->record->hasMethod('getExandableForm')) { |
||
74 | $form = $this->record->getExandableForm($this, __FUNCTION__); |
||
75 | $this->record->extend('updateExandableForm', $form); |
||
76 | } elseif ($this->record->hasMethod('getExandableFormFields')) { |
||
77 | $fields = $this->record->getExandableFormFields(); |
||
78 | $this->record->extend('updateExandableFormFields', $fields); |
||
79 | } else { |
||
80 | $fields = $this->record->scaffoldFormFields(); |
||
81 | $this->record->extend('updateExandableFormFields', $fields); |
||
82 | } |
||
83 | |||
84 | if (empty($form)) { |
||
85 | $actions = new FieldList(); |
||
86 | $actions->push( |
||
87 | FormAction::create('doSave', _t('GridFieldDetailForm.Save', 'Save')) |
||
88 | ->setUseButtonTag(true) |
||
89 | ->addExtraClass('ss-ui-action-constructive btn-primary font-icon-save') |
||
90 | ->setAttribute('data-icon', 'accept') |
||
91 | ->setAttribute('data-action-type', 'default') |
||
92 | ); |
||
93 | |||
94 | $form = new Form( |
||
95 | $this, |
||
96 | 'ExpandableForm', |
||
97 | $fields, |
||
98 | $actions |
||
99 | ); |
||
100 | } |
||
101 | |||
102 | if ($this->validator) { |
||
103 | $form->setValidator($this->validator); |
||
104 | } |
||
105 | |||
106 | $form->loadDataFrom($this->record, Form::MERGE_DEFAULT); |
||
107 | |||
108 | $form->IncludeFormTag = false; |
||
109 | |||
110 | // Ensure form is made readonly if editing not allowed |
||
111 | if (!$record->canEdit()) { |
||
112 | $form->makeReadonly(); |
||
113 | } |
||
114 | |||
115 | return $form; |
||
116 | } |
||
117 | |||
190 |