Code Duplication    Length = 19-26 lines in 2 locations

src/Arrayy.php 2 locations

@@ 974-992 (lines=19) @@
971
     * @psalm-return static<TKey,T>
972
     * @psalm-mutation-free
973
     */
974
    public function appendToEachKey($prefix): self
975
    {
976
        // init
977
        $result = [];
978
979
        foreach ($this->getGenerator() as $key => $item) {
980
            if ($item instanceof self) {
981
                $result[$prefix . $key] = $item->appendToEachKey($prefix);
982
            } elseif (\is_array($item) === true) {
983
                $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
984
                    ->appendToEachKey($prefix)
985
                    ->toArray();
986
            } else {
987
                $result[$prefix . $key] = $item;
988
            }
989
        }
990
991
        return self::create($result, $this->iteratorClass, false);
992
    }
993
994
    /**
995
     * Add a prefix to each value.
@@ 4314-4339 (lines=26) @@
4311
     * @psalm-return static<TKey,T>
4312
     * @psalm-mutation-free
4313
     */
4314
    public function prependToEachKey($suffix): self
4315
    {
4316
        // init
4317
        $result = [];
4318
4319
        foreach ($this->getGenerator() as $key => $item) {
4320
            if ($item instanceof self) {
4321
                $result[$key] = $item->prependToEachKey($suffix);
4322
            } elseif (\is_array($item) === true) {
4323
                $result[$key] = self::create(
4324
                    $item,
4325
                    $this->iteratorClass,
4326
                    false
4327
                )->prependToEachKey($suffix)
4328
                    ->toArray();
4329
            } else {
4330
                $result[$key . $suffix] = $item;
4331
            }
4332
        }
4333
4334
        return self::create(
4335
            $result,
4336
            $this->iteratorClass,
4337
            false
4338
        );
4339
    }
4340
4341
    /**
4342
     * Add a suffix to each value.