Code Duplication    Length = 24-28 lines in 4 locations

src/Zicht/Itertools/itertools.php 4 locations

@@ 535-562 (lines=28) @@
532
 *
533
 * @return FilterIterator
534
 */
535
function filter()
536
{
537
    // note, once we stop supporting php 5.5, we can rewrite the code below
538
    // to the filter(...$iterables) structure.
539
    // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
540
541
    $args = func_get_args();
542
    switch (sizeof($args)) {
543
        case 1:
544
            $strategy = null;
545
            $iterable = $args[0];
546
            break;
547
548
        case 2:
549
            $strategy = $args[0];
550
            $iterable = $args[1];
551
            break;
552
553
        default:
554
            throw new \InvalidArgumentException('filter requires either one (iterable) or two (strategy, iterable) arguments');
555
    }
556
557
    if (!($iterable instanceof FilterInterface)) {
558
        $iterable = iterable($iterable);
559
    }
560
561
    return $iterable->filter($strategy);
562
}
563
564
/**
565
 * Make an iterator that returns values from $iterable where the
@@ 684-707 (lines=24) @@
681
 *
682
 * @return UniqueIterator
683
 */
684
function unique()
685
{
686
    $args = func_get_args();
687
    switch (sizeof($args)) {
688
        case 1:
689
            $strategy = null;
690
            $iterable = $args[0];
691
            break;
692
693
        case 2:
694
            $strategy = $args[0];
695
            $iterable = $args[1];
696
            break;
697
698
        default:
699
            throw new \InvalidArgumentException('unique requires either one (iterable) or two (strategy, iterable) arguments');
700
    }
701
702
    if (!($iterable instanceof UniqueInterface)) {
703
        $iterable = iterable($iterable);
704
    }
705
706
    return $iterable->unique($strategy);
707
}
708
709
/**
710
 * Returns an iterator where the values from $strategy are unique
@@ 743-766 (lines=24) @@
740
 *
741
 * @return boolean
742
 */
743
function any()
744
{
745
    $args = func_get_args();
746
    switch (sizeof($args)) {
747
        case 1:
748
            $strategy = null;
749
            $iterable = $args[0];
750
            break;
751
752
        case 2:
753
            $strategy = $args[0];
754
            $iterable = $args[1];
755
            break;
756
757
        default:
758
            throw new \InvalidArgumentException('any requires either one (iterable) or two (strategy, iterable) arguments');
759
    }
760
761
    if (!($iterable instanceof AllInterface)) {
762
        $iterable = iterable($iterable);
763
    }
764
765
    return $iterable->any($strategy);
766
}
767
768
/**
769
 * Returns true when all elements of $iterable are not empty, otherwise returns false
@@ 788-811 (lines=24) @@
785
 *
786
 * @return boolean
787
 */
788
function all()
789
{
790
    $args = func_get_args();
791
    switch (sizeof($args)) {
792
        case 1:
793
            $strategy = null;
794
            $iterable = $args[0];
795
            break;
796
797
        case 2:
798
            $strategy = $args[0];
799
            $iterable = $args[1];
800
            break;
801
802
        default:
803
            throw new \InvalidArgumentException('all requires either one (iterable) or two (strategy, iterable) arguments');
804
    }
805
806
    if (!($iterable instanceof AllInterface)) {
807
        $iterable = iterable($iterable);
808
    }
809
810
    return $iterable->all($strategy);
811
}
812
813
/**
814
 * Make an iterator that contains a slice of $iterable