Code Duplication    Length = 15-24 lines in 5 locations

src/Arrayy.php 5 locations

@@ 3105-3128 (lines=24) @@
3102
     * @psalm-return static<TKey,T>
3103
     * @psalm-mutation-free
3104
     */
3105
    public function invoke($callable, $arguments = []): self
3106
    {
3107
        // If one argument given for each iteration, create an array for it.
3108
        if (\is_array($arguments) === false) {
3109
            $arguments = \array_fill(
3110
                0,
3111
                $this->count(),
3112
                $arguments
3113
            );
3114
        }
3115
3116
        // If the callable has arguments, pass them.
3117
        if ($arguments) {
3118
            $array = \array_map($callable, $this->toArray(), $arguments);
3119
        } else {
3120
            $array = $this->map($callable);
3121
        }
3122
3123
        return static::create(
3124
            $array,
3125
            $this->iteratorClass,
3126
            false
3127
        );
3128
    }
3129
3130
    /**
3131
     * Check whether array is associative or not.
@@ 3700-3714 (lines=15) @@
3697
     * @psalm-return static<int|TKey,T>
3698
     * @psalm-mutation-free
3699
     */
3700
    public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self
3701
    {
3702
        if ($recursive === true) {
3703
            $array = $this->getArrayRecursiveHelperArrayy($array);
3704
            $result = \array_replace_recursive($this->toArray(), $array);
3705
        } else {
3706
            $result = \array_replace($this->toArray(), $array);
3707
        }
3708
3709
        return static::create(
3710
            $result,
3711
            $this->iteratorClass,
3712
            false
3713
        );
3714
    }
3715
3716
    /**
3717
     * Merge the new $array into the current array.
@@ 3732-3746 (lines=15) @@
3729
     * @psalm-return static<TKey,T>
3730
     * @psalm-mutation-free
3731
     */
3732
    public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self
3733
    {
3734
        if ($recursive === true) {
3735
            $array = $this->getArrayRecursiveHelperArrayy($array);
3736
            $result = \array_merge_recursive($this->toArray(), $array);
3737
        } else {
3738
            $result = \array_merge($this->toArray(), $array);
3739
        }
3740
3741
        return static::create(
3742
            $result,
3743
            $this->iteratorClass,
3744
            false
3745
        );
3746
    }
3747
3748
    /**
3749
     * Merge the the current array into the $array.
@@ 3763-3777 (lines=15) @@
3760
     * @psalm-return static<TKey,T>
3761
     * @psalm-mutation-free
3762
     */
3763
    public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self
3764
    {
3765
        if ($recursive === true) {
3766
            $array = $this->getArrayRecursiveHelperArrayy($array);
3767
            $result = \array_replace_recursive($array, $this->toArray());
3768
        } else {
3769
            $result = \array_replace($array, $this->toArray());
3770
        }
3771
3772
        return static::create(
3773
            $result,
3774
            $this->iteratorClass,
3775
            false
3776
        );
3777
    }
3778
3779
    /**
3780
     * Merge the current array into the new $array.
@@ 3795-3809 (lines=15) @@
3792
     * @psalm-return static<TKey,T>
3793
     * @psalm-mutation-free
3794
     */
3795
    public function mergePrependNewIndex(array $array = [], bool $recursive = false): self
3796
    {
3797
        if ($recursive === true) {
3798
            $array = $this->getArrayRecursiveHelperArrayy($array);
3799
            $result = \array_merge_recursive($array, $this->toArray());
3800
        } else {
3801
            $result = \array_merge($array, $this->toArray());
3802
        }
3803
3804
        return static::create(
3805
            $result,
3806
            $this->iteratorClass,
3807
            false
3808
        );
3809
    }
3810
3811
    /**
3812
     * @return ArrayyMeta|static