Code Duplication    Length = 19-28 lines in 2 locations

src/Arrayy.php 2 locations

@@ 970-988 (lines=19) @@
967
     * @psalm-return static<TKey,T>
968
     * @psalm-mutation-free
969
     */
970
    public function appendToEachValue($prefix): self
971
    {
972
        // init
973
        $result = [];
974
975
        foreach ($this->getGenerator() as $key => $item) {
976
            if ($item instanceof self) {
977
                $result[$key] = $item->appendToEachValue($prefix);
978
            } elseif (\is_array($item) === true) {
979
                $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray();
980
            } elseif (\is_object($item) === true) {
981
                $result[$key] = $item;
982
            } else {
983
                $result[$key] = $prefix . $item;
984
            }
985
        }
986
987
        return self::create($result, $this->iteratorClass, false);
988
    }
989
990
    /**
991
     * Sort an array in reverse order and maintain index association.
@@ 4019-4046 (lines=28) @@
4016
     * @psalm-return static<TKey,T>
4017
     * @psalm-mutation-free
4018
     */
4019
    public function prependToEachValue($suffix): self
4020
    {
4021
        // init
4022
        $result = [];
4023
4024
        foreach ($this->getGenerator() as $key => $item) {
4025
            if ($item instanceof self) {
4026
                $result[$key] = $item->prependToEachValue($suffix);
4027
            } elseif (\is_array($item) === true) {
4028
                $result[$key] = self::create(
4029
                    $item,
4030
                    $this->iteratorClass,
4031
                    false
4032
                )->prependToEachValue($suffix)
4033
                    ->toArray();
4034
            } elseif (\is_object($item) === true) {
4035
                $result[$key] = $item;
4036
            } else {
4037
                $result[$key] = $item . $suffix;
4038
            }
4039
        }
4040
4041
        return self::create(
4042
            $result,
4043
            $this->iteratorClass,
4044
            false
4045
        );
4046
    }
4047
4048
    /**
4049
     * Return the value of a given key and