Code Duplication    Length = 19-26 lines in 2 locations

src/Arrayy.php 2 locations

@@ 708-726 (lines=19) @@
705
     * @return static
706
     *                <p>(Immutable) Return an Arrayy object, with the prefixed keys.</p>
707
     */
708
    public function appendToEachKey($prefix): self
709
    {
710
        // init
711
        $result = [];
712
713
        foreach ($this->getGenerator() as $key => $item) {
714
            if ($item instanceof self) {
715
                $result[$prefix . $key] = $item->appendToEachKey($prefix);
716
            } elseif (\is_array($item) === true) {
717
                $result[$prefix . $key] = self::create($item, $this->iteratorClass, false)
718
                    ->appendToEachKey($prefix)
719
                    ->toArray();
720
            } else {
721
                $result[$prefix . $key] = $item;
722
            }
723
        }
724
725
        return self::create($result, $this->iteratorClass, false);
726
    }
727
728
    /**
729
     * Add a prefix to each value.
@@ 3341-3366 (lines=26) @@
3338
     * @return static
3339
     *                <p>(Immutable) Return an Arrayy object, with the prepended keys.</p>
3340
     */
3341
    public function prependToEachKey($suffix): self
3342
    {
3343
        // init
3344
        $result = [];
3345
3346
        foreach ($this->getGenerator() as $key => $item) {
3347
            if ($item instanceof self) {
3348
                $result[$key] = $item->prependToEachKey($suffix);
3349
            } elseif (\is_array($item) === true) {
3350
                $result[$key] = self::create(
3351
                    $item,
3352
                    $this->iteratorClass,
3353
                    false
3354
                )->prependToEachKey($suffix)
3355
                    ->toArray();
3356
            } else {
3357
                $result[$key . $suffix] = $item;
3358
            }
3359
        }
3360
3361
        return self::create(
3362
            $result,
3363
            $this->iteratorClass,
3364
            false
3365
        );
3366
    }
3367
3368
    /**
3369
     * Add a suffix to each value.