Conditions | 1 |
Paths | 1 |
Total Lines | 73 |
Code Lines | 47 |
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 |
||
25 | private function getCommonArgLists() { |
||
26 | $argLists = array(); |
||
27 | |||
28 | $old = array(); |
||
29 | $new = array(); |
||
30 | $expected = array(); |
||
31 | |||
32 | $argLists[] = array( $old, $new, $expected, |
||
33 | 'There should be no difference between empty arrays' ); |
||
34 | |||
35 | |||
36 | $old = array( 42 ); |
||
37 | $new = array( 42 ); |
||
38 | $expected = array(); |
||
39 | |||
40 | $argLists[] = array( $old, $new, $expected, |
||
41 | 'There should be no difference between arrays with the same element' ); |
||
42 | |||
43 | |||
44 | $old = array( 42, 'ohi', 4.2, false ); |
||
45 | $new = array( 42, 'ohi', 4.2, false ); |
||
46 | $expected = array(); |
||
47 | |||
48 | $argLists[] = array( $old, $new, $expected, |
||
49 | 'There should be no difference between arrays with the same elements' ); |
||
50 | |||
51 | |||
52 | $old = array( 42, 'ohi', 4.2, false ); |
||
53 | $new = array( false, 4.2, 'ohi', 42 ); |
||
54 | $expected = array(); |
||
55 | |||
56 | $argLists[] = array( $old, $new, $expected, |
||
57 | 'There should be no difference between arrays with the same elements even when not ordered the same' ); |
||
58 | |||
59 | |||
60 | $old = array(); |
||
61 | $new = array( 42 ); |
||
62 | $expected = array( new DiffOpAdd( 42 ) ); |
||
63 | |||
64 | $argLists[] = array( $old, $new, $expected, |
||
65 | 'An array with a single element should be an add operation different from an empty array' ); |
||
66 | |||
67 | |||
68 | $old = array( 42 ); |
||
69 | $new = array(); |
||
70 | $expected = array( new DiffOpRemove( 42 ) ); |
||
71 | |||
72 | $argLists[] = array( $old, $new, $expected, |
||
73 | 'An empty array should be a remove operation different from an array with one element' ); |
||
74 | |||
75 | |||
76 | $old = array( 1 ); |
||
77 | $new = array( 2 ); |
||
78 | $expected = array( new DiffOpRemove( 1 ), new DiffOpAdd( 2 ) ); |
||
79 | |||
80 | $argLists[] = array( $old, $new, $expected, |
||
81 | 'Two arrays with a single different element should differ by an add and a remove op' ); |
||
82 | |||
83 | |||
84 | $old = array( 9001, 42, 1, 0 ); |
||
85 | $new = array( 9001, 2, 0, 42 ); |
||
86 | $expected = array( new DiffOpRemove( 1 ), new DiffOpAdd( 2 ) ); |
||
87 | |||
88 | $argLists[] = array( |
||
89 | $old, |
||
90 | $new, |
||
91 | $expected, |
||
92 | 'Two arrays with a single different element should differ by an add ' |
||
93 | . 'and a remove op even when they share identical elements' |
||
94 | ); |
||
95 | |||
96 | return $argLists; |
||
97 | } |
||
98 | |||
231 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.