Code Duplication    Length = 24-28 lines in 4 locations

src/Zicht/Itertools/itertools.php 4 locations

@@ 517-544 (lines=28) @@
514
 *
515
 * @return FilterIterator
516
 */
517
function filter()
518
{
519
    // note, once we stop supporting php 5.5, we can rewrite the code below
520
    // to the filter(...$iterables) structure.
521
    // http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list
522
523
    $args = func_get_args();
524
    switch (sizeof($args)) {
525
        case 1:
526
            $strategy = null;
527
            $iterable = $args[0];
528
            break;
529
530
        case 2:
531
            $strategy = $args[0];
532
            $iterable = $args[1];
533
            break;
534
535
        default:
536
            throw new \InvalidArgumentException('filter requires either one (iterable) or two (strategy, iterable) arguments');
537
    }
538
539
    if (!($iterable instanceof FilterInterface)) {
540
        $iterable = iterable($iterable);
541
    }
542
543
    return $iterable->filter($strategy);
544
}
545
546
/**
547
 * Make an iterator that returns values from $iterable where the
@@ 666-689 (lines=24) @@
663
 *
664
 * @return UniqueIterator
665
 */
666
function unique()
667
{
668
    $args = func_get_args();
669
    switch (sizeof($args)) {
670
        case 1:
671
            $strategy = null;
672
            $iterable = $args[0];
673
            break;
674
675
        case 2:
676
            $strategy = $args[0];
677
            $iterable = $args[1];
678
            break;
679
680
        default:
681
            throw new \InvalidArgumentException('unique requires either one (iterable) or two (strategy, iterable) arguments');
682
    }
683
684
    if (!($iterable instanceof UniqueInterface)) {
685
        $iterable = iterable($iterable);
686
    }
687
688
    return $iterable->unique($strategy);
689
}
690
691
/**
692
 * Returns an iterator where the values from $strategy are unique
@@ 725-748 (lines=24) @@
722
 *
723
 * @return boolean
724
 */
725
function any()
726
{
727
    $args = func_get_args();
728
    switch (sizeof($args)) {
729
        case 1:
730
            $strategy = null;
731
            $iterable = $args[0];
732
            break;
733
734
        case 2:
735
            $strategy = $args[0];
736
            $iterable = $args[1];
737
            break;
738
739
        default:
740
            throw new \InvalidArgumentException('any requires either one (iterable) or two (strategy, iterable) arguments');
741
    }
742
743
    if (!($iterable instanceof AllInterface)) {
744
        $iterable = iterable($iterable);
745
    }
746
747
    return $iterable->any($strategy);
748
}
749
750
/**
751
 * Returns true when all elements of $iterable are not empty, otherwise returns false
@@ 770-793 (lines=24) @@
767
 *
768
 * @return boolean
769
 */
770
function all()
771
{
772
    $args = func_get_args();
773
    switch (sizeof($args)) {
774
        case 1:
775
            $strategy = null;
776
            $iterable = $args[0];
777
            break;
778
779
        case 2:
780
            $strategy = $args[0];
781
            $iterable = $args[1];
782
            break;
783
784
        default:
785
            throw new \InvalidArgumentException('all requires either one (iterable) or two (strategy, iterable) arguments');
786
    }
787
788
    if (!($iterable instanceof AllInterface)) {
789
        $iterable = iterable($iterable);
790
    }
791
792
    return $iterable->all($strategy);
793
}
794
795
/**
796
 * Make an iterator that contains a slice of $iterable