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