Conditions | 1 |
Paths | 1 |
Total Lines | 115 |
Code Lines | 76 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 3 | 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 |
||
31 | public function init() |
||
32 | { |
||
33 | $this->setAttribute('method', 'post'); |
||
34 | |||
35 | $this->add([ |
||
36 | 'name' => 'id', |
||
37 | 'attributes' => [ |
||
38 | 'type' => 'hidden', |
||
39 | ], |
||
40 | ]); |
||
41 | |||
42 | $this->add([ |
||
43 | 'name' => 'name', |
||
44 | 'attributes' => [ |
||
45 | 'type' => 'text', |
||
46 | 'class' => 'form-control', |
||
47 | ], |
||
48 | 'options' => [ |
||
49 | 'label' => 'Name', |
||
50 | ], |
||
51 | ]); |
||
52 | |||
53 | $this->add([ |
||
54 | 'type' => 'Zend\Form\Element\Select', |
||
55 | 'name' => 'gender', |
||
56 | 'options' => [ |
||
57 | 'label' => 'Gender', |
||
58 | 'value_options' => [ |
||
59 | '1' => 'Select your gender', |
||
60 | '2' => 'Female', |
||
61 | '3' => 'Male', |
||
62 | ], |
||
63 | ], |
||
64 | 'attributes' => [ |
||
65 | 'class' => 'form-control', |
||
66 | 'value' => '1', //set selected to '1' |
||
67 | ], |
||
68 | ]); |
||
69 | |||
70 | $this->add([ |
||
71 | 'type' => 'Zend\Form\Element\MultiCheckbox', |
||
72 | 'name' => 'hobby', |
||
73 | 'options' => [ |
||
74 | 'label' => 'Please choose one/more of the hobbies', |
||
75 | 'value_options' => [ |
||
76 | '1' => 'Cooking', |
||
77 | '2' => 'Writing', |
||
78 | '3' => 'Others', |
||
79 | ], |
||
80 | ], |
||
81 | 'attributes' => [ |
||
82 | 'class' => 'form-control', |
||
83 | 'value' => '1', //set checked to '1' |
||
84 | ], |
||
85 | ]); |
||
86 | |||
87 | $this->add([ |
||
88 | 'type' => 'Zend\Form\Element\Email', |
||
89 | 'name' => 'email', |
||
90 | 'options' => [ |
||
91 | 'label' => 'Email', |
||
92 | ], |
||
93 | 'attributes' => [ |
||
94 | 'placeholder' => '[email protected]', |
||
95 | ], |
||
96 | ]); |
||
97 | |||
98 | $this->add([ |
||
99 | 'type' => 'Zend\Form\Element\Date', |
||
100 | 'name' => 'birth', |
||
101 | 'options' => [ |
||
102 | 'label' => 'Birth ( Y/m/d )', |
||
103 | ], |
||
104 | 'attributes' => [ |
||
105 | 'class' => 'form-control', |
||
106 | ], |
||
107 | ]); |
||
108 | |||
109 | $this->add([ |
||
110 | 'name' => 'address', |
||
111 | 'attributes' => [ |
||
112 | 'class' => 'form-control', |
||
113 | 'type' => 'textarea', |
||
114 | ], |
||
115 | 'options' => [ |
||
116 | 'label' => 'Address', |
||
117 | ], |
||
118 | ]); |
||
119 | |||
120 | $this->add([ |
||
121 | 'type' => 'Zend\Form\Element\Radio', |
||
122 | 'name' => 'direction', |
||
123 | 'options' => [ |
||
124 | 'label' => 'Please choose one of the directions', |
||
125 | 'value_options' => [ |
||
126 | '1' => 'Programming', |
||
127 | '2' => 'Design', |
||
128 | ], |
||
129 | ], |
||
130 | 'attributes' => [ |
||
131 | 'class' => 'form-control', |
||
132 | 'value' => '1', //set checked to '1' |
||
133 | ], |
||
134 | ]); |
||
135 | |||
136 | $this->add([ |
||
137 | 'name' => 'submit', |
||
138 | 'attributes' => [ |
||
139 | 'class' => 'form-control', |
||
140 | 'type' => 'submit', |
||
141 | 'value' => 'Go', |
||
142 | 'id' => 'submitbutton', |
||
143 | ], |
||
144 | ]); |
||
145 | } |
||
146 | |||
239 |