Code Duplication    Length = 24-28 lines in 5 locations

src/Zicht/Itertools/itertools.php 5 locations

@@ 548-575 (lines=28) @@
545
 * @return FilterIterator
546
 * @deprecated Use iterable($iterable)->filter($strategy), will be removed in version 3.0
547
 */
548
function filter()
549
{
550
    // note, once we stop supporting php 5.5, we can rewrite the code below
551
    // to the filter(...$iterables) structure.
552
    // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
553
554
    $args = func_get_args();
555
    switch (sizeof($args)) {
556
        case 1:
557
            $strategy = null;
558
            $iterable = $args[0];
559
            break;
560
561
        case 2:
562
            $strategy = $args[0];
563
            $iterable = $args[1];
564
            break;
565
566
        default:
567
            throw new \InvalidArgumentException('filter requires either one (iterable) or two (strategy, iterable) arguments');
568
    }
569
570
    if (!($iterable instanceof FilterInterface)) {
571
        $iterable = iterable($iterable);
572
    }
573
574
    return $iterable->filter($strategy);
575
}
576
577
/**
578
 * Make an iterator that returns values from $iterable where the
@@ 699-722 (lines=24) @@
696
 * @return UniqueIterator
697
 * @deprecated Use iterable($iterable)->unique($strategy), will be removed in version 3.0
698
 */
699
function unique()
700
{
701
    $args = func_get_args();
702
    switch (sizeof($args)) {
703
        case 1:
704
            $strategy = null;
705
            $iterable = $args[0];
706
            break;
707
708
        case 2:
709
            $strategy = $args[0];
710
            $iterable = $args[1];
711
            break;
712
713
        default:
714
            throw new \InvalidArgumentException('unique requires either one (iterable) or two (strategy, iterable) arguments');
715
    }
716
717
    if (!($iterable instanceof UniqueInterface)) {
718
        $iterable = iterable($iterable);
719
    }
720
721
    return $iterable->unique($strategy);
722
}
723
724
/**
725
 * Returns an iterator where the values from $strategy are unique
@@ 732-755 (lines=24) @@
729
 * @return UniqueIterator
730
 * @deprecated Use iterable($iterable)->unique($strategy), will be removed in version 3.0
731
 */
732
function uniqueBy($strategy, $iterable) // phpcs:ignore Zicht.NamingConventions.Functions.GlobalNaming
733
{
734
    $args = func_get_args();
735
    switch (sizeof($args)) {
736
        case 1:
737
            $strategy = null;
738
            $iterable = $args[0];
739
            break;
740
741
        case 2:
742
            $strategy = $args[0];
743
            $iterable = $args[1];
744
            break;
745
746
        default:
747
            throw new \InvalidArgumentException('unique requires either one (iterable) or two (strategy, iterable) arguments');
748
    }
749
750
    if (!($iterable instanceof UniqueInterface)) {
751
        $iterable = iterable($iterable);
752
    }
753
754
    return $iterable->unique($strategy);
755
}
756
757
/**
758
 * Returns true when one or more element of $iterable is not empty, otherwise returns false
@@ 778-801 (lines=24) @@
775
 * @return boolean
776
 * @deprecated Use iterable($iterable)->any($strategy), will be removed in version 3.0
777
 */
778
function any()
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('any 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->any($strategy);
801
}
802
803
/**
804
 * Returns true when all elements of $iterable are not empty, otherwise returns false
@@ 824-847 (lines=24) @@
821
 * @return boolean
822
 * @deprecated Use iterable($iterable)->all($strategy), will be removed in version 3.0
823
 */
824
function all()
825
{
826
    $args = func_get_args();
827
    switch (sizeof($args)) {
828
        case 1:
829
            $strategy = null;
830
            $iterable = $args[0];
831
            break;
832
833
        case 2:
834
            $strategy = $args[0];
835
            $iterable = $args[1];
836
            break;
837
838
        default:
839
            throw new \InvalidArgumentException('all requires either one (iterable) or two (strategy, iterable) arguments');
840
    }
841
842
    if (!($iterable instanceof AllInterface)) {
843
        $iterable = iterable($iterable);
844
    }
845
846
    return $iterable->all($strategy);
847
}
848
849
/**
850
 * Make an iterator that contains a slice of $iterable