| Conditions | 1 |
| Paths | 1 |
| Total Lines | 114 |
| Code Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 74 | public function init() |
||
| 75 | { |
||
| 76 | $this->setName('info'); |
||
| 77 | |||
| 78 | $this->add( |
||
| 79 | [ |
||
| 80 | 'name' => 'email', |
||
| 81 | 'options' => [ |
||
| 82 | 'label' => /* @translate */ 'Email' |
||
| 83 | ], |
||
| 84 | 'attributes' => [ |
||
| 85 | 'required' => true, // marks the label as required. |
||
| 86 | ] |
||
| 87 | ] |
||
| 88 | ); |
||
| 89 | |||
| 90 | $this->add( |
||
| 91 | [ |
||
| 92 | 'name' => 'phone', |
||
| 93 | 'type' => '\Core\Form\Element\Phone', |
||
| 94 | 'options' => [ |
||
| 95 | 'label' => /* @translate */ 'Phone', |
||
| 96 | ], |
||
| 97 | 'maxlength' => 20, |
||
| 98 | 'attributes' => [ |
||
| 99 | 'required' => true, |
||
| 100 | ] |
||
| 101 | ] |
||
| 102 | ); |
||
| 103 | |||
| 104 | $this->add( |
||
| 105 | [ |
||
| 106 | 'name' => 'postalCode', |
||
| 107 | 'options' => array( |
||
| 108 | 'label' => /* @translate */ 'Postalcode' |
||
| 109 | ) |
||
| 110 | ] |
||
| 111 | ); |
||
| 112 | |||
| 113 | $this->add( |
||
| 114 | [ |
||
| 115 | 'name' => 'city', |
||
| 116 | 'options' => [ |
||
| 117 | 'label' => /* @translate */ 'City' |
||
| 118 | ] |
||
| 119 | ] |
||
| 120 | ); |
||
| 121 | |||
| 122 | $this->add( |
||
| 123 | array( |
||
| 124 | 'name' => 'gender', |
||
| 125 | 'type' => 'Zend\Form\Element\Select', |
||
| 126 | 'options' => [ |
||
| 127 | 'label' => /*@translate */ 'Salutation', |
||
| 128 | 'value_options' => [ |
||
| 129 | '' => '', |
||
| 130 | 'male' => /*@translate */ 'Mr.', |
||
| 131 | 'female' => /*@translate */ 'Mrs.', |
||
| 132 | ] |
||
| 133 | ], |
||
| 134 | 'attributes' => [ |
||
| 135 | 'data-placeholder' => /*@translate*/ 'please select', |
||
| 136 | 'data-allowclear' => 'false', |
||
| 137 | 'data-searchbox' => -1, // hide the search box |
||
| 138 | 'required' => true, // mark label as required |
||
| 139 | ], |
||
| 140 | ) |
||
| 141 | ); |
||
| 142 | |||
| 143 | $this->add( |
||
| 144 | array( |
||
| 145 | 'name' => 'firstName', |
||
| 146 | 'required' => true, |
||
| 147 | 'options' => [ |
||
| 148 | 'label' => /*@translate*/ 'First name', |
||
| 149 | 'maxlength' => 50, |
||
| 150 | ], |
||
| 151 | 'attributes' => [ |
||
| 152 | 'required' => true, |
||
| 153 | ] |
||
| 154 | ) |
||
| 155 | ); |
||
| 156 | |||
| 157 | $this->add( |
||
| 158 | array( |
||
| 159 | 'name' => 'lastName', |
||
| 160 | 'options' => array( |
||
| 161 | 'label' => /*@translate*/ 'Last name', |
||
| 162 | 'maxlength' => 50, |
||
| 163 | ), |
||
| 164 | 'attributes' => [ |
||
| 165 | 'required' => true, |
||
| 166 | ] |
||
| 167 | ) |
||
| 168 | ); |
||
| 169 | |||
| 170 | $this->add( |
||
| 171 | [ |
||
| 172 | 'name' => 'street', |
||
| 173 | 'options' => [ |
||
| 174 | 'label' => /*@translate*/ 'street' |
||
| 175 | ] |
||
| 176 | ] |
||
| 177 | ); |
||
| 178 | |||
| 179 | $this->add( |
||
| 180 | [ |
||
| 181 | 'name' => 'houseNumber', |
||
| 182 | 'options' => [ |
||
| 183 | 'label' => /*@translate*/ 'house number' |
||
| 184 | ] |
||
| 185 | ] |
||
| 186 | ); |
||
| 187 | } |
||
| 188 | |||
| 274 |