Code Duplication    Length = 19-26 lines in 2 locations

src/Arrayy.php 2 locations

@@ 939-957 (lines=19) @@
936
     * @psalm-return static<TKey,T>
937
     * @psalm-mutation-free
938
     */
939
    public function appendToEachKey($prefix): self
940
    {
941
        // init
942
        $result = [];
943
944
        foreach ($this->getGenerator() as $key => $item) {
945
            if ($item instanceof self) {
946
                $result[$prefix . $key] = $item->appendToEachKey($prefix);
947
            } elseif (\is_array($item) === true) {
948
                $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
949
                    ->appendToEachKey($prefix)
950
                    ->toArray();
951
            } else {
952
                $result[$prefix . $key] = $item;
953
            }
954
        }
955
956
        return self::create($result, $this->iteratorClass, false);
957
    }
958
959
    /**
960
     * Add a prefix to each value.
@@ 3976-4001 (lines=26) @@
3973
     * @psalm-return static<TKey,T>
3974
     * @psalm-mutation-free
3975
     */
3976
    public function prependToEachKey($suffix): self
3977
    {
3978
        // init
3979
        $result = [];
3980
3981
        foreach ($this->getGenerator() as $key => $item) {
3982
            if ($item instanceof self) {
3983
                $result[$key] = $item->prependToEachKey($suffix);
3984
            } elseif (\is_array($item) === true) {
3985
                $result[$key] = self::create(
3986
                    $item,
3987
                    $this->iteratorClass,
3988
                    false
3989
                )->prependToEachKey($suffix)
3990
                    ->toArray();
3991
            } else {
3992
                $result[$key . $suffix] = $item;
3993
            }
3994
        }
3995
3996
        return self::create(
3997
            $result,
3998
            $this->iteratorClass,
3999
            false
4000
        );
4001
    }
4002
4003
    /**
4004
     * Add a suffix to each value.