Code Duplication    Length = 19-28 lines in 2 locations

src/Arrayy.php 2 locations

@@ 988-1006 (lines=19) @@
985
     * @psalm-return static<TKey,T>
986
     * @psalm-mutation-free
987
     */
988
    public function appendToEachValue($prefix): self
989
    {
990
        // init
991
        $result = [];
992
993
        foreach ($this->getGenerator() as $key => $item) {
994
            if ($item instanceof self) {
995
                $result[$key] = $item->appendToEachValue($prefix);
996
            } elseif (\is_array($item) === true) {
997
                $result[$key] = self::create($item, $this->iteratorClass, false)->appendToEachValue($prefix)->toArray();
998
            } elseif (\is_object($item) === true) {
999
                $result[$key] = $item;
1000
            } else {
1001
                $result[$key] = $prefix . $item;
1002
            }
1003
        }
1004
1005
        return self::create($result, $this->iteratorClass, false);
1006
    }
1007
1008
    /**
1009
     * Sort an array in reverse order and maintain index association.
@@ 4231-4258 (lines=28) @@
4228
     * @psalm-return static<TKey,T>
4229
     * @psalm-mutation-free
4230
     */
4231
    public function prependToEachValue($suffix): self
4232
    {
4233
        // init
4234
        $result = [];
4235
4236
        foreach ($this->getGenerator() as $key => $item) {
4237
            if ($item instanceof self) {
4238
                $result[$key] = $item->prependToEachValue($suffix);
4239
            } elseif (\is_array($item) === true) {
4240
                $result[$key] = self::create(
4241
                    $item,
4242
                    $this->iteratorClass,
4243
                    false
4244
                )->prependToEachValue($suffix)
4245
                    ->toArray();
4246
            } elseif (\is_object($item) === true) {
4247
                $result[$key] = $item;
4248
            } else {
4249
                $result[$key] = $item . $suffix;
4250
            }
4251
        }
4252
4253
        return self::create(
4254
            $result,
4255
            $this->iteratorClass,
4256
            false
4257
        );
4258
    }
4259
4260
    /**
4261
     * Return the value of a given key and