| Conditions | 1 |
| Paths | 1 |
| Total Lines | 131 |
| Code Lines | 93 |
| Lines | 0 |
| Ratio | 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 |
||
| 102 | public function testRequestVars() { |
||
| 103 | $getVars = array( |
||
| 104 | 'first' => 'a', |
||
| 105 | 'second' => 'b', |
||
| 106 | ); |
||
| 107 | $postVars = array( |
||
| 108 | 'third' => 'c', |
||
| 109 | 'fourth' => 'd', |
||
| 110 | ); |
||
| 111 | $requestVars = array( |
||
| 112 | 'first' => 'a', |
||
| 113 | 'second' => 'b', |
||
| 114 | 'third' => 'c', |
||
| 115 | 'fourth' => 'd', |
||
| 116 | ); |
||
| 117 | $request = new SS_HTTPRequest( |
||
| 118 | 'POST', |
||
| 119 | 'admin/crm', |
||
| 120 | $getVars, |
||
| 121 | $postVars |
||
| 122 | ); |
||
| 123 | $this->assertEquals( |
||
| 124 | $requestVars, |
||
| 125 | $request->requestVars(), |
||
| 126 | 'GET parameters should supplement POST parameters' |
||
| 127 | ); |
||
| 128 | |||
| 129 | $getVars = array( |
||
| 130 | 'first' => 'a', |
||
| 131 | 'second' => 'b', |
||
| 132 | ); |
||
| 133 | $postVars = array( |
||
| 134 | 'first' => 'c', |
||
| 135 | 'third' => 'd', |
||
| 136 | ); |
||
| 137 | $requestVars = array( |
||
| 138 | 'first' => 'c', |
||
| 139 | 'second' => 'b', |
||
| 140 | 'third' => 'd', |
||
| 141 | ); |
||
| 142 | $request = new SS_HTTPRequest( |
||
| 143 | 'POST', |
||
| 144 | 'admin/crm', |
||
| 145 | $getVars, |
||
| 146 | $postVars |
||
| 147 | ); |
||
| 148 | $this->assertEquals( |
||
| 149 | $requestVars, |
||
| 150 | $request->requestVars(), |
||
| 151 | 'POST parameters should override GET parameters' |
||
| 152 | ); |
||
| 153 | |||
| 154 | $getVars = array( |
||
| 155 | 'first' => array( |
||
| 156 | 'first' => 'a', |
||
| 157 | ), |
||
| 158 | 'second' => array( |
||
| 159 | 'second' => 'b', |
||
| 160 | ), |
||
| 161 | ); |
||
| 162 | $postVars = array( |
||
| 163 | 'first' => array( |
||
| 164 | 'first' => 'c', |
||
| 165 | ), |
||
| 166 | 'third' => array( |
||
| 167 | 'third' => 'd', |
||
| 168 | ), |
||
| 169 | ); |
||
| 170 | $requestVars = array( |
||
| 171 | 'first' => array( |
||
| 172 | 'first' => 'c', |
||
| 173 | ), |
||
| 174 | 'second' => array( |
||
| 175 | 'second' => 'b', |
||
| 176 | ), |
||
| 177 | 'third' => array( |
||
| 178 | 'third' => 'd', |
||
| 179 | ), |
||
| 180 | ); |
||
| 181 | $request = new SS_HTTPRequest( |
||
| 182 | 'POST', |
||
| 183 | 'admin/crm', |
||
| 184 | $getVars, |
||
| 185 | $postVars |
||
| 186 | ); |
||
| 187 | $this->assertEquals( |
||
| 188 | $requestVars, |
||
| 189 | $request->requestVars(), |
||
| 190 | 'Nested POST parameters should override GET parameters' |
||
| 191 | ); |
||
| 192 | |||
| 193 | $getVars = array( |
||
| 194 | 'first' => array( |
||
| 195 | 'first' => 'a', |
||
| 196 | ), |
||
| 197 | 'second' => array( |
||
| 198 | 'second' => 'b', |
||
| 199 | ), |
||
| 200 | ); |
||
| 201 | $postVars = array( |
||
| 202 | 'first' => array( |
||
| 203 | 'second' => 'c', |
||
| 204 | ), |
||
| 205 | 'third' => array( |
||
| 206 | 'third' => 'd', |
||
| 207 | ), |
||
| 208 | ); |
||
| 209 | $requestVars = array( |
||
| 210 | 'first' => array( |
||
| 211 | 'first' => 'a', |
||
| 212 | 'second' => 'c', |
||
| 213 | ), |
||
| 214 | 'second' => array( |
||
| 215 | 'second' => 'b', |
||
| 216 | ), |
||
| 217 | 'third' => array( |
||
| 218 | 'third' => 'd', |
||
| 219 | ), |
||
| 220 | ); |
||
| 221 | $request = new SS_HTTPRequest( |
||
| 222 | 'POST', |
||
| 223 | 'admin/crm', |
||
| 224 | $getVars, |
||
| 225 | $postVars |
||
| 226 | ); |
||
| 227 | $this->assertEquals( |
||
| 228 | $requestVars, |
||
| 229 | $request->requestVars(), |
||
| 230 | 'Nested GET parameters should supplement POST parameters' |
||
| 231 | ); |
||
| 232 | } |
||
| 233 | |||
| 277 |