Code Duplication    Length = 17-19 lines in 2 locations

src/Arrayy.php 2 locations

@@ 631-649 (lines=19) @@
628
     * @return static
629
     *                <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p>
630
     */
631
    public function appendToEachKey($prefix): self
632
    {
633
        // init
634
        $result = [];
635
636
        foreach ($this->getGenerator() as $key => $item) {
637
            if ($item instanceof self) {
638
                $result[$prefix . $key] = $item->appendToEachKey($prefix);
639
            } elseif (\is_array($item)) {
640
                $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
641
                    ->appendToEachKey($prefix)
642
                    ->toArray();
643
            } else {
644
                $result[$prefix . $key] = $item;
645
            }
646
        }
647
648
        return self::create($result, $this->iteratorClass, false);
649
    }
650
651
    /**
652
     * Add a prefix to each value.
@@ 2584-2600 (lines=17) @@
2581
     * @return static
2582
     *                <p>(Immutable) Return an Arrayy object, with the prepended keys.</p>
2583
     */
2584
    public function prependToEachKey($suffix): self
2585
    {
2586
        // init
2587
        $result = [];
2588
2589
        foreach ($this->getGenerator() as $key => $item) {
2590
            if ($item instanceof self) {
2591
                $result[$key] = $item->prependToEachKey($suffix);
2592
            } elseif (\is_array($item)) {
2593
                $result[$key] = self::create($item, $this->iteratorClass, false)->prependToEachKey($suffix)->toArray();
2594
            } else {
2595
                $result[$key . $suffix] = $item;
2596
            }
2597
        }
2598
2599
        return self::create($result, $this->iteratorClass, false);
2600
    }
2601
2602
    /**
2603
     * Add a suffix to each value.