| @@ 243-260 (lines=18) @@ | ||
| 240 | * @return string |
|
| 241 | * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not NAME |
|
| 242 | */ |
|
| 243 | public function nextName(): string |
|
| 244 | { |
|
| 245 | if ($this->peek() !== JsonToken::NAME) { |
|
| 246 | throw new UnexpectedJsonTokenException( |
|
| 247 | sprintf('Expected "%s", but found "%s"', JsonToken::NAME, $this->peek()) |
|
| 248 | ); |
|
| 249 | } |
|
| 250 | ||
| 251 | /** @var StdClassIterator $iterator */ |
|
| 252 | $iterator = $this->stack[$this->stackSize - 1]; |
|
| 253 | $key = $iterator->key(); |
|
| 254 | $value = $iterator->current(); |
|
| 255 | $iterator->next(); |
|
| 256 | ||
| 257 | $this->push($value); |
|
| 258 | ||
| 259 | return $key; |
|
| 260 | } |
|
| 261 | ||
| 262 | /** |
|
| 263 | * Returns an enum representing the type of the next token without consuming it |
|
| @@ 249-266 (lines=18) @@ | ||
| 246 | * @return string |
|
| 247 | * @throws \Tebru\Gson\Exception\UnexpectedJsonTokenException If the next token is not NAME |
|
| 248 | */ |
|
| 249 | public function nextName(): string |
|
| 250 | { |
|
| 251 | if ($this->peek() !== JsonToken::NAME) { |
|
| 252 | throw new UnexpectedJsonTokenException( |
|
| 253 | sprintf('Expected "%s", but found "%s"', JsonToken::NAME, $this->peek()) |
|
| 254 | ); |
|
| 255 | } |
|
| 256 | ||
| 257 | /** @var JsonObjectIterator $iterator */ |
|
| 258 | $iterator = $this->stack[$this->stackSize - 1]; |
|
| 259 | $key = $iterator->key(); |
|
| 260 | $value = $iterator->current(); |
|
| 261 | $iterator->next(); |
|
| 262 | ||
| 263 | $this->push($value); |
|
| 264 | ||
| 265 | return $key; |
|
| 266 | } |
|
| 267 | ||
| 268 | /** |
|
| 269 | * Returns an enum representing the type of the next token without consuming it |
|