Code Duplication    Length = 19-26 lines in 2 locations

src/Arrayy.php 2 locations

@@ 902-920 (lines=19) @@
899
     * @psalm-return static<TKey,T>
900
     * @psalm-mutation-free
901
     */
902
    public function appendToEachKey($prefix): self
903
    {
904
        // init
905
        $result = [];
906
907
        foreach ($this->getGenerator() as $key => $item) {
908
            if ($item instanceof self) {
909
                $result[$prefix . $key] = $item->appendToEachKey($prefix);
910
            } elseif (\is_array($item) === true) {
911
                $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
912
                    ->appendToEachKey($prefix)
913
                    ->toArray();
914
            } else {
915
                $result[$prefix . $key] = $item;
916
            }
917
        }
918
919
        return self::create($result, $this->iteratorClass, false);
920
    }
921
922
    /**
923
     * Add a prefix to each value.
@@ 3929-3954 (lines=26) @@
3926
     * @psalm-return static<TKey,T>
3927
     * @psalm-mutation-free
3928
     */
3929
    public function prependToEachKey($suffix): self
3930
    {
3931
        // init
3932
        $result = [];
3933
3934
        foreach ($this->getGenerator() as $key => $item) {
3935
            if ($item instanceof self) {
3936
                $result[$key] = $item->prependToEachKey($suffix);
3937
            } elseif (\is_array($item) === true) {
3938
                $result[$key] = self::create(
3939
                    $item,
3940
                    $this->iteratorClass,
3941
                    false
3942
                )->prependToEachKey($suffix)
3943
                    ->toArray();
3944
            } else {
3945
                $result[$key . $suffix] = $item;
3946
            }
3947
        }
3948
3949
        return self::create(
3950
            $result,
3951
            $this->iteratorClass,
3952
            false
3953
        );
3954
    }
3955
3956
    /**
3957
     * Add a suffix to each value.