| Conditions | 57 |
| Paths | 168 |
| Total Lines | 223 |
| Code Lines | 148 |
| 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 |
||
| 386 | function simplifyRestriction($restriction) { |
||
| 387 | if (!is_array($restriction)) { |
||
| 388 | return $restriction; |
||
| 389 | } |
||
| 390 | |||
| 391 | switch ($restriction[0]) { |
||
| 392 | case RES_AND: |
||
| 393 | $restriction[0] = "RES_AND"; |
||
| 394 | if (isset($restriction[1][0]) && is_array($restriction[1][0])) { |
||
| 395 | foreach ($restriction[1] as &$res) { |
||
| 396 | $res = simplifyRestriction($res); |
||
| 397 | } |
||
| 398 | unset($res); |
||
| 399 | } |
||
| 400 | elseif (isset($restriction[1]) && $restriction[1]) { |
||
| 401 | $restriction[1] = simplifyRestriction($restriction[1]); |
||
| 402 | } |
||
| 403 | break; |
||
| 404 | |||
| 405 | case RES_OR: |
||
| 406 | $restriction[0] = "RES_OR"; |
||
| 407 | if (isset($restriction[1][0]) && is_array($restriction[1][0])) { |
||
| 408 | foreach ($restriction[1] as &$res) { |
||
| 409 | $res = simplifyRestriction($res); |
||
| 410 | } |
||
| 411 | unset($res); |
||
| 412 | } |
||
| 413 | elseif (isset($restriction[1]) && $restriction[1]) { |
||
| 414 | $restriction[1] = simplifyRestriction($restriction[1]); |
||
| 415 | } |
||
| 416 | break; |
||
| 417 | |||
| 418 | case RES_NOT: |
||
| 419 | $restriction[0] = "RES_NOT"; |
||
| 420 | $restriction[1][0] = simplifyRestriction($restriction[1][0]); |
||
| 421 | break; |
||
| 422 | |||
| 423 | case RES_COMMENT: |
||
| 424 | $restriction[0] = "RES_COMMENT"; |
||
| 425 | $res = simplifyRestriction($restriction[1][RESTRICTION]); |
||
| 426 | $props = $restriction[1][PROPS]; |
||
| 427 | |||
| 428 | foreach ($props as &$prop) { |
||
| 429 | $propTag = $prop[ULPROPTAG]; |
||
| 430 | $propValue = $prop[VALUE]; |
||
| 431 | |||
| 432 | unset($prop); |
||
| 433 | |||
| 434 | $prop["ULPROPTAG"] = is_string($propTag) ? $propTag : prop2Str($propTag); |
||
| 435 | $prop["VALUE"] = is_array($propValue) ? $propValue[$propTag] : $propValue; |
||
| 436 | } |
||
| 437 | unset($prop, $restriction[1]); |
||
| 438 | |||
| 439 | $restriction[1]["RESTRICTION"] = $res; |
||
| 440 | $restriction[1]["PROPS"] = $props; |
||
| 441 | break; |
||
| 442 | |||
| 443 | case RES_PROPERTY: |
||
| 444 | $restriction[0] = "RES_PROPERTY"; |
||
| 445 | $propTag = $restriction[1][ULPROPTAG]; |
||
| 446 | $propValue = $restriction[1][VALUE]; |
||
| 447 | $relOp = $restriction[1][RELOP]; |
||
| 448 | |||
| 449 | unset($restriction[1]); |
||
| 450 | |||
| 451 | // relop flags |
||
| 452 | $relOpFlags = ""; |
||
| 453 | if ($relOp == RELOP_LT) { |
||
| 454 | $relOpFlags = "RELOP_LT"; |
||
| 455 | } |
||
| 456 | elseif ($relOp == RELOP_LE) { |
||
| 457 | $relOpFlags = "RELOP_LE"; |
||
| 458 | } |
||
| 459 | elseif ($relOp == RELOP_GT) { |
||
| 460 | $relOpFlags = "RELOP_GT"; |
||
| 461 | } |
||
| 462 | elseif ($relOp == RELOP_GE) { |
||
| 463 | $relOpFlags = "RELOP_GE"; |
||
| 464 | } |
||
| 465 | elseif ($relOp == RELOP_EQ) { |
||
| 466 | $relOpFlags = "RELOP_EQ"; |
||
| 467 | } |
||
| 468 | elseif ($relOp == RELOP_NE) { |
||
| 469 | $relOpFlags = "RELOP_NE"; |
||
| 470 | } |
||
| 471 | elseif ($relOp == RELOP_RE) { |
||
| 472 | $relOpFlags = "RELOP_RE"; |
||
| 473 | } |
||
| 474 | |||
| 475 | $restriction[1]["RELOP"] = $relOpFlags; |
||
| 476 | $restriction[1]["ULPROPTAG"] = is_string($propTag) ? $propTag : prop2Str($propTag); |
||
| 477 | $restriction[1]["VALUE"] = is_array($propValue) ? $propValue[$propTag] : $propValue; |
||
| 478 | break; |
||
| 479 | |||
| 480 | case RES_CONTENT: |
||
| 481 | $restriction[0] = "RES_CONTENT"; |
||
| 482 | $propTag = $restriction[1][ULPROPTAG]; |
||
| 483 | $propValue = $restriction[1][VALUE]; |
||
| 484 | $fuzzyLevel = $restriction[1][FUZZYLEVEL]; |
||
| 485 | |||
| 486 | unset($restriction[1]); |
||
| 487 | |||
| 488 | // fuzzy level flags |
||
| 489 | $levels = []; |
||
| 490 | |||
| 491 | if (($fuzzyLevel & FL_SUBSTRING) == FL_SUBSTRING) { |
||
| 492 | $levels[] = "FL_SUBSTRING"; |
||
| 493 | } |
||
| 494 | elseif (($fuzzyLevel & FL_PREFIX) == FL_PREFIX) { |
||
| 495 | $levels[] = "FL_PREFIX"; |
||
| 496 | } |
||
| 497 | else { |
||
| 498 | $levels[] = "FL_FULLSTRING"; |
||
| 499 | } |
||
| 500 | |||
| 501 | if (($fuzzyLevel & FL_IGNORECASE) == FL_IGNORECASE) { |
||
| 502 | $levels[] = "FL_IGNORECASE"; |
||
| 503 | } |
||
| 504 | |||
| 505 | if (($fuzzyLevel & FL_IGNORENONSPACE) == FL_IGNORENONSPACE) { |
||
| 506 | $levels[] = "FL_IGNORENONSPACE"; |
||
| 507 | } |
||
| 508 | |||
| 509 | if (($fuzzyLevel & FL_LOOSE) == FL_LOOSE) { |
||
| 510 | $levels[] = "FL_LOOSE"; |
||
| 511 | } |
||
| 512 | |||
| 513 | $fuzzyLevelFlags = implode(" | ", $levels); |
||
| 514 | |||
| 515 | $restriction[1]["FUZZYLEVEL"] = $fuzzyLevelFlags; |
||
| 516 | $restriction[1]["ULPROPTAG"] = is_string($propTag) ? $propTag : prop2Str($propTag); |
||
| 517 | $restriction[1]["VALUE"] = is_array($propValue) ? $propValue[$propTag] : $propValue; |
||
| 518 | break; |
||
| 519 | |||
| 520 | case RES_COMPAREPROPS: |
||
| 521 | $propTag1 = $restriction[1][ULPROPTAG1]; |
||
| 522 | $propTag2 = $restriction[1][ULPROPTAG2]; |
||
| 523 | |||
| 524 | unset($restriction[1]); |
||
| 525 | |||
| 526 | $restriction[1]["ULPROPTAG1"] = is_string($propTag1) ? $proptag1 : prop2Str($proptag1); |
||
| 527 | $restriction[1]["ULPROPTAG2"] = is_string($propTag2) ? $propTag2 : prop2Str($propTag2); |
||
| 528 | break; |
||
| 529 | |||
| 530 | case RES_BITMASK: |
||
| 531 | $restriction[0] = "RES_BITMASK"; |
||
| 532 | $propTag = $restriction[1][ULPROPTAG]; |
||
| 533 | $maskType = $restriction[1][ULTYPE]; |
||
| 534 | $maskValue = $restriction[1][ULMASK]; |
||
| 535 | |||
| 536 | unset($restriction[1]); |
||
| 537 | |||
| 538 | // relop flags |
||
| 539 | $maskTypeFlags = ""; |
||
| 540 | if ($maskType == BMR_EQZ) { |
||
| 541 | $maskTypeFlags = "BMR_EQZ"; |
||
| 542 | } |
||
| 543 | elseif ($maskType == BMR_NEZ) { |
||
| 544 | $maskTypeFlags = "BMR_NEZ"; |
||
| 545 | } |
||
| 546 | |||
| 547 | $restriction[1]["ULPROPTAG"] = is_string($propTag) ? $propTag : prop2Str($propTag); |
||
| 548 | $restriction[1]["ULTYPE"] = $maskTypeFlags; |
||
| 549 | $restriction[1]["ULMASK"] = $maskValue; |
||
| 550 | break; |
||
| 551 | |||
| 552 | case RES_SIZE: |
||
| 553 | $restriction[0] = "RES_SIZE"; |
||
| 554 | $propTag = $restriction[1][ULPROPTAG]; |
||
| 555 | $propValue = $restriction[1][CB]; |
||
| 556 | $relOp = $restriction[1][RELOP]; |
||
| 557 | |||
| 558 | unset($restriction[1]); |
||
| 559 | |||
| 560 | // relop flags |
||
| 561 | $relOpFlags = ""; |
||
| 562 | if ($relOp == RELOP_LT) { |
||
| 563 | $relOpFlags = "RELOP_LT"; |
||
| 564 | } |
||
| 565 | elseif ($relOp == RELOP_LE) { |
||
| 566 | $relOpFlags = "RELOP_LE"; |
||
| 567 | } |
||
| 568 | elseif ($relOp == RELOP_GT) { |
||
| 569 | $relOpFlags = "RELOP_GT"; |
||
| 570 | } |
||
| 571 | elseif ($relOp == RELOP_GE) { |
||
| 572 | $relOpFlags = "RELOP_GE"; |
||
| 573 | } |
||
| 574 | elseif ($relOp == RELOP_EQ) { |
||
| 575 | $relOpFlags = "RELOP_EQ"; |
||
| 576 | } |
||
| 577 | elseif ($relOp == RELOP_NE) { |
||
| 578 | $relOpFlags = "RELOP_NE"; |
||
| 579 | } |
||
| 580 | elseif ($relOp == RELOP_RE) { |
||
| 581 | $relOpFlags = "RELOP_RE"; |
||
| 582 | } |
||
| 583 | |||
| 584 | $restriction[1]["ULPROPTAG"] = is_string($propTag) ? $propTag : prop2Str($propTag); |
||
| 585 | $restriction[1]["RELOP"] = $relOpFlags; |
||
| 586 | $restriction[1]["CB"] = $propValue; |
||
| 587 | break; |
||
| 588 | |||
| 589 | case RES_EXIST: |
||
| 590 | $propTag = $restriction[1][ULPROPTAG]; |
||
| 591 | |||
| 592 | unset($restriction[1]); |
||
| 593 | |||
| 594 | $restriction[1]["ULPROPTAG"] = is_string($propTag) ? $propTag : prop2Str($propTag); |
||
| 595 | break; |
||
| 596 | |||
| 597 | case RES_SUBRESTRICTION: |
||
| 598 | $propTag = $restriction[1][ULPROPTAG]; |
||
| 599 | $res = simplifyRestriction($restriction[1][RESTRICTION]); |
||
| 600 | |||
| 601 | unset($restriction[1]); |
||
| 602 | |||
| 603 | $restriction[1]["ULPROPTAG"] = is_string($propTag) ? $propTag : prop2Str($propTag); |
||
| 604 | $restriction[1]["RESTRICTION"] = $res; |
||
| 605 | break; |
||
| 606 | } |
||
| 607 | |||
| 608 | return $restriction; |
||
| 609 | } |
||
| 610 |