| @@ 1035-1053 (lines=19) @@ | ||
| 1032 | * @psalm-return static<TKey,T> |
|
| 1033 | * @psalm-mutation-free |
|
| 1034 | */ |
|
| 1035 | public function appendToEachKey($prefix): self |
|
| 1036 | { |
|
| 1037 | // init |
|
| 1038 | $result = []; |
|
| 1039 | ||
| 1040 | foreach ($this->getGenerator() as $key => $item) { |
|
| 1041 | if ($item instanceof self) { |
|
| 1042 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 1043 | } elseif (\is_array($item)) { |
|
| 1044 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 1045 | ->appendToEachKey($prefix) |
|
| 1046 | ->toArray(); |
|
| 1047 | } else { |
|
| 1048 | $result[$prefix . $key] = $item; |
|
| 1049 | } |
|
| 1050 | } |
|
| 1051 | ||
| 1052 | return self::create($result, $this->iteratorClass, false); |
|
| 1053 | } |
|
| 1054 | ||
| 1055 | /** |
|
| 1056 | * Add a prefix to each value. |
|
| @@ 4770-4786 (lines=17) @@ | ||
| 4767 | * @psalm-return static<TKey,T> |
|
| 4768 | * @psalm-mutation-free |
|
| 4769 | */ |
|
| 4770 | public function prependToEachKey($suffix): self |
|
| 4771 | { |
|
| 4772 | // init |
|
| 4773 | $result = []; |
|
| 4774 | ||
| 4775 | foreach ($this->getGenerator() as $key => $item) { |
|
| 4776 | if ($item instanceof self) { |
|
| 4777 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 4778 | } elseif (\is_array($item)) { |
|
| 4779 | $result[$key] = self::create( |
|
| 4780 | $item, |
|
| 4781 | $this->iteratorClass, |
|
| 4782 | false |
|
| 4783 | )->prependToEachKey($suffix) |
|
| 4784 | ->toArray(); |
|
| 4785 | } else { |
|
| 4786 | $result[$key . $suffix] = $item; |
|
| 4787 | } |
|
| 4788 | } |
|
| 4789 | ||