@@ 965-983 (lines=19) @@ | ||
962 | * @psalm-return static<TKey,T> |
|
963 | * @psalm-mutation-free |
|
964 | */ |
|
965 | public function appendToEachKey($prefix): self |
|
966 | { |
|
967 | // init |
|
968 | $result = []; |
|
969 | ||
970 | foreach ($this->getGenerator() as $key => $item) { |
|
971 | if ($item instanceof self) { |
|
972 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
973 | } elseif (\is_array($item) === true) { |
|
974 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
975 | ->appendToEachKey($prefix) |
|
976 | ->toArray(); |
|
977 | } else { |
|
978 | $result[$prefix . $key] = $item; |
|
979 | } |
|
980 | } |
|
981 | ||
982 | return self::create($result, $this->iteratorClass, false); |
|
983 | } |
|
984 | ||
985 | /** |
|
986 | * Add a prefix to each value. |
|
@@ 4156-4181 (lines=26) @@ | ||
4153 | * @psalm-return static<TKey,T> |
|
4154 | * @psalm-mutation-free |
|
4155 | */ |
|
4156 | public function prependToEachKey($suffix): self |
|
4157 | { |
|
4158 | // init |
|
4159 | $result = []; |
|
4160 | ||
4161 | foreach ($this->getGenerator() as $key => $item) { |
|
4162 | if ($item instanceof self) { |
|
4163 | $result[$key] = $item->prependToEachKey($suffix); |
|
4164 | } elseif (\is_array($item) === true) { |
|
4165 | $result[$key] = self::create( |
|
4166 | $item, |
|
4167 | $this->iteratorClass, |
|
4168 | false |
|
4169 | )->prependToEachKey($suffix) |
|
4170 | ->toArray(); |
|
4171 | } else { |
|
4172 | $result[$key . $suffix] = $item; |
|
4173 | } |
|
4174 | } |
|
4175 | ||
4176 | return self::create( |
|
4177 | $result, |
|
4178 | $this->iteratorClass, |
|
4179 | false |
|
4180 | ); |
|
4181 | } |
|
4182 | ||
4183 | /** |
|
4184 | * Add a suffix to each value. |