Code Duplication    Length = 19-26 lines in 2 locations

src/Arrayy.php 2 locations

@@ 957-975 (lines=19) @@
954
     * @psalm-return static<TKey,T>
955
     * @psalm-mutation-free
956
     */
957
    public function appendToEachKey($prefix): self
958
    {
959
        // init
960
        $result = [];
961
962
        foreach ($this->getGenerator() as $key => $item) {
963
            if ($item instanceof self) {
964
                $result[$prefix . $key] = $item->appendToEachKey($prefix);
965
            } elseif (\is_array($item) === true) {
966
                $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
967
                    ->appendToEachKey($prefix)
968
                    ->toArray();
969
            } else {
970
                $result[$prefix . $key] = $item;
971
            }
972
        }
973
974
        return self::create($result, $this->iteratorClass, false);
975
    }
976
977
    /**
978
     * Add a prefix to each value.
@@ 4110-4135 (lines=26) @@
4107
     * @psalm-return static<TKey,T>
4108
     * @psalm-mutation-free
4109
     */
4110
    public function prependToEachKey($suffix): self
4111
    {
4112
        // init
4113
        $result = [];
4114
4115
        foreach ($this->getGenerator() as $key => $item) {
4116
            if ($item instanceof self) {
4117
                $result[$key] = $item->prependToEachKey($suffix);
4118
            } elseif (\is_array($item) === true) {
4119
                $result[$key] = self::create(
4120
                    $item,
4121
                    $this->iteratorClass,
4122
                    false
4123
                )->prependToEachKey($suffix)
4124
                    ->toArray();
4125
            } else {
4126
                $result[$key . $suffix] = $item;
4127
            }
4128
        }
4129
4130
        return self::create(
4131
            $result,
4132
            $this->iteratorClass,
4133
            false
4134
        );
4135
    }
4136
4137
    /**
4138
     * Add a suffix to each value.