Code Duplication    Length = 15-24 lines in 5 locations

src/Arrayy.php 5 locations

@@ 3099-3122 (lines=24) @@
3096
     * @psalm-return static<TKey,T>
3097
     * @psalm-mutation-free
3098
     */
3099
    public function invoke($callable, $arguments = []): self
3100
    {
3101
        // If one argument given for each iteration, create an array for it.
3102
        if (\is_array($arguments) === false) {
3103
            $arguments = \array_fill(
3104
                0,
3105
                $this->count(),
3106
                $arguments
3107
            );
3108
        }
3109
3110
        // If the callable has arguments, pass them.
3111
        if ($arguments) {
3112
            $array = \array_map($callable, $this->toArray(), $arguments);
3113
        } else {
3114
            $array = $this->map($callable);
3115
        }
3116
3117
        return static::create(
3118
            $array,
3119
            $this->iteratorClass,
3120
            false
3121
        );
3122
    }
3123
3124
    /**
3125
     * Check whether array is associative or not.
@@ 3694-3708 (lines=15) @@
3691
     * @psalm-return static<int|TKey,T>
3692
     * @psalm-mutation-free
3693
     */
3694
    public function mergeAppendKeepIndex(array $array = [], bool $recursive = false): self
3695
    {
3696
        if ($recursive === true) {
3697
            $array = $this->getArrayRecursiveHelperArrayy($array);
3698
            $result = \array_replace_recursive($this->toArray(), $array);
3699
        } else {
3700
            $result = \array_replace($this->toArray(), $array);
3701
        }
3702
3703
        return static::create(
3704
            $result,
3705
            $this->iteratorClass,
3706
            false
3707
        );
3708
    }
3709
3710
    /**
3711
     * Merge the new $array into the current array.
@@ 3726-3740 (lines=15) @@
3723
     * @psalm-return static<TKey,T>
3724
     * @psalm-mutation-free
3725
     */
3726
    public function mergeAppendNewIndex(array $array = [], bool $recursive = false): self
3727
    {
3728
        if ($recursive === true) {
3729
            $array = $this->getArrayRecursiveHelperArrayy($array);
3730
            $result = \array_merge_recursive($this->toArray(), $array);
3731
        } else {
3732
            $result = \array_merge($this->toArray(), $array);
3733
        }
3734
3735
        return static::create(
3736
            $result,
3737
            $this->iteratorClass,
3738
            false
3739
        );
3740
    }
3741
3742
    /**
3743
     * Merge the the current array into the $array.
@@ 3757-3771 (lines=15) @@
3754
     * @psalm-return static<TKey,T>
3755
     * @psalm-mutation-free
3756
     */
3757
    public function mergePrependKeepIndex(array $array = [], bool $recursive = false): self
3758
    {
3759
        if ($recursive === true) {
3760
            $array = $this->getArrayRecursiveHelperArrayy($array);
3761
            $result = \array_replace_recursive($array, $this->toArray());
3762
        } else {
3763
            $result = \array_replace($array, $this->toArray());
3764
        }
3765
3766
        return static::create(
3767
            $result,
3768
            $this->iteratorClass,
3769
            false
3770
        );
3771
    }
3772
3773
    /**
3774
     * Merge the current array into the new $array.
@@ 3789-3803 (lines=15) @@
3786
     * @psalm-return static<TKey,T>
3787
     * @psalm-mutation-free
3788
     */
3789
    public function mergePrependNewIndex(array $array = [], bool $recursive = false): self
3790
    {
3791
        if ($recursive === true) {
3792
            $array = $this->getArrayRecursiveHelperArrayy($array);
3793
            $result = \array_merge_recursive($array, $this->toArray());
3794
        } else {
3795
            $result = \array_merge($array, $this->toArray());
3796
        }
3797
3798
        return static::create(
3799
            $result,
3800
            $this->iteratorClass,
3801
            false
3802
        );
3803
    }
3804
3805
    /**
3806
     * @return ArrayyMeta|static