| Conditions | 2 |
| Paths | 2 |
| Total Lines | 51 |
| Code Lines | 34 |
| 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 |
||
| 62 | protected function createContactForm() |
||
| 63 | { |
||
| 64 | $form = UserDefinedForm::create(array( |
||
| 65 | 'Title' => 'Contact', |
||
| 66 | 'URLSegment' => 'contact', |
||
| 67 | 'Content' => '<p>$UserDefinedForm</p>', |
||
| 68 | 'SubmitButtonText' => 'Submit', |
||
| 69 | 'ClearButtonText' => 'Clear', |
||
| 70 | 'OnCompleteMessage' => "<p>Thanks, we've received your submission and will be in touch shortly.</p>", |
||
| 71 | 'EnableLiveValidation' => true |
||
| 72 | )); |
||
| 73 | |||
| 74 | $form->write(); |
||
| 75 | |||
| 76 | // Add form fields |
||
| 77 | $fields = array( |
||
| 78 | EditableFormStep::create(array( |
||
| 79 | 'Title' => _t('EditableFormStep.TITLE_FIRST', 'First Page') |
||
| 80 | )), |
||
| 81 | EditableTextField::create(array( |
||
| 82 | 'Title' => 'Name', |
||
| 83 | 'Required' => true, |
||
| 84 | 'RightTitle' => 'Please enter your first and last name' |
||
| 85 | )), |
||
| 86 | EditableEmailField::create(array( |
||
| 87 | 'Title' => 'Email', |
||
| 88 | 'Required' => true, |
||
| 89 | 'Placeholder' => '[email protected]' |
||
| 90 | )), |
||
| 91 | EditableTextField::create(array( |
||
| 92 | 'Title' => 'Subject' |
||
| 93 | )), |
||
| 94 | EditableTextField::create(array( |
||
| 95 | 'Title' => 'Message', |
||
| 96 | 'Required' => true, |
||
| 97 | 'Rows' => 5 |
||
| 98 | )) |
||
| 99 | ); |
||
| 100 | |||
| 101 | foreach ($fields as $field) { |
||
| 102 | $field->write(); |
||
| 103 | $form->Fields()->add($field); |
||
| 104 | $field->publish('Stage', 'Live'); |
||
| 105 | } |
||
| 106 | |||
| 107 | $form->publish('Stage', 'Live'); |
||
| 108 | $form->flushCache(); |
||
| 109 | |||
| 110 | $this->output(' + Created "contact" UserDefinedForm page'); |
||
| 111 | |||
| 112 | return $this; |
||
| 113 | } |
||
| 133 |