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.
@@ 4014-4041 (lines=28) @@
4011
     * @psalm-return static<TKey,T>
4012
     * @psalm-mutation-free
4013
     */
4014
    public function prependToEachValue($suffix): self
4015
    {
4016
        // init
4017
        $result = [];
4018
4019
        foreach ($this->getGenerator() as $key => $item) {
4020
            if ($item instanceof self) {
4021
                $result[$key] = $item->prependToEachValue($suffix);
4022
            } elseif (\is_array($item) === true) {
4023
                $result[$key] = self::create(
4024
                    $item,
4025
                    $this->iteratorClass,
4026
                    false
4027
                )->prependToEachValue($suffix)
4028
                    ->toArray();
4029
            } elseif (\is_object($item) === true) {
4030
                $result[$key] = $item;
4031
            } else {
4032
                $result[$key] = $item . $suffix;
4033
            }
4034
        }
4035
4036
        return self::create(
4037
            $result,
4038
            $this->iteratorClass,
4039
            false
4040
        );
4041
    }
4042
4043
    /**
4044
     * Return the value of a given key and