Conditions | 1 |
Paths | 1 |
Total Lines | 94 |
Code Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
156 | public function unformattedNumberByPrecisionProvider() { |
||
157 | |||
158 | $provider['un.1'] = array( |
||
159 | 10000, |
||
160 | 1000, |
||
161 | 2, |
||
162 | 'en', |
||
163 | 'en', |
||
164 | '1000.00' |
||
165 | ); |
||
166 | |||
167 | $provider['un.2'] = array( |
||
168 | 10000, |
||
169 | 1000.42, |
||
170 | 3, |
||
171 | 'en', |
||
172 | 'en', |
||
173 | '1000.420' |
||
174 | ); |
||
175 | |||
176 | $provider['un.3'] = array( |
||
177 | 10000, |
||
178 | 1000000, |
||
179 | 0, |
||
180 | 'en', |
||
181 | 'en', |
||
182 | '1000000' |
||
183 | ); |
||
184 | |||
185 | $provider['un.4'] = array( |
||
186 | 10000000, |
||
187 | 1000000, |
||
188 | 2, |
||
189 | 'en', |
||
190 | 'en', |
||
191 | '1000000.00' |
||
192 | ); |
||
193 | |||
194 | $provider['un.5'] = array( |
||
195 | 10000000, |
||
196 | 1000000, |
||
197 | false, |
||
198 | 'en', |
||
199 | 'en', |
||
200 | '1000000' |
||
201 | ); |
||
202 | |||
203 | $provider['un.6'] = array( |
||
204 | 10000000, |
||
205 | 312.23545555, |
||
206 | false, |
||
207 | 'en', |
||
208 | 'en', |
||
209 | '312.23545555' |
||
210 | ); |
||
211 | |||
212 | $provider['un.7'] = array( |
||
213 | 10000000, |
||
214 | 312.23545555, |
||
215 | 6, |
||
216 | 'en', |
||
217 | 'en', |
||
218 | '312.235456' |
||
219 | ); |
||
220 | |||
221 | $provider['un.8'] = array( |
||
222 | 10000000, |
||
223 | 312.23545555, |
||
224 | 9, |
||
225 | 'en', |
||
226 | 'en', |
||
227 | '312.235455550' |
||
228 | ); |
||
229 | |||
230 | $provider['un.9'] = array( |
||
231 | 10000000, |
||
232 | 1.334e-13, |
||
233 | false, |
||
234 | 'en', |
||
235 | 'en', |
||
236 | '1.334e-13' |
||
237 | ); |
||
238 | |||
239 | $provider['un.10'] = array( |
||
240 | 10000000, |
||
241 | 1.334e-13, |
||
242 | false, |
||
243 | 'en', |
||
244 | 'fr', |
||
245 | '1,334e-13' |
||
246 | ); |
||
247 | |||
248 | return $provider; |
||
249 | } |
||
250 | |||
321 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.