Conditions | 1 |
Paths | 1 |
Total Lines | 59 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
35 | public function valueProvider() { |
||
36 | |||
37 | $provider[] = array( |
||
|
|||
38 | '2/1352/01/01', |
||
39 | '2214875.500000' |
||
40 | ); |
||
41 | |||
42 | $provider[] = array( |
||
43 | '1/2100/10/04', |
||
44 | '2488345.500000' |
||
45 | ); |
||
46 | |||
47 | $provider[] = array( |
||
48 | '1/2100/10/04', |
||
49 | '2488345.500000' |
||
50 | ); |
||
51 | |||
52 | $provider[] = array( |
||
53 | '2/1582/10/04', |
||
54 | '2299159.500000' |
||
55 | ); |
||
56 | |||
57 | $provider[] = array( |
||
58 | '1/1582/10/15', |
||
59 | '2299160.5' |
||
60 | ); |
||
61 | |||
62 | $provider[] = array( |
||
63 | '2/-900/10/4', |
||
64 | '1392974.500000' |
||
65 | ); |
||
66 | |||
67 | $provider[] = array( |
||
68 | '2/-4713/01/02', |
||
69 | '0.5' |
||
70 | ); |
||
71 | |||
72 | $provider[] = array( |
||
73 | '2/-4713/01/02/12/0/0', |
||
74 | '1' |
||
75 | ); |
||
76 | |||
77 | $provider[] = array( |
||
78 | '2/-9000/10/4', |
||
79 | '-1565550.5' |
||
80 | ); |
||
81 | |||
82 | $provider[] = array( |
||
83 | '1/2100/10/4/13/55/55', |
||
84 | '2488346.0804977' |
||
85 | ); |
||
86 | |||
87 | $provider[] = array( |
||
88 | '1/2100/10/4/13/55/55', |
||
89 | 2488346.0804977 |
||
90 | ); |
||
91 | |||
92 | return $provider; |
||
93 | } |
||
94 | |||
96 |
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.