Code Duplication    Length = 15-24 lines in 5 locations

src/Arrayy.php 5 locations

@@ 3265-3288 (lines=24) @@
3262
     * @psalm-return static<TKey,T>
3263
     * @psalm-mutation-free
3264
     */
3265
    public function invoke($callable, $arguments = []): self
3266
    {
3267
        // If one argument given for each iteration, create an array for it.
3268
        if (\is_array($arguments) === false) {
3269
            $arguments = \array_fill(
3270
                0,
3271
                $this->count(),
3272
                $arguments
3273
            );
3274
        }
3275
3276
        // If the callable has arguments, pass them.
3277
        if ($arguments) {
3278
            $array = \array_map($callable, $this->toArray(), $arguments);
3279
        } else {
3280
            $array = $this->map($callable);
3281
        }
3282
3283
        return static::create(
3284
            $array,
3285
            $this->iteratorClass,
3286
            false
3287
        );
3288
    }
3289
3290
    /**
3291
     * Check whether array is associative or not.
@@ 3862-3876 (lines=15) @@
3859
     * @psalm-return static<int|TKey,T>
3860
     * @psalm-mutation-free
3861
     */
3862
    public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self
3863
    {
3864
        if ($recursive === true) {
3865
            $array = $this->getArrayRecursiveHelperArrayy($array);
3866
            $result = \array_replace_recursive($this->toArray(), $array);
3867
        } else {
3868
            $result = \array_replace($this->toArray(), $array);
3869
        }
3870
3871
        return static::create(
3872
            $result,
3873
            $this->iteratorClass,
3874
            false
3875
        );
3876
    }
3877
3878
    /**
3879
     * Merge the new $array into the current array.
@@ 3894-3908 (lines=15) @@
3891
     * @psalm-return static<TKey,T>
3892
     * @psalm-mutation-free
3893
     */
3894
    public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self
3895
    {
3896
        if ($recursive === true) {
3897
            $array = $this->getArrayRecursiveHelperArrayy($array);
3898
            $result = \array_merge_recursive($this->toArray(), $array);
3899
        } else {
3900
            $result = \array_merge($this->toArray(), $array);
3901
        }
3902
3903
        return static::create(
3904
            $result,
3905
            $this->iteratorClass,
3906
            false
3907
        );
3908
    }
3909
3910
    /**
3911
     * Merge the the current array into the $array.
@@ 3925-3939 (lines=15) @@
3922
     * @psalm-return static<TKey,T>
3923
     * @psalm-mutation-free
3924
     */
3925
    public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self
3926
    {
3927
        if ($recursive === true) {
3928
            $array = $this->getArrayRecursiveHelperArrayy($array);
3929
            $result = \array_replace_recursive($array, $this->toArray());
3930
        } else {
3931
            $result = \array_replace($array, $this->toArray());
3932
        }
3933
3934
        return static::create(
3935
            $result,
3936
            $this->iteratorClass,
3937
            false
3938
        );
3939
    }
3940
3941
    /**
3942
     * Merge the current array into the new $array.
@@ 3957-3971 (lines=15) @@
3954
     * @psalm-return static<TKey,T>
3955
     * @psalm-mutation-free
3956
     */
3957
    public function mergePrependNewIndex(array $array = [], bool $recursive = false): self
3958
    {
3959
        if ($recursive === true) {
3960
            $array = $this->getArrayRecursiveHelperArrayy($array);
3961
            $result = \array_merge_recursive($array, $this->toArray());
3962
        } else {
3963
            $result = \array_merge($array, $this->toArray());
3964
        }
3965
3966
        return static::create(
3967
            $result,
3968
            $this->iteratorClass,
3969
            false
3970
        );
3971
    }
3972
3973
    /**
3974
     * @return ArrayyMeta|static