Code Duplication    Length = 19-26 lines in 2 locations

src/Arrayy.php 2 locations

@@ 944-962 (lines=19) @@
941
     * @psalm-return static<TKey,T>
942
     * @psalm-mutation-free
943
     */
944
    public function appendToEachKey($prefix): self
945
    {
946
        // init
947
        $result = [];
948
949
        foreach ($this->getGenerator() as $key => $item) {
950
            if ($item instanceof self) {
951
                $result[$prefix . $key] = $item->appendToEachKey($prefix);
952
            } elseif (\is_array($item) === true) {
953
                $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
954
                    ->appendToEachKey($prefix)
955
                    ->toArray();
956
            } else {
957
                $result[$prefix . $key] = $item;
958
            }
959
        }
960
961
        return self::create($result, $this->iteratorClass, false);
962
    }
963
964
    /**
965
     * Add a prefix to each value.
@@ 4067-4092 (lines=26) @@
4064
     * @psalm-return static<TKey,T>
4065
     * @psalm-mutation-free
4066
     */
4067
    public function prependToEachKey($suffix): self
4068
    {
4069
        // init
4070
        $result = [];
4071
4072
        foreach ($this->getGenerator() as $key => $item) {
4073
            if ($item instanceof self) {
4074
                $result[$key] = $item->prependToEachKey($suffix);
4075
            } elseif (\is_array($item) === true) {
4076
                $result[$key] = self::create(
4077
                    $item,
4078
                    $this->iteratorClass,
4079
                    false
4080
                )->prependToEachKey($suffix)
4081
                    ->toArray();
4082
            } else {
4083
                $result[$key . $suffix] = $item;
4084
            }
4085
        }
4086
4087
        return self::create(
4088
            $result,
4089
            $this->iteratorClass,
4090
            false
4091
        );
4092
    }
4093
4094
    /**
4095
     * Add a suffix to each value.