Conditions | 10 |
Paths | 10 |
Total Lines | 32 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | 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 |
||
34 | public function detectClass($len) |
||
35 | { |
||
36 | if($len == 1) |
||
37 | return "A"; |
||
38 | |||
39 | |||
40 | if($len == 2) |
||
41 | return "B"; |
||
42 | |||
43 | |||
44 | if($len == 3) |
||
45 | return "C"; |
||
46 | |||
47 | |||
48 | if($len == 4) |
||
49 | return "D"; |
||
50 | |||
51 | |||
52 | if($len == 5) |
||
53 | return "E"; |
||
54 | |||
55 | if($len == 6) |
||
56 | return "F"; |
||
57 | |||
58 | if($len == 7) |
||
59 | return "G"; |
||
60 | |||
61 | if($len == 8) |
||
62 | return "H"; |
||
63 | |||
64 | if($len == 9) |
||
65 | return "I"; |
||
66 | |||
69 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: