Code Duplication    Length = 15-24 lines in 5 locations

src/Arrayy.php 5 locations

@@ 3033-3056 (lines=24) @@
3030
     * @psalm-return static<TKey,T>
3031
     * @psalm-mutation-free
3032
     */
3033
    public function invoke($callable, $arguments = []): self
3034
    {
3035
        // If one argument given for each iteration, create an array for it.
3036
        if (\is_array($arguments) === false) {
3037
            $arguments = \array_fill(
3038
                0,
3039
                $this->count(),
3040
                $arguments
3041
            );
3042
        }
3043
3044
        // If the callable has arguments, pass them.
3045
        if ($arguments) {
3046
            $array = \array_map($callable, $this->toArray(), $arguments);
3047
        } else {
3048
            $array = $this->map($callable);
3049
        }
3050
3051
        return static::create(
3052
            $array,
3053
            $this->iteratorClass,
3054
            false
3055
        );
3056
    }
3057
3058
    /**
3059
     * Check whether array is associative or not.
@@ 3628-3642 (lines=15) @@
3625
     * @psalm-return static<int|TKey,T>
3626
     * @psalm-mutation-free
3627
     */
3628
    public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self
3629
    {
3630
        if ($recursive === true) {
3631
            $array = $this->getArrayRecursiveHelperArrayy($array);
3632
            $result = \array_replace_recursive($this->toArray(), $array);
3633
        } else {
3634
            $result = \array_replace($this->toArray(), $array);
3635
        }
3636
3637
        return static::create(
3638
            $result,
3639
            $this->iteratorClass,
3640
            false
3641
        );
3642
    }
3643
3644
    /**
3645
     * Merge the new $array into the current array.
@@ 3660-3674 (lines=15) @@
3657
     * @psalm-return static<TKey,T>
3658
     * @psalm-mutation-free
3659
     */
3660
    public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self
3661
    {
3662
        if ($recursive === true) {
3663
            $array = $this->getArrayRecursiveHelperArrayy($array);
3664
            $result = \array_merge_recursive($this->toArray(), $array);
3665
        } else {
3666
            $result = \array_merge($this->toArray(), $array);
3667
        }
3668
3669
        return static::create(
3670
            $result,
3671
            $this->iteratorClass,
3672
            false
3673
        );
3674
    }
3675
3676
    /**
3677
     * Merge the the current array into the $array.
@@ 3691-3705 (lines=15) @@
3688
     * @psalm-return static<TKey,T>
3689
     * @psalm-mutation-free
3690
     */
3691
    public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self
3692
    {
3693
        if ($recursive === true) {
3694
            $array = $this->getArrayRecursiveHelperArrayy($array);
3695
            $result = \array_replace_recursive($array, $this->toArray());
3696
        } else {
3697
            $result = \array_replace($array, $this->toArray());
3698
        }
3699
3700
        return static::create(
3701
            $result,
3702
            $this->iteratorClass,
3703
            false
3704
        );
3705
    }
3706
3707
    /**
3708
     * Merge the current array into the new $array.
@@ 3723-3737 (lines=15) @@
3720
     * @psalm-return static<TKey,T>
3721
     * @psalm-mutation-free
3722
     */
3723
    public function mergePrependNewIndex(array $array = [], bool $recursive = false): self
3724
    {
3725
        if ($recursive === true) {
3726
            $array = $this->getArrayRecursiveHelperArrayy($array);
3727
            $result = \array_merge_recursive($array, $this->toArray());
3728
        } else {
3729
            $result = \array_merge($array, $this->toArray());
3730
        }
3731
3732
        return static::create(
3733
            $result,
3734
            $this->iteratorClass,
3735
            false
3736
        );
3737
    }
3738
3739
    /**
3740
     * @return ArrayyMeta|static