Conditions | 8 |
Paths | 26 |
Total Lines | 79 |
Code Lines | 23 |
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 |
||
143 | public function generateFormByArray($form_array) |
||
144 | { |
||
145 | // debug display incomming form description array |
||
146 | #\Koch\Debug\Debug::firebug($form_array); |
||
147 | |||
148 | // loop over all elements of the form description array |
||
149 | foreach ($form_array as $form_array_section => $form_array_elements) { |
||
150 | #\Koch\Debug\Debug::firebug($form_array_elements); |
||
151 | #\Koch\Debug\Debug::firebug($form_array_section); |
||
152 | |||
153 | foreach ($form_array_elements as $form_array_element_number => $form_array_element) { |
||
154 | #\Koch\Debug\Debug::firebug($form_array_element); |
||
155 | |||
156 | // @todo ensure these elements exist !!! |
||
157 | |||
158 | // add a new element to this form, position it by it's number in the array |
||
159 | $this->addElement($form_array_element['formfieldtype'], $form_array_element_number); |
||
160 | |||
161 | // fetch the new formelement object by its positional number |
||
162 | $formelement = $this->getElementByPosition($form_array_element_number); |
||
163 | |||
164 | #\Koch\Debug\Debug::firebug($formelement); |
||
165 | |||
166 | // and apply the settings (id, name, description, value) to it |
||
167 | $formelement->setID($form_array_element['id']); |
||
168 | |||
169 | // provide array access to the form data (in $_POST) by prefixing it with the formulars name |
||
170 | // @todo if you group formelements, add the name of the group here |
||
171 | $formelement->setName($this->getName() . '[' . $form_array_section . '][' . $form_array_element['name'] . ']'); |
||
172 | $formelement->setDescription($form_array_element['description']); |
||
173 | |||
174 | // @todo consider this as formdebug display (sets formname as label) |
||
175 | #$formelement->setLabel($this->getName().'['.$form_array_element['name'].']'); |
||
176 | |||
177 | $formelement->setLabel($form_array_element['label']); |
||
178 | |||
179 | // set the options['selected'] value as default value |
||
180 | if ($form_array_element['options']['selected'] !== null) { |
||
181 | $formelement->setDefault($form_array_element['options']['selected']); |
||
182 | unset($form_array_element['options']['selected']); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * check if $form_array_element['value'] is of type array or single value |
||
187 | * array indicates, that we have a request for |
||
188 | * something like a multiselect formfield with several options. |
||
189 | */ |
||
190 | if (is_array($form_array_element['value']) === false) { |
||
191 | $formelement->setValue($form_array_element['value']); |
||
192 | } else { |
||
193 | $formelement->setOptions($form_array_element['value']); |
||
194 | } |
||
195 | |||
196 | /* |
||
197 | * OPTIONAL ELEMENTS |
||
198 | */ |
||
199 | |||
200 | // if we have a class attribute defined, then add it (optional) |
||
201 | if ($form_array_element['class'] !== null) { |
||
202 | $formelement->setCssClass($form_array_element['class']); |
||
203 | } |
||
204 | |||
205 | /* |
||
206 | * set a decorator for the formelement |
||
207 | * optional because: the default decorator would be active |
||
208 | */ |
||
209 | if ($form_array_element['decorator'] !== null) { |
||
210 | if ($form_array_element['decorator'] instanceof \Koch\Form\Element\Decorator) { |
||
211 | $formelement->setDecorator($form_array_element['decorator']); |
||
212 | } |
||
213 | } |
||
214 | } |
||
215 | } |
||
216 | |||
217 | // unset the form description array, because we are done with it |
||
218 | unset($form_array); |
||
219 | |||
220 | return $this->render(); |
||
221 | } |
||
222 | |||
236 |
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.