| Conditions | 1 |
| Paths | 1 |
| Total Lines | 125 |
| Code Lines | 90 |
| 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 |
||
| 31 | private function getCommonArgLists() { |
||
| 32 | $argLists = array(); |
||
| 33 | |||
| 34 | $old = array(); |
||
| 35 | $new = array(); |
||
| 36 | $expected = array(); |
||
| 37 | |||
| 38 | $argLists[] = array( $old, $new, $expected, |
||
| 39 | 'There should be no difference between empty arrays' ); |
||
| 40 | |||
| 41 | $old = array( 42 ); |
||
| 42 | $new = array( 42 ); |
||
| 43 | $expected = array(); |
||
| 44 | |||
| 45 | $argLists[] = array( $old, $new, $expected, |
||
| 46 | 'There should be no difference between arrays with the same element' ); |
||
| 47 | |||
| 48 | $old = array( 42, 'ohi', 4.2, false ); |
||
| 49 | $new = array( 42, 'ohi', 4.2, false ); |
||
| 50 | $expected = array(); |
||
| 51 | |||
| 52 | $argLists[] = array( $old, $new, $expected, |
||
| 53 | 'There should be no difference between arrays with the same elements' ); |
||
| 54 | |||
| 55 | $old = array( 42, 'ohi', 4.2, false ); |
||
| 56 | $new = array( false, 4.2, 'ohi', 42 ); |
||
| 57 | $expected = array( |
||
| 58 | new DiffOpAdd( false ), |
||
| 59 | new DiffOpAdd( 4.2 ), |
||
| 60 | new DiffOpAdd( 'ohi' ), |
||
| 61 | new DiffOpAdd( 42 ), |
||
| 62 | new DiffOpRemove( 42 ), |
||
| 63 | new DiffOpRemove( 'ohi' ), |
||
| 64 | new DiffOpRemove( 4.2 ), |
||
| 65 | new DiffOpRemove( false ) |
||
| 66 | ); |
||
| 67 | |||
| 68 | $argLists[] = array( $old, $new, $expected, |
||
| 69 | 'Changing the order of all four elements should result in four add operations and four remove operations' ); |
||
| 70 | |||
| 71 | $old = array( 42, 'ohi', 4.2, false ); |
||
| 72 | $new = array( 4.2, 'ohi', 42, false ); |
||
| 73 | $expected = array( |
||
| 74 | new DiffOpAdd( 4.2 ), |
||
| 75 | new DiffOpAdd( 42 ), |
||
| 76 | new DiffOpRemove( 42 ), |
||
| 77 | new DiffOpRemove( 4.2 ), |
||
| 78 | ); |
||
| 79 | |||
| 80 | $argLists[] = array( $old, $new, $expected, |
||
| 81 | 'Changing the order of two of four elements should result in two add operations and two remove operations' ); |
||
| 82 | |||
| 83 | $old = array(); |
||
| 84 | $new = array( 42 ); |
||
| 85 | $expected = array( new DiffOpAdd( 42 ) ); |
||
| 86 | |||
| 87 | $argLists[] = array( $old, $new, $expected, |
||
| 88 | 'An array with a single element should be an add operation different from an empty array' ); |
||
| 89 | |||
| 90 | $old = array( 42 ); |
||
| 91 | $new = array(); |
||
| 92 | $expected = array( new DiffOpRemove( 42 ) ); |
||
| 93 | |||
| 94 | $argLists[] = array( $old, $new, $expected, |
||
| 95 | 'An empty array should be a remove operation different from an array with one element' ); |
||
| 96 | |||
| 97 | $old = array( 1 ); |
||
| 98 | $new = array( 2 ); |
||
| 99 | $expected = array( new DiffOpRemove( 1 ), new DiffOpAdd( 2 ) ); |
||
| 100 | |||
| 101 | $argLists[] = array( $old, $new, $expected, |
||
| 102 | 'Two arrays with a single different element should differ by an add and a remove op' ); |
||
| 103 | |||
| 104 | $old = array( 9001, 42, 1, 0 ); |
||
| 105 | $new = array( 9001, 42, 2, 0 ); |
||
| 106 | $expected = array( new DiffOpRemove( 1 ), new DiffOpAdd( 2 ) ); |
||
| 107 | |||
| 108 | $argLists[] = array( $old, $new, $expected, |
||
| 109 | 'Two arrays with a single different element should differ by an add and a remove op |
||
| 110 | when the order of the identical elements stays the same' ); |
||
| 111 | |||
| 112 | $old = array( 'a', 'b', 'c' ); |
||
| 113 | $new = array( 'c', 'b', 'a', 'd' ); |
||
| 114 | $expected = array( |
||
| 115 | new DiffOpRemove( 'a' ), |
||
| 116 | new DiffOpRemove( 'c' ), |
||
| 117 | new DiffOpAdd( 'c' ), |
||
| 118 | new DiffOpAdd( 'a' ), |
||
| 119 | new DiffOpAdd( 'd' ) |
||
| 120 | ); |
||
| 121 | |||
| 122 | $argLists[] = array( $old, $new, $expected, |
||
| 123 | 'Changing the position of two elements and adding one new element should result |
||
| 124 | in two remove ops and three add ops' ); |
||
| 125 | |||
| 126 | $old = array( 'a', 'b', 'c', 'd' ); |
||
| 127 | $new = array( 'b', 'a', 'c' ); |
||
| 128 | $expected = array( |
||
| 129 | new DiffOpRemove( 'a' ), |
||
| 130 | new DiffOpRemove( 'b' ), |
||
| 131 | new DiffOpRemove( 'd' ), |
||
| 132 | new DiffOpAdd( 'b' ), |
||
| 133 | new DiffOpAdd( 'a' ) |
||
| 134 | ); |
||
| 135 | |||
| 136 | $argLists[] = array( $old, $new, $expected, |
||
| 137 | 'Changing the position of two elements and removing the last element should result |
||
| 138 | in three remove ops and two add ops' ); |
||
| 139 | |||
| 140 | $old = array( 'a', 'b', 'c' ); |
||
| 141 | $new = array( 'b', 'c' ); |
||
| 142 | $expected = array( |
||
| 143 | new DiffOpRemove( 'a' ), |
||
| 144 | new DiffOpRemove( 'b' ), |
||
| 145 | new DiffOpRemove( 'c' ), |
||
| 146 | new DiffOpAdd( 'b' ), |
||
| 147 | new DiffOpAdd( 'c' ) |
||
| 148 | ); |
||
| 149 | |||
| 150 | $argLists[] = array( $old, $new, $expected, |
||
| 151 | 'Removing the first element results in remove ops for all elements and add ops for the remaining elements, |
||
| 152 | because the position of all remaining elements has changed' ); |
||
| 153 | |||
| 154 | return $argLists; |
||
| 155 | } |
||
| 156 | |||
| 291 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.