| @@ 957-975 (lines=19) @@ | ||
| 954 | * @psalm-return static<TKey,T> |
|
| 955 | * @psalm-mutation-free |
|
| 956 | */ |
|
| 957 | public function appendToEachKey($prefix): self |
|
| 958 | { |
|
| 959 | // init |
|
| 960 | $result = []; |
|
| 961 | ||
| 962 | foreach ($this->getGenerator() as $key => $item) { |
|
| 963 | if ($item instanceof self) { |
|
| 964 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 965 | } elseif (\is_array($item) === true) { |
|
| 966 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 967 | ->appendToEachKey($prefix) |
|
| 968 | ->toArray(); |
|
| 969 | } else { |
|
| 970 | $result[$prefix . $key] = $item; |
|
| 971 | } |
|
| 972 | } |
|
| 973 | ||
| 974 | return self::create($result, $this->iteratorClass, false); |
|
| 975 | } |
|
| 976 | ||
| 977 | /** |
|
| 978 | * Add a prefix to each value. |
|
| @@ 4146-4171 (lines=26) @@ | ||
| 4143 | * @psalm-return static<TKey,T> |
|
| 4144 | * @psalm-mutation-free |
|
| 4145 | */ |
|
| 4146 | public function prependToEachKey($suffix): self |
|
| 4147 | { |
|
| 4148 | // init |
|
| 4149 | $result = []; |
|
| 4150 | ||
| 4151 | foreach ($this->getGenerator() as $key => $item) { |
|
| 4152 | if ($item instanceof self) { |
|
| 4153 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 4154 | } elseif (\is_array($item) === true) { |
|
| 4155 | $result[$key] = self::create( |
|
| 4156 | $item, |
|
| 4157 | $this->iteratorClass, |
|
| 4158 | false |
|
| 4159 | )->prependToEachKey($suffix) |
|
| 4160 | ->toArray(); |
|
| 4161 | } else { |
|
| 4162 | $result[$key . $suffix] = $item; |
|
| 4163 | } |
|
| 4164 | } |
|
| 4165 | ||
| 4166 | return self::create( |
|
| 4167 | $result, |
|
| 4168 | $this->iteratorClass, |
|
| 4169 | false |
|
| 4170 | ); |
|
| 4171 | } |
|
| 4172 | ||
| 4173 | /** |
|
| 4174 | * Add a suffix to each value. |
|