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