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