Code Duplication    Length = 15-24 lines in 5 locations

src/Arrayy.php 5 locations

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