| Conditions | 45 | 
| Paths | > 20000 | 
| Total Lines | 184 | 
| Code Lines | 123 | 
| Lines | 128 | 
| Ratio | 69.57 % | 
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 | ||
| 262 | public function getQueryBuilderBySearchDataForAdmin($searchData) | ||
| 263 |     { | ||
| 264 |         $qb = $this->createQueryBuilder('o'); | ||
| 265 | |||
| 266 | // order_id_start | ||
| 267 | View Code Duplication |         if (isset($searchData['order_id_start']) && Str::isNotBlank($searchData['order_id_start'])) { | |
| 268 | $qb | ||
| 269 |                 ->andWhere('o.id >= :order_id_start') | ||
| 270 |                 ->setParameter('order_id_start', $searchData['order_id_start']); | ||
| 271 | } | ||
| 272 | // multi | ||
| 273 | View Code Duplication |         if (isset( $searchData['multi']) && Str::isNotBlank($searchData['multi'])) { | |
| 274 |             $multi = preg_match('/^\d+$/', $searchData['multi']) ? $searchData['multi'] : null; | ||
| 275 | $qb | ||
| 276 |                 ->andWhere('o.id = :multi OR o.name01 LIKE :likemulti OR o.name02 LIKE :likemulti OR ' . | ||
| 277 | 'o.kana01 LIKE :likemulti OR o.kana02 LIKE :likemulti OR o.company_name LIKE :likemulti') | ||
| 278 |                 ->setParameter('multi', $multi) | ||
| 279 |                 ->setParameter('likemulti', '%' . $searchData['multi'] . '%'); | ||
| 280 | } | ||
| 281 | |||
| 282 | // order_id_end | ||
| 283 | View Code Duplication |         if (isset($searchData['order_id_end']) && Str::isNotBlank($searchData['order_id_end'])) { | |
| 284 | $qb | ||
| 285 |                 ->andWhere('o.id <= :order_id_end') | ||
| 286 |                 ->setParameter('order_id_end', $searchData['order_id_end']); | ||
| 287 | } | ||
| 288 | |||
| 289 | // status | ||
| 290 |         if (!empty($searchData['status']) && $searchData['status']) { | ||
| 291 | $qb | ||
| 292 |                 ->andWhere('o.OrderStatus = :status') | ||
| 293 |                 ->setParameter('status', $searchData['status']); | ||
| 294 |         } else { | ||
| 295 | // 購入処理中は検索対象から除外 | ||
| 296 |             $qb->andWhere('o.OrderStatus <> :status') | ||
| 297 |                 ->setParameter('status', $this->app['config']['order_processing']); | ||
| 298 | } | ||
| 299 | |||
| 300 | // name | ||
| 301 | View Code Duplication |         if (isset($searchData['name']) && Str::isNotBlank($searchData['name'])) { | |
| 302 | $qb | ||
| 303 |                 ->andWhere('CONCAT(o.name01, o.name02) LIKE :name') | ||
| 304 |                 ->setParameter('name', '%' . $searchData['name'] . '%'); | ||
| 305 | } | ||
| 306 | |||
| 307 | // kana | ||
| 308 | View Code Duplication |         if (isset($searchData['kana']) && Str::isNotBlank($searchData['kana'])) { | |
| 309 | $qb | ||
| 310 |                 ->andWhere('CONCAT(o.kana01, o.kana02) LIKE :kana') | ||
| 311 |                 ->setParameter('kana', '%' . $searchData['kana'] . '%'); | ||
| 312 | } | ||
| 313 | |||
| 314 | |||
| 315 | View Code Duplication |         if (isset($searchData['email']) && Str::isNotBlank($searchData['email'])) { | |
| 316 | $qb | ||
| 317 |                 ->andWhere('o.email like :email') | ||
| 318 |                 ->setParameter('email', '%' . $searchData['email'] . '%'); | ||
| 319 | } | ||
| 320 | |||
| 321 | // tel | ||
| 322 | View Code Duplication |         if (isset($searchData['tel']) && Str::isNotBlank($searchData['tel'])) { | |
| 323 | $qb | ||
| 324 |                 ->andWhere('CONCAT(o.tel01, o.tel02, o.tel03) LIKE :tel') | ||
| 325 |                 ->setParameter('tel', '%' . $searchData['tel'] . '%'); | ||
| 326 | } | ||
| 327 | |||
| 328 | // sex | ||
| 329 |         if (!empty($searchData['sex']) && count($searchData['sex']) > 0) { | ||
| 330 | $qb | ||
| 331 |                 ->andWhere($qb->expr()->in('o.Sex', ':sex')) | ||
| 332 |                 ->setParameter('sex', $searchData['sex']->toArray()); | ||
| 333 | } | ||
| 334 | |||
| 335 | // payment | ||
| 336 | View Code Duplication |         if (!empty($searchData['payment']) && count($searchData['payment'])) { | |
| 337 | $payments = array(); | ||
| 338 |             foreach ($searchData['payment'] as $payment) { | ||
| 339 | $payments[] = $payment->getId(); | ||
| 340 | } | ||
| 341 | $qb | ||
| 342 |                 ->leftJoin('o.Payment', 'p') | ||
| 343 |                 ->andWhere($qb->expr()->in('p.id', ':payments')) | ||
| 344 |                 ->setParameter('payments', $payments); | ||
| 345 | } | ||
| 346 | |||
| 347 | // oreder_date | ||
| 348 | View Code Duplication |         if (!empty($searchData['order_date_start']) && $searchData['order_date_start']) { | |
| 349 | $date = $searchData['order_date_start'] | ||
| 350 |                 ->format('Y-m-d H:i:s'); | ||
| 351 | $qb | ||
| 352 |                 ->andWhere('o.order_date >= :order_date_start') | ||
| 353 |                 ->setParameter('order_date_start', $date); | ||
| 354 | } | ||
| 355 | View Code Duplication |         if (!empty($searchData['order_date_end']) && $searchData['order_date_end']) { | |
| 356 | $date = clone $searchData['order_date_end']; | ||
| 357 | $date = $date | ||
| 358 |                 ->modify('+1 days') | ||
| 359 |                 ->format('Y-m-d H:i:s'); | ||
| 360 | $qb | ||
| 361 |                 ->andWhere('o.order_date < :order_date_end') | ||
| 362 |                 ->setParameter('order_date_end', $date); | ||
| 363 | } | ||
| 364 | |||
| 365 | // payment_date | ||
| 366 | View Code Duplication |         if (!empty($searchData['payment_date_start']) && $searchData['payment_date_start']) { | |
| 367 | $date = $searchData['payment_date_start'] | ||
| 368 |                 ->format('Y-m-d H:i:s'); | ||
| 369 | $qb | ||
| 370 |                 ->andWhere('o.payment_date >= :payment_date_start') | ||
| 371 |                 ->setParameter('payment_date_start', $date); | ||
| 372 | } | ||
| 373 | View Code Duplication |         if (!empty($searchData['payment_date_end']) && $searchData['payment_date_end']) { | |
| 374 | $date = clone $searchData['payment_date_end']; | ||
| 375 | $date = $date | ||
| 376 |                 ->modify('+1 days') | ||
| 377 |                 ->format('Y-m-d H:i:s'); | ||
| 378 | $qb | ||
| 379 |                 ->andWhere('o.payment_date < :payment_date_end') | ||
| 380 |                 ->setParameter('payment_date_end', $date); | ||
| 381 | } | ||
| 382 | |||
| 383 | // commit_date | ||
| 384 | View Code Duplication |         if (!empty($searchData['commit_date_start']) && $searchData['commit_date_start']) { | |
| 385 | $date = $searchData['commit_date_start'] | ||
| 386 |                 ->format('Y-m-d H:i:s'); | ||
| 387 | $qb | ||
| 388 |                 ->andWhere('o.commit_date >= :commit_date_start') | ||
| 389 |                 ->setParameter('commit_date_start', $date); | ||
| 390 | } | ||
| 391 | View Code Duplication |         if (!empty($searchData['commit_date_end']) && $searchData['commit_date_end']) { | |
| 392 | $date = clone $searchData['commit_date_end']; | ||
| 393 | $date = $date | ||
| 394 |                 ->modify('+1 days') | ||
| 395 |                 ->format('Y-m-d H:i:s'); | ||
| 396 | $qb | ||
| 397 |                 ->andWhere('o.commit_date < :commit_date_end') | ||
| 398 |                 ->setParameter('commit_date_end', $date); | ||
| 399 | } | ||
| 400 | |||
| 401 | |||
| 402 | // update_date | ||
| 403 | View Code Duplication |         if (!empty($searchData['update_date_start']) && $searchData['update_date_start']) { | |
| 404 | $date = $searchData['update_date_start'] | ||
| 405 |                 ->format('Y-m-d H:i:s'); | ||
| 406 | $qb | ||
| 407 |                 ->andWhere('o.update_date >= :update_date_start') | ||
| 408 |                 ->setParameter('update_date_start', $date); | ||
| 409 | } | ||
| 410 | View Code Duplication |         if (!empty($searchData['update_date_end']) && $searchData['update_date_end']) { | |
| 411 | $date = clone $searchData['update_date_end']; | ||
| 412 | $date = $date | ||
| 413 |                 ->modify('+1 days') | ||
| 414 |                 ->format('Y-m-d H:i:s'); | ||
| 415 | $qb | ||
| 416 |                 ->andWhere('o.update_date < :update_date_end') | ||
| 417 |                 ->setParameter('update_date_end', $date); | ||
| 418 | } | ||
| 419 | |||
| 420 | // payment_total | ||
| 421 | View Code Duplication |         if (isset($searchData['payment_total_start']) && Str::isNotBlank($searchData['payment_total_start'])) { | |
| 422 | $qb | ||
| 423 |                 ->andWhere('o.payment_total >= :payment_total_start') | ||
| 424 |                 ->setParameter('payment_total_start', $searchData['payment_total_start']); | ||
| 425 | } | ||
| 426 | View Code Duplication |         if (isset($searchData['payment_total_end']) && Str::isNotBlank($searchData['payment_total_end'])) { | |
| 427 | $qb | ||
| 428 |                 ->andWhere('o.payment_total <= :payment_total_end') | ||
| 429 |                 ->setParameter('payment_total_end', $searchData['payment_total_end']); | ||
| 430 | } | ||
| 431 | |||
| 432 | // buy_product_name | ||
| 433 | View Code Duplication |         if (isset($searchData['buy_product_name']) && Str::isNotBlank($searchData['buy_product_name'])) { | |
| 434 | $qb | ||
| 435 |                 ->leftJoin('o.OrderDetails', 'od') | ||
| 436 |                 ->andWhere('od.product_name LIKE :buy_product_name') | ||
| 437 |                 ->setParameter('buy_product_name', '%' . $searchData['buy_product_name'] . '%'); | ||
| 438 | } | ||
| 439 | |||
| 440 | |||
| 441 | // Order By | ||
| 442 |         $qb->addOrderBy('o.update_date', 'DESC'); | ||
| 443 | |||
| 444 | return $qb; | ||
| 445 | } | ||
| 446 | |||
| 506 |