Code Duplication    Length = 15-24 lines in 5 locations

src/Arrayy.php 5 locations

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