@@ 759-777 (lines=19) @@ | ||
756 | * @psalm-return static<TKey,T> |
|
757 | * @psalm-mutation-free |
|
758 | */ |
|
759 | public function appendToEachKey($prefix): self |
|
760 | { |
|
761 | // init |
|
762 | $result = []; |
|
763 | ||
764 | foreach ($this->getGenerator() as $key => $item) { |
|
765 | if ($item instanceof self) { |
|
766 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
767 | } elseif (\is_array($item) === true) { |
|
768 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
769 | ->appendToEachKey($prefix) |
|
770 | ->toArray(); |
|
771 | } else { |
|
772 | $result[$prefix . $key] = $item; |
|
773 | } |
|
774 | } |
|
775 | ||
776 | return self::create($result, $this->iteratorClass, false); |
|
777 | } |
|
778 | ||
779 | /** |
|
780 | * Add a prefix to each value. |
|
@@ 3634-3659 (lines=26) @@ | ||
3631 | * @psalm-return static<TKey,T> |
|
3632 | * @psalm-mutation-free |
|
3633 | */ |
|
3634 | public function prependToEachKey($suffix): self |
|
3635 | { |
|
3636 | // init |
|
3637 | $result = []; |
|
3638 | ||
3639 | foreach ($this->getGenerator() as $key => $item) { |
|
3640 | if ($item instanceof self) { |
|
3641 | $result[$key] = $item->prependToEachKey($suffix); |
|
3642 | } elseif (\is_array($item) === true) { |
|
3643 | $result[$key] = self::create( |
|
3644 | $item, |
|
3645 | $this->iteratorClass, |
|
3646 | false |
|
3647 | )->prependToEachKey($suffix) |
|
3648 | ->toArray(); |
|
3649 | } else { |
|
3650 | $result[$key . $suffix] = $item; |
|
3651 | } |
|
3652 | } |
|
3653 | ||
3654 | return self::create( |
|
3655 | $result, |
|
3656 | $this->iteratorClass, |
|
3657 | false |
|
3658 | ); |
|
3659 | } |
|
3660 | ||
3661 | /** |
|
3662 | * Add a suffix to each value. |