| Conditions | 1 |
| Paths | 1 |
| Total Lines | 187 |
| Code Lines | 131 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 27 | public function patchProvider() { |
||
| 28 | $argLists = array(); |
||
| 29 | |||
| 30 | $patcher = new MapPatcher(); |
||
| 31 | $base = array(); |
||
| 32 | $diff = new Diff(); |
||
| 33 | $expected = array(); |
||
| 34 | |||
| 35 | $argLists['all empty'] = array( $patcher, $base, $diff, $expected ); |
||
| 36 | |||
| 37 | $patcher = new MapPatcher(); |
||
| 38 | $base = array( 'foo', 'bar' => array( 'baz' ) ); |
||
| 39 | $diff = new Diff(); |
||
| 40 | $expected = array( 'foo', 'bar' => array( 'baz' ) ); |
||
| 41 | |||
| 42 | $argLists['empty patch'] = array( $patcher, $base, $diff, $expected ); |
||
| 43 | |||
| 44 | $patcher = new MapPatcher(); |
||
| 45 | $base = array( 'foo', 'bar' => array( 'baz' ) ); |
||
| 46 | $diff = new Diff( array( 'bah' => new DiffOpAdd( 'blah' ) ) ); |
||
| 47 | $expected = array( 'foo', 'bar' => array( 'baz' ), 'bah' => 'blah' ); |
||
| 48 | |||
| 49 | $argLists['add'] = array( $patcher, $base, $diff, $expected ); |
||
| 50 | |||
| 51 | $patcher = new MapPatcher(); |
||
| 52 | $base = array( 'foo', 'bar' => array( 'baz' ) ); |
||
| 53 | $diff = new Diff( array( 'bah' => new DiffOpAdd( 'blah' ) ) ); |
||
| 54 | $expected = array( 'foo', 'bar' => array( 'baz' ), 'bah' => 'blah' ); |
||
| 55 | |||
| 56 | $argLists['add2'] = array( $patcher, $base, $diff, $expected ); //FIXME: dupe? |
||
| 57 | |||
| 58 | $patcher = new MapPatcher(); |
||
| 59 | $base = array(); |
||
| 60 | $diff = new Diff( array( |
||
| 61 | 'foo' => new DiffOpAdd( 'bar' ), |
||
| 62 | 'bah' => new DiffOpAdd( 'blah' ) |
||
| 63 | ) ); |
||
| 64 | $expected = array( |
||
| 65 | 'foo' => 'bar', |
||
| 66 | 'bah' => 'blah' |
||
| 67 | ); |
||
| 68 | |||
| 69 | $argLists['add to empty base'] = array( $patcher, $base, $diff, $expected ); |
||
| 70 | |||
| 71 | $patcher = new MapPatcher(); |
||
| 72 | $base = array( |
||
| 73 | 'enwiki' => array( |
||
| 74 | 'name' => 'Nyan Cat', |
||
| 75 | 'badges' => array( 'FA' ) |
||
| 76 | ) |
||
| 77 | ); |
||
| 78 | $diff = new Diff( array( |
||
| 79 | 'nlwiki' => new Diff( array( |
||
| 80 | 'name' => new DiffOpAdd( 'Nyan Cat' ), |
||
| 81 | 'badges' => new Diff( array( |
||
| 82 | new DiffOpAdd( 'J approves' ), |
||
| 83 | ), false ), |
||
| 84 | ), true ), |
||
| 85 | ), true ); |
||
| 86 | $expected = array( |
||
| 87 | 'enwiki' => array( |
||
| 88 | 'name' => 'Nyan Cat', |
||
| 89 | 'badges' => array( 'FA' ) |
||
| 90 | ), |
||
| 91 | |||
| 92 | 'nlwiki' => array( |
||
| 93 | 'name' => 'Nyan Cat', |
||
| 94 | 'badges' => array( 'J approves' ) |
||
| 95 | ) |
||
| 96 | ); |
||
| 97 | |||
| 98 | $argLists['add to non-existent key'] = array( $patcher, $base, $diff, $expected ); |
||
| 99 | |||
| 100 | $patcher = new MapPatcher(); |
||
| 101 | $base = array( |
||
| 102 | 'foo' => 'bar', |
||
| 103 | 'nyan' => 'cat', |
||
| 104 | 'bah' => 'blah', |
||
| 105 | ); |
||
| 106 | $diff = new Diff( array( |
||
| 107 | 'foo' => new DiffOpRemove( 'bar' ), |
||
| 108 | 'bah' => new DiffOpRemove( 'blah' ), |
||
| 109 | ) ); |
||
| 110 | $expected = array( |
||
| 111 | 'nyan' => 'cat' |
||
| 112 | ); |
||
| 113 | |||
| 114 | $argLists['remove'] = array( $patcher, $base, $diff, $expected ); |
||
| 115 | |||
| 116 | $patcher = new MapPatcher(); |
||
| 117 | $base = array( |
||
| 118 | 'foo' => 'bar', |
||
| 119 | 'nyan' => 'cat', |
||
| 120 | 'spam' => 'blah', |
||
| 121 | 'bah' => 'blah', |
||
| 122 | ); |
||
| 123 | $diff = new Diff( array( |
||
| 124 | 'foo' => new DiffOpChange( 'bar', 'baz' ), |
||
| 125 | 'bah' => new DiffOpRemove( 'blah' ), |
||
| 126 | 'oh' => new DiffOpAdd( 'noez' ), |
||
| 127 | ) ); |
||
| 128 | $expected = array( |
||
| 129 | 'foo' => 'baz', |
||
| 130 | 'nyan' => 'cat', |
||
| 131 | 'spam' => 'blah', |
||
| 132 | 'oh' => 'noez', |
||
| 133 | ); |
||
| 134 | |||
| 135 | $argLists['change/add/remove'] = array( $patcher, $base, $diff, $expected ); |
||
| 136 | |||
| 137 | $patcher = new MapPatcher(); |
||
| 138 | $base = array( |
||
| 139 | 'foo' => 'bar', |
||
| 140 | ); |
||
| 141 | $diff = new Diff( array( |
||
| 142 | 'baz' => new Diff( array( new DiffOpAdd( 'ny' ), new DiffOpAdd( 'an' ) ), false ), |
||
| 143 | ) ); |
||
| 144 | $expected = array( |
||
| 145 | 'foo' => 'bar', |
||
| 146 | 'baz' => array( 'ny', 'an' ), |
||
| 147 | ); |
||
| 148 | |||
| 149 | $argLists['add to substructure'] = array( $patcher, $base, $diff, $expected ); |
||
| 150 | |||
| 151 | // ---- conflicts ---- |
||
| 152 | |||
| 153 | $patcher = new MapPatcher(); |
||
| 154 | $base = array(); |
||
| 155 | $diff = new Diff( array( |
||
| 156 | 'baz' => new DiffOpRemove( 'X' ), |
||
| 157 | ) ); |
||
| 158 | $expected = $base; |
||
| 159 | |||
| 160 | $argLists['conflict: remove missing'] = array( $patcher, $base, $diff, $expected ); |
||
| 161 | |||
| 162 | $patcher = new MapPatcher(); |
||
| 163 | $base = array( 'baz' => 'Y' ); |
||
| 164 | $diff = new Diff( array( |
||
| 165 | 'baz' => new DiffOpRemove( 'X' ), |
||
| 166 | ) ); |
||
| 167 | $expected = $base; |
||
| 168 | |||
| 169 | $argLists['conflict: remove mismatching value'] = array( $patcher, $base, $diff, $expected ); |
||
| 170 | |||
| 171 | $patcher = new MapPatcher(); |
||
| 172 | $base = array( 'baz' => 'Y' ); |
||
| 173 | $diff = new Diff( array( |
||
| 174 | 'baz' => new DiffOpAdd( 'X' ), |
||
| 175 | ) ); |
||
| 176 | $expected = $base; |
||
| 177 | |||
| 178 | $argLists['conflict: add existing'] = array( $patcher, $base, $diff, $expected ); |
||
| 179 | |||
| 180 | $patcher = new MapPatcher(); |
||
| 181 | $base = array( 'baz' => 'Y' ); |
||
| 182 | $diff = new Diff( array( |
||
| 183 | 'baz' => new DiffOpChange( 'X', 'Z' ), |
||
| 184 | ) ); |
||
| 185 | $expected = $base; |
||
| 186 | |||
| 187 | $argLists['conflict: change mismatching value'] = array( $patcher, $base, $diff, $expected ); |
||
| 188 | |||
| 189 | $patcher = new MapPatcher(); |
||
| 190 | $base = array( |
||
| 191 | 'foo' => 'bar', |
||
| 192 | 'nyan' => 'cat', |
||
| 193 | 'spam' => 'blah', |
||
| 194 | 'bah' => 'blah', |
||
| 195 | ); |
||
| 196 | $diff = new Diff( array( |
||
| 197 | 'foo' => new DiffOpChange( 'bar', 'var' ), |
||
| 198 | 'nyan' => new DiffOpRemove( 'fat' ), |
||
| 199 | 'bah' => new DiffOpChange( 'blubb', 'clubb' ), |
||
| 200 | 'yea' => new DiffOpAdd( 'stuff' ), |
||
| 201 | ) ); |
||
| 202 | $expected = array( |
||
| 203 | 'foo' => 'var', |
||
| 204 | 'nyan' => 'cat', |
||
| 205 | 'spam' => 'blah', |
||
| 206 | 'bah' => 'blah', |
||
| 207 | 'yea' => 'stuff', |
||
| 208 | ); |
||
| 209 | |||
| 210 | $argLists['some mixed conflicts'] = array( $patcher, $base, $diff, $expected ); |
||
| 211 | |||
| 212 | return $argLists; |
||
| 213 | } |
||
| 214 | |||
| 445 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.