| Conditions | 1 |
| Paths | 1 |
| Total Lines | 118 |
| Code Lines | 88 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 174 | public function dataConsoleStore() |
||
| 175 | { |
||
| 176 | $testException = new Exception('testing'); |
||
| 177 | $display = new Display(); |
||
| 178 | $reflectedTime = $this->getAccessibleMethod($display, 'getReadableTime'); |
||
| 179 | $reflectedMemory = $this->getAccessibleMethod($display, 'getReadableMemory'); |
||
| 180 | |||
| 181 | return array( |
||
| 182 | array( |
||
| 183 | 'store' => array( |
||
| 184 | array( |
||
| 185 | 'data' => 'testing message', |
||
| 186 | 'type' => 'log' |
||
| 187 | ), |
||
| 188 | array( |
||
| 189 | 'name' => 'now', |
||
| 190 | 'data' => microtime(true), |
||
| 191 | 'type' => 'speed' |
||
| 192 | ), |
||
| 193 | array( |
||
| 194 | 'name' => 'little later', |
||
| 195 | 'data' => microtime(true) + 1, |
||
| 196 | 'type' => 'speed' |
||
| 197 | ), |
||
| 198 | array( |
||
| 199 | 'name' => 'invalid key', |
||
| 200 | 'type' => 'foo' |
||
| 201 | ) |
||
| 202 | ), |
||
| 203 | 'meta' => array( |
||
| 204 | 'log' => 1, |
||
| 205 | 'memory' => 0, |
||
| 206 | 'error' => 1, |
||
| 207 | 'speed' => 2 |
||
| 208 | ), |
||
| 209 | 'messages' => array( |
||
| 210 | array( |
||
| 211 | 'message' => 'testing message', |
||
| 212 | 'type' => 'log' |
||
| 213 | ), |
||
| 214 | array( |
||
| 215 | 'message' => 'now', |
||
| 216 | 'data' => $reflectedTime->invokeArgs($display, array(microtime(true))), |
||
| 217 | 'type' => 'speed' |
||
| 218 | ), |
||
| 219 | array( |
||
| 220 | 'message' => 'little later', |
||
| 221 | 'data' => $reflectedTime->invokeArgs($display, array(microtime(true) + 1)), |
||
| 222 | 'type' => 'speed' |
||
| 223 | ), |
||
| 224 | array( |
||
| 225 | 'message' => 'Unrecognized console log type: foo', |
||
| 226 | 'type' => 'error' |
||
| 227 | ) |
||
| 228 | ) |
||
| 229 | ), |
||
| 230 | array( |
||
| 231 | 'store' => array( |
||
| 232 | array( |
||
| 233 | 'data' => 'another testing message', |
||
| 234 | 'type' => 'log' |
||
| 235 | ), |
||
| 236 | array( |
||
| 237 | 'name' => 'test array', |
||
| 238 | 'data' => strlen(serialize(array('key' => 'value'))), |
||
| 239 | 'data_type' => 'array', |
||
| 240 | 'type' => 'memory' |
||
| 241 | ), |
||
| 242 | array( |
||
| 243 | 'name' => 'memory usage test', |
||
| 244 | 'data' => memory_get_usage(), |
||
| 245 | 'data_type' => '', |
||
| 246 | 'type' => 'memory' |
||
| 247 | ), |
||
| 248 | array( |
||
| 249 | 'data' => $testException->getMessage(), |
||
| 250 | 'file' => $testException->getFile(), |
||
| 251 | 'line' => $testException->getLine(), |
||
| 252 | 'type' => 'error' |
||
| 253 | ) |
||
| 254 | ), |
||
| 255 | 'meta' => array( |
||
| 256 | 'log' => 1, |
||
| 257 | 'memory' => 2, |
||
| 258 | 'error' => 1, |
||
| 259 | 'speed' => 0 |
||
| 260 | ), |
||
| 261 | 'messages' => array( |
||
| 262 | array( |
||
| 263 | 'message' => 'another testing message', |
||
| 264 | 'type' => 'log' |
||
| 265 | ), |
||
| 266 | array( |
||
| 267 | 'message' => 'array: test array', |
||
| 268 | 'data' => $reflectedMemory->invokeArgs( |
||
| 269 | $display, |
||
| 270 | array(strlen(serialize(array('key' => 'value')))) |
||
| 271 | ), |
||
| 272 | 'type' => 'memory' |
||
| 273 | ), |
||
| 274 | array( |
||
| 275 | 'message' => 'memory usage test', |
||
| 276 | 'data' => $reflectedMemory->invokeArgs($display, array(memory_get_usage())), |
||
| 277 | 'type' => 'memory' |
||
| 278 | ), |
||
| 279 | array( |
||
| 280 | 'message' => sprintf( |
||
| 281 | 'Line %s: %s in %s', |
||
| 282 | $testException->getLine(), |
||
| 283 | $testException->getMessage(), |
||
| 284 | $testException->getFile() |
||
| 285 | ), |
||
| 286 | 'type' => 'error' |
||
| 287 | ) |
||
| 288 | ) |
||
| 289 | ) |
||
| 290 | ); |
||
| 291 | } |
||
| 292 | |||
| 309 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.