Code Duplication    Length = 24-28 lines in 4 locations

src/Zicht/Itertools/itertools.php 4 locations

@@ 525-552 (lines=28) @@
522
 *
523
 * @return FilterIterator
524
 */
525
function filter()
526
{
527
    // note, once we stop supporting php 5.5, we can rewrite the code below
528
    // to the filter(...$iterables) structure.
529
    // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
530
531
    $args = func_get_args();
532
    switch (sizeof($args)) {
533
        case 1:
534
            $strategy = null;
535
            $iterable = $args[0];
536
            break;
537
538
        case 2:
539
            $strategy = $args[0];
540
            $iterable = $args[1];
541
            break;
542
543
        default:
544
            throw new \InvalidArgumentException('filter requires either one (iterable) or two (strategy, iterable) arguments');
545
    }
546
547
    if (!($iterable instanceof FilterInterface)) {
548
        $iterable = iterable($iterable);
549
    }
550
551
    return $iterable->filter($strategy);
552
}
553
554
/**
555
 * Make an iterator that returns values from $iterable where the
@@ 674-697 (lines=24) @@
671
 *
672
 * @return UniqueIterator
673
 */
674
function unique()
675
{
676
    $args = func_get_args();
677
    switch (sizeof($args)) {
678
        case 1:
679
            $strategy = null;
680
            $iterable = $args[0];
681
            break;
682
683
        case 2:
684
            $strategy = $args[0];
685
            $iterable = $args[1];
686
            break;
687
688
        default:
689
            throw new \InvalidArgumentException('unique requires either one (iterable) or two (strategy, iterable) arguments');
690
    }
691
692
    if (!($iterable instanceof UniqueInterface)) {
693
        $iterable = iterable($iterable);
694
    }
695
696
    return $iterable->unique($strategy);
697
}
698
699
/**
700
 * Returns an iterator where the values from $strategy are unique
@@ 733-756 (lines=24) @@
730
 *
731
 * @return boolean
732
 */
733
function any()
734
{
735
    $args = func_get_args();
736
    switch (sizeof($args)) {
737
        case 1:
738
            $strategy = null;
739
            $iterable = $args[0];
740
            break;
741
742
        case 2:
743
            $strategy = $args[0];
744
            $iterable = $args[1];
745
            break;
746
747
        default:
748
            throw new \InvalidArgumentException('any requires either one (iterable) or two (strategy, iterable) arguments');
749
    }
750
751
    if (!($iterable instanceof AllInterface)) {
752
        $iterable = iterable($iterable);
753
    }
754
755
    return $iterable->any($strategy);
756
}
757
758
/**
759
 * Returns true when all elements of $iterable are not empty, otherwise returns false
@@ 778-801 (lines=24) @@
775
 *
776
 * @return boolean
777
 */
778
function all()
779
{
780
    $args = func_get_args();
781
    switch (sizeof($args)) {
782
        case 1:
783
            $strategy = null;
784
            $iterable = $args[0];
785
            break;
786
787
        case 2:
788
            $strategy = $args[0];
789
            $iterable = $args[1];
790
            break;
791
792
        default:
793
            throw new \InvalidArgumentException('all requires either one (iterable) or two (strategy, iterable) arguments');
794
    }
795
796
    if (!($iterable instanceof AllInterface)) {
797
        $iterable = iterable($iterable);
798
    }
799
800
    return $iterable->all($strategy);
801
}
802
803
/**
804
 * Make an iterator that contains a slice of $iterable