| @@ 1035-1053 (lines=19) @@ | ||
| 1032 | * @psalm-return static<TKey,T> |
|
| 1033 | * @psalm-mutation-free |
|
| 1034 | */ |
|
| 1035 | public function appendToEachKey($prefix): self |
|
| 1036 | { |
|
| 1037 | // init |
|
| 1038 | $result = []; |
|
| 1039 | ||
| 1040 | foreach ($this->getGenerator() as $key => $item) { |
|
| 1041 | if ($item instanceof self) { |
|
| 1042 | $result[$prefix . $key] = $item->appendToEachKey($prefix); |
|
| 1043 | } elseif (\is_array($item)) { |
|
| 1044 | $result[$prefix . $key] = self::create($item, $this->iteratorClass, false) |
|
| 1045 | ->appendToEachKey($prefix) |
|
| 1046 | ->toArray(); |
|
| 1047 | } else { |
|
| 1048 | $result[$prefix . $key] = $item; |
|
| 1049 | } |
|
| 1050 | } |
|
| 1051 | ||
| 1052 | return self::create($result, $this->iteratorClass, false); |
|
| 1053 | } |
|
| 1054 | ||
| 1055 | /** |
|
| 1056 | * Add a prefix to each value. |
|
| @@ 4649-4665 (lines=17) @@ | ||
| 4646 | * @psalm-return static<TKey,T> |
|
| 4647 | * @psalm-mutation-free |
|
| 4648 | */ |
|
| 4649 | public function prependToEachKey($suffix): self |
|
| 4650 | { |
|
| 4651 | // init |
|
| 4652 | $result = []; |
|
| 4653 | ||
| 4654 | foreach ($this->getGenerator() as $key => $item) { |
|
| 4655 | if ($item instanceof self) { |
|
| 4656 | $result[$key] = $item->prependToEachKey($suffix); |
|
| 4657 | } elseif (\is_array($item)) { |
|
| 4658 | $result[$key] = self::create( |
|
| 4659 | $item, |
|
| 4660 | $this->iteratorClass, |
|
| 4661 | false |
|
| 4662 | )->prependToEachKey($suffix) |
|
| 4663 | ->toArray(); |
|
| 4664 | } else { |
|
| 4665 | $result[$key . $suffix] = $item; |
|
| 4666 | } |
|
| 4667 | } |
|
| 4668 | ||