Code Duplication    Length = 15-24 lines in 5 locations

src/Arrayy.php 5 locations

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