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.
@@ 3981-4006 (lines=26) @@
3978
     * @psalm-return static<TKey,T>
3979
     * @psalm-mutation-free
3980
     */
3981
    public function prependToEachKey($suffix): self
3982
    {
3983
        // init
3984
        $result = [];
3985
3986
        foreach ($this->getGenerator() as $key => $item) {
3987
            if ($item instanceof self) {
3988
                $result[$key] = $item->prependToEachKey($suffix);
3989
            } elseif (\is_array($item) === true) {
3990
                $result[$key] = self::create(
3991
                    $item,
3992
                    $this->iteratorClass,
3993
                    false
3994
                )->prependToEachKey($suffix)
3995
                    ->toArray();
3996
            } else {
3997
                $result[$key . $suffix] = $item;
3998
            }
3999
        }
4000
4001
        return self::create(
4002
            $result,
4003
            $this->iteratorClass,
4004
            false
4005
        );
4006
    }
4007
4008
    /**
4009
     * Add a suffix to each value.