@@ 1028-1046 (lines=19) @@ | ||
1025 | * @psalm-return static<TKey,T> |
|
1026 | * @psalm-mutation-free |
|
1027 | */ |
|
1028 | public function appendToEachKey($prefix): self |
|
1029 | { |
|
1030 | // init |
|
1031 | $result = []; |
|
1032 | ||
1033 | foreach ($this->getGenerator() as $key => $item) { |
|
1034 | if ($item instanceof self) { |
|
1035 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
1036 | } elseif (\is_array($item)) { |
|
1037 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
1038 | ->appendToEachKey($prefix) |
|
1039 | ->toArray(); |
|
1040 | } else { |
|
1041 | $result[$prefix . $key] = $item; |
|
1042 | } |
|
1043 | } |
|
1044 | ||
1045 | return self::create($result, $this->iteratorClass, false); |
|
1046 | } |
|
1047 | ||
1048 | /** |
|
1049 | * Add a prefix to each value. |
|
@@ 4801-4817 (lines=17) @@ | ||
4798 | * @psalm-return static<TKey,T> |
|
4799 | * @psalm-mutation-free |
|
4800 | */ |
|
4801 | public function prependToEachKey($suffix): self |
|
4802 | { |
|
4803 | // init |
|
4804 | $result = []; |
|
4805 | ||
4806 | foreach ($this->getGenerator() as $key => $item) { |
|
4807 | if ($item instanceof self) { |
|
4808 | $result[$key] = $item->prependToEachKey($suffix); |
|
4809 | } elseif (\is_array($item)) { |
|
4810 | $result[$key] = self::create( |
|
4811 | $item, |
|
4812 | $this->iteratorClass, |
|
4813 | false |
|
4814 | )->prependToEachKey($suffix) |
|
4815 | ->toArray(); |
|
4816 | } else { |
|
4817 | $result[$key . $suffix] = $item; |
|
4818 | } |
|
4819 | } |
|
4820 |