| Conditions | 1 |
| Paths | 1 |
| Total Lines | 108 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 204 | public function upsert(ConnectionPDOInterface $db): array |
||
| 205 | { |
||
| 206 | return [ |
||
| 207 | 'regular values' => [ |
||
| 208 | ['params' => ['T_upsert', ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3]]], |
||
| 209 | ['params' => ['T_upsert', ['email' => '[email protected]', 'address' => 'Universe', 'status' => 1]]], |
||
| 210 | ], |
||
| 211 | 'regular values with update part' => [ |
||
| 212 | ['params' => [ |
||
| 213 | 'T_upsert', |
||
| 214 | ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3], |
||
| 215 | ['address' => 'Moon', 'status' => 2], |
||
| 216 | ], |
||
| 217 | ], |
||
| 218 | [ |
||
| 219 | 'params' => [ |
||
| 220 | 'T_upsert', |
||
| 221 | ['email' => '[email protected]', 'address' => 'Universe', 'status' => 1], |
||
| 222 | ['address' => 'Moon', 'status' => 2], |
||
| 223 | ], |
||
| 224 | 'expected' => ['email' => '[email protected]', 'address' => 'Moon', 'status' => 2], |
||
| 225 | ], |
||
| 226 | ], |
||
| 227 | 'regular values without update part' => [ |
||
| 228 | ['params' => ['T_upsert', ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3], false]], |
||
| 229 | [ |
||
| 230 | 'params' => [ |
||
| 231 | 'T_upsert', |
||
| 232 | ['email' => '[email protected]', 'address' => 'Universe', 'status' => 1], |
||
| 233 | false, |
||
| 234 | ], |
||
| 235 | 'expected' => ['email' => '[email protected]', 'address' => 'Earth', 'status' => 3], |
||
| 236 | ], |
||
| 237 | ], |
||
| 238 | 'query' => [ |
||
| 239 | [ |
||
| 240 | 'params' => [ |
||
| 241 | 'T_upsert', |
||
| 242 | (new query($db)) |
||
| 243 | ->select(['email', 'address', 'status' => new Expression('1')]) |
||
| 244 | ->from('customer') |
||
| 245 | ->where(['name' => 'user1']) |
||
| 246 | ->limit(1), |
||
| 247 | ], |
||
| 248 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], |
||
| 249 | ], |
||
| 250 | [ |
||
| 251 | 'params' => [ |
||
| 252 | 'T_upsert', |
||
| 253 | (new query($db)) |
||
| 254 | ->select(['email', 'address', 'status' => new Expression('2')]) |
||
| 255 | ->from('customer') |
||
| 256 | ->where(['name' => 'user1']) |
||
| 257 | ->limit(1), |
||
| 258 | ], |
||
| 259 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 2], |
||
| 260 | ], |
||
| 261 | ], |
||
| 262 | 'query with update part' => [ |
||
| 263 | [ |
||
| 264 | 'params' => [ |
||
| 265 | 'T_upsert', |
||
| 266 | (new query($db)) |
||
| 267 | ->select(['email', 'address', 'status' => new Expression('1')]) |
||
| 268 | ->from('customer') |
||
| 269 | ->where(['name' => 'user1']) |
||
| 270 | ->limit(1), |
||
| 271 | ['address' => 'Moon', 'status' => 2], |
||
| 272 | ], |
||
| 273 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], |
||
| 274 | ], |
||
| 275 | [ |
||
| 276 | 'params' => [ |
||
| 277 | 'T_upsert', |
||
| 278 | (new query($db)) |
||
| 279 | ->select(['email', 'address', 'status' => new Expression('3')]) |
||
| 280 | ->from('customer') |
||
| 281 | ->where(['name' => 'user1']) |
||
| 282 | ->limit(1), |
||
| 283 | ['address' => 'Moon', 'status' => 2], |
||
| 284 | ], |
||
| 285 | 'expected' => ['email' => '[email protected]', 'address' => 'Moon', 'status' => 2], |
||
| 286 | ], |
||
| 287 | ], |
||
| 288 | 'query without update part' => [ |
||
| 289 | [ |
||
| 290 | 'params' => [ |
||
| 291 | 'T_upsert', |
||
| 292 | (new query($db)) |
||
| 293 | ->select(['email', 'address', 'status' => new Expression('1')]) |
||
| 294 | ->from('customer') |
||
| 295 | ->where(['name' => 'user1']) |
||
| 296 | ->limit(1), |
||
| 297 | false, |
||
| 298 | ], |
||
| 299 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], |
||
| 300 | ], |
||
| 301 | [ |
||
| 302 | 'params' => [ |
||
| 303 | 'T_upsert', |
||
| 304 | (new query($db)) |
||
| 305 | ->select(['email', 'address', 'status' => new Expression('2')]) |
||
| 306 | ->from('customer') |
||
| 307 | ->where(['name' => 'user1']) |
||
| 308 | ->limit(1), |
||
| 309 | false, |
||
| 310 | ], |
||
| 311 | 'expected' => ['email' => '[email protected]', 'address' => 'address1', 'status' => 1], |
||
| 312 | ], |
||
| 317 |