Code Duplication    Length = 19-26 lines in 2 locations

src/Arrayy.php 2 locations

@@ 710-728 (lines=19) @@
707
     * @return static
708
     *                <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p>
709
     */
710
    public function appendToEachKey($prefix): self
711
    {
712
        // init
713
        $result = [];
714
715
        foreach ($this->getGenerator() as $key => $item) {
716
            if ($item instanceof self) {
717
                $result[$prefix . $key] = $item->appendToEachKey($prefix);
718
            } elseif (\is_array($item) === true) {
719
                $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
720
                    ->appendToEachKey($prefix)
721
                    ->toArray();
722
            } else {
723
                $result[$prefix . $key] = $item;
724
            }
725
        }
726
727
        return self::create($result, $this->iteratorClass, false);
728
    }
729
730
    /**
731
     * Add a prefix to each value.
@@ 3327-3352 (lines=26) @@
3324
     * @return static
3325
     *                <p>(Immutable) Return an Arrayy object, with the prepended keys.</p>
3326
     */
3327
    public function prependToEachKey($suffix): self
3328
    {
3329
        // init
3330
        $result = [];
3331
3332
        foreach ($this->getGenerator() as $key => $item) {
3333
            if ($item instanceof self) {
3334
                $result[$key] = $item->prependToEachKey($suffix);
3335
            } elseif (\is_array($item) === true) {
3336
                $result[$key] = self::create(
3337
                    $item,
3338
                    $this->iteratorClass,
3339
                    false
3340
                )->prependToEachKey($suffix)
3341
                    ->toArray();
3342
            } else {
3343
                $result[$key . $suffix] = $item;
3344
            }
3345
        }
3346
3347
        return self::create(
3348
            $result,
3349
            $this->iteratorClass,
3350
            false
3351
        );
3352
    }
3353
3354
    /**
3355
     * Add a suffix to each value.