@@ 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. |
|
@@ 4080-4105 (lines=26) @@ | ||
4077 | * @psalm-return static<TKey,T> |
|
4078 | * @psalm-mutation-free |
|
4079 | */ |
|
4080 | public function prependToEachKey($suffix): self |
|
4081 | { |
|
4082 | // init |
|
4083 | $result = []; |
|
4084 | ||
4085 | foreach ($this->getGenerator() as $key => $item) { |
|
4086 | if ($item instanceof self) { |
|
4087 | $result[$key] = $item->prependToEachKey($suffix); |
|
4088 | } elseif (\is_array($item) === true) { |
|
4089 | $result[$key] = self::create( |
|
4090 | $item, |
|
4091 | $this->iteratorClass, |
|
4092 | false |
|
4093 | )->prependToEachKey($suffix) |
|
4094 | ->toArray(); |
|
4095 | } else { |
|
4096 | $result[$key . $suffix] = $item; |
|
4097 | } |
|
4098 | } |
|
4099 | ||
4100 | return self::create( |
|
4101 | $result, |
|
4102 | $this->iteratorClass, |
|
4103 | false |
|
4104 | ); |
|
4105 | } |
|
4106 | ||
4107 | /** |
|
4108 | * Add a suffix to each value. |