| @@ 954-972 (lines=19) @@ | ||
| 951 | * @psalm-return static<TKey,T> |
|
| 952 | * @psalm-mutation-free |
|
| 953 | */ |
|
| 954 | public function appendToEachKey($prefix): self |
|
| 955 | { |
|
| 956 | // init |
|
| 957 | $result = []; |
|
| 958 | ||
| 959 | foreach ($this->getGenerator() as $key => $item) { |
|
| 960 | if ($item instanceof self) { |
|
| 961 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 962 | } elseif (\is_array($item) === true) { |
|
| 963 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 964 | ->appendToEachKey($prefix) |
|
| 965 | ->toArray(); |
|
| 966 | } else { |
|
| 967 | $result[$prefix . $key] = $item; |
|
| 968 | } |
|
| 969 | } |
|
| 970 | ||
| 971 | return self::create($result, $this->iteratorClass, false); |
|
| 972 | } |
|
| 973 | ||
| 974 | /** |
|
| 975 | * Add a prefix to each value. |
|
| @@ 4077-4102 (lines=26) @@ | ||
| 4074 | * @psalm-return static<TKey,T> |
|
| 4075 | * @psalm-mutation-free |
|
| 4076 | */ |
|
| 4077 | public function prependToEachKey($suffix): self |
|
| 4078 | { |
|
| 4079 | // init |
|
| 4080 | $result = []; |
|
| 4081 | ||
| 4082 | foreach ($this->getGenerator() as $key => $item) { |
|
| 4083 | if ($item instanceof self) { |
|
| 4084 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 4085 | } elseif (\is_array($item) === true) { |
|
| 4086 | $result[$key] = self::create( |
|
| 4087 | $item, |
|
| 4088 | $this->iteratorClass, |
|
| 4089 | false |
|
| 4090 | )->prependToEachKey($suffix) |
|
| 4091 | ->toArray(); |
|
| 4092 | } else { |
|
| 4093 | $result[$key . $suffix] = $item; |
|
| 4094 | } |
|
| 4095 | } |
|
| 4096 | ||
| 4097 | return self::create( |
|
| 4098 | $result, |
|
| 4099 | $this->iteratorClass, |
|
| 4100 | false |
|
| 4101 | ); |
|
| 4102 | } |
|
| 4103 | ||
| 4104 | /** |
|
| 4105 | * Add a suffix to each value. |
|