| Conditions | 1 |
| Paths | 1 |
| Total Lines | 206 |
| Code Lines | 100 |
| 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 |
||
| 273 | public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) |
||
| 274 | { |
||
| 275 | $metadata->setPrimaryTable( |
||
| 276 | [ |
||
| 277 | 'name' => 'cms_users_customid', |
||
| 278 | ] |
||
| 279 | ); |
||
| 280 | |||
| 281 | $metadata->addNamedNativeQuery( |
||
| 282 | [ |
||
| 283 | 'name' => 'fetchIdAndUsernameWithResultClass', |
||
| 284 | 'query' => 'SELECT id, username FROM cms_users_customid WHERE username = ?', |
||
| 285 | 'resultClass' => CmsUser::class, |
||
| 286 | ] |
||
| 287 | ); |
||
| 288 | |||
| 289 | $metadata->addNamedNativeQuery( |
||
| 290 | [ |
||
| 291 | 'name' => 'fetchAllColumns', |
||
| 292 | 'query' => 'SELECT * FROM cms_users_customid WHERE username = ?', |
||
| 293 | 'resultClass' => CmsUser::class, |
||
| 294 | ] |
||
| 295 | ); |
||
| 296 | |||
| 297 | $metadata->addNamedNativeQuery( |
||
| 298 | [ |
||
| 299 | 'name' => 'fetchJoinedAddress', |
||
| 300 | 'query' => 'SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users_customid u INNER JOIN cms_addresses_customid a ON u.id = a.user_id WHERE u.username = ?', |
||
| 301 | 'resultSetMapping' => 'mappingJoinedAddress', |
||
| 302 | ] |
||
| 303 | ); |
||
| 304 | |||
| 305 | $metadata->addNamedNativeQuery( |
||
| 306 | [ |
||
| 307 | 'name' => 'fetchJoinedPhonenumber', |
||
| 308 | 'query' => 'SELECT id, name, status, phonenumber AS number FROM cms_users_customid INNER JOIN cms_phonenumbers_customid ON id = user_id WHERE username = ?', |
||
| 309 | 'resultSetMapping' => 'mappingJoinedPhonenumber', |
||
| 310 | ] |
||
| 311 | ); |
||
| 312 | |||
| 313 | $metadata->addNamedNativeQuery( |
||
| 314 | [ |
||
| 315 | 'name' => 'fetchUserPhonenumberCount', |
||
| 316 | 'query' => 'SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users_customid INNER JOIN cms_phonenumbers_customid ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username', |
||
| 317 | 'resultSetMapping' => 'mappingUserPhonenumberCount', |
||
| 318 | ] |
||
| 319 | ); |
||
| 320 | |||
| 321 | $metadata->addNamedNativeQuery( |
||
| 322 | [ |
||
| 323 | "name" => "fetchMultipleJoinsEntityResults", |
||
| 324 | "resultSetMapping" => "mappingMultipleJoinsEntityResults", |
||
| 325 | "query" => "SELECT u.id AS u_id, u.name AS u_name, u.status AS u_status, a.id AS a_id, a.zip AS a_zip, a.country AS a_country, COUNT(p.phonenumber) AS numphones FROM cms_users_customid u INNER JOIN cms_addresses_customid a ON u.id = a.user_id INNER JOIN cms_phonenumbers_customid p ON u.id = p.user_id GROUP BY u.id, u.name, u.status, u.username, a.id, a.zip, a.country ORDER BY u.username" |
||
| 326 | ] |
||
| 327 | ); |
||
| 328 | |||
| 329 | $metadata->addSqlResultSetMapping( |
||
| 330 | [ |
||
| 331 | 'name' => 'mappingJoinedAddress', |
||
| 332 | 'columns' => [], |
||
| 333 | 'entities' => [ |
||
| 334 | [ |
||
| 335 | 'fields'=> [ |
||
| 336 | [ |
||
| 337 | 'name' => 'id', |
||
| 338 | 'column' => 'id', |
||
| 339 | ], |
||
| 340 | [ |
||
| 341 | 'name' => 'name', |
||
| 342 | 'column' => 'name', |
||
| 343 | ], |
||
| 344 | [ |
||
| 345 | 'name' => 'status', |
||
| 346 | 'column' => 'status', |
||
| 347 | ], |
||
| 348 | [ |
||
| 349 | 'name' => 'address.zip', |
||
| 350 | 'column' => 'zip', |
||
| 351 | ], |
||
| 352 | [ |
||
| 353 | 'name' => 'address.city', |
||
| 354 | 'column' => 'city', |
||
| 355 | ], |
||
| 356 | [ |
||
| 357 | 'name' => 'address.country', |
||
| 358 | 'column' => 'country', |
||
| 359 | ], |
||
| 360 | [ |
||
| 361 | 'name' => 'address.id', |
||
| 362 | 'column' => 'a_id', |
||
| 363 | ], |
||
| 364 | ], |
||
| 365 | 'entityClass' => CmsUser::class, |
||
| 366 | 'discriminatorColumn' => null |
||
| 367 | ], |
||
| 368 | ], |
||
| 369 | ] |
||
| 370 | ); |
||
| 371 | |||
| 372 | $metadata->addSqlResultSetMapping( |
||
| 373 | [ |
||
| 374 | 'name' => 'mappingJoinedPhonenumber', |
||
| 375 | 'columns' => [], |
||
| 376 | 'entities' => [ |
||
| 377 | [ |
||
| 378 | 'fields'=> [ |
||
| 379 | [ |
||
| 380 | 'name' => 'id', |
||
| 381 | 'column' => 'id', |
||
| 382 | ], |
||
| 383 | [ |
||
| 384 | 'name' => 'name', |
||
| 385 | 'column' => 'name', |
||
| 386 | ], |
||
| 387 | [ |
||
| 388 | 'name' => 'status', |
||
| 389 | 'column' => 'status', |
||
| 390 | ], |
||
| 391 | [ |
||
| 392 | 'name' => 'phonenumbers.phonenumber', |
||
| 393 | 'column' => 'number', |
||
| 394 | ], |
||
| 395 | ], |
||
| 396 | 'entityClass' => CmsUser::class, |
||
| 397 | 'discriminatorColumn' => null |
||
| 398 | ], |
||
| 399 | ], |
||
| 400 | ] |
||
| 401 | ); |
||
| 402 | |||
| 403 | $metadata->addSqlResultSetMapping( |
||
| 404 | [ |
||
| 405 | 'name' => 'mappingUserPhonenumberCount', |
||
| 406 | 'columns' => [], |
||
| 407 | 'entities' => [ |
||
| 408 | [ |
||
| 409 | 'fields' => [ |
||
| 410 | [ |
||
| 411 | 'name' => 'id', |
||
| 412 | 'column' => 'id', |
||
| 413 | ], |
||
| 414 | [ |
||
| 415 | 'name' => 'name', |
||
| 416 | 'column' => 'name', |
||
| 417 | ], |
||
| 418 | [ |
||
| 419 | 'name' => 'status', |
||
| 420 | 'column' => 'status', |
||
| 421 | ] |
||
| 422 | ], |
||
| 423 | 'entityClass' => CmsUser::class, |
||
| 424 | 'discriminatorColumn' => null |
||
| 425 | ] |
||
| 426 | ], |
||
| 427 | 'columns' => [ |
||
| 428 | [ |
||
| 429 | 'name' => 'numphones', |
||
| 430 | ] |
||
| 431 | ] |
||
| 432 | ] |
||
| 433 | ); |
||
| 434 | |||
| 435 | $metadata->addSqlResultSetMapping( |
||
| 436 | [ |
||
| 437 | 'name' => 'mappingMultipleJoinsEntityResults', |
||
| 438 | 'entities' => [ |
||
| 439 | [ |
||
| 440 | 'fields' => [ |
||
| 441 | [ |
||
| 442 | 'name' => 'id', |
||
| 443 | 'column' => 'u_id', |
||
| 444 | ], |
||
| 445 | [ |
||
| 446 | 'name' => 'name', |
||
| 447 | 'column' => 'u_name', |
||
| 448 | ], |
||
| 449 | [ |
||
| 450 | 'name' => 'status', |
||
| 451 | 'column' => 'u_status', |
||
| 452 | ] |
||
| 453 | ], |
||
| 454 | 'entityClass' => CmsUser::class, |
||
| 455 | 'discriminatorColumn' => null, |
||
| 456 | ], |
||
| 457 | [ |
||
| 458 | 'fields' => [ |
||
| 459 | [ |
||
| 460 | 'name' => 'id', |
||
| 461 | 'column' => 'a_id', |
||
| 462 | ], |
||
| 463 | [ |
||
| 464 | 'name' => 'zip', |
||
| 465 | 'column' => 'a_zip', |
||
| 466 | ], |
||
| 467 | [ |
||
| 468 | 'name' => 'country', |
||
| 469 | 'column' => 'a_country', |
||
| 470 | ], |
||
| 471 | ], |
||
| 472 | 'entityClass' => CmsAddress::class, |
||
| 473 | 'discriminatorColumn' => null, |
||
| 474 | ], |
||
| 475 | ], |
||
| 476 | 'columns' => [ |
||
| 477 | [ |
||
| 478 | 'name' => 'numphones', |
||
| 479 | ] |
||
| 486 |