Code Duplication    Length = 19-28 lines in 2 locations

src/Arrayy.php 2 locations

@@ 933-951 (lines=19) @@
930
     * @psalm-return static<TKey,T>
931
     * @psalm-mutation-free
932
     */
933
    public function appendToEachValue($prefix): self
934
    {
935
        // init
936
        $result = [];
937
938
        foreach ($this->getGenerator() as $key => $item) {
939
            if ($item instanceof self) {
940
                $result[$key] = $item->appendToEachValue($prefix);
941
            } elseif (\is_array($item) === true) {
942
                $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray();
943
            } elseif (\is_object($item) === true) {
944
                $result[$key] = $item;
945
            } else {
946
                $result[$key] = $prefix . $item;
947
            }
948
        }
949
950
        return self::create($result, $this->iteratorClass, false);
951
    }
952
953
    /**
954
     * Sort an array in reverse order and maintain index association.
@@ 3967-3994 (lines=28) @@
3964
     * @psalm-return static<TKey,T>
3965
     * @psalm-mutation-free
3966
     */
3967
    public function prependToEachValue($suffix): self
3968
    {
3969
        // init
3970
        $result = [];
3971
3972
        foreach ($this->getGenerator() as $key => $item) {
3973
            if ($item instanceof self) {
3974
                $result[$key] = $item->prependToEachValue($suffix);
3975
            } elseif (\is_array($item) === true) {
3976
                $result[$key] = self::create(
3977
                    $item,
3978
                    $this->iteratorClass,
3979
                    false
3980
                )->prependToEachValue($suffix)
3981
                    ->toArray();
3982
            } elseif (\is_object($item) === true) {
3983
                $result[$key] = $item;
3984
            } else {
3985
                $result[$key] = $item . $suffix;
3986
            }
3987
        }
3988
3989
        return self::create(
3990
            $result,
3991
            $this->iteratorClass,
3992
            false
3993
        );
3994
    }
3995
3996
    /**
3997
     * Return the value of a given key and