| @@ 361-376 (lines=16) @@ | ||
| 358 | * @param string $type |
|
| 359 | * @return ClassGenerator |
|
| 360 | */ |
|
| 361 | public function generateArrayPop(string $name, string $type): ClassGenerator |
|
| 362 | { |
|
| 363 | $this->class |
|
| 364 | ->addMethod(static::camelCase('pop_' . $name)) |
|
| 365 | ->addComment( |
|
| 366 | '@return null|' . $this->getCommentTypeHint($type) |
|
| 367 | )->setReturnType($this->getTypeHint($type)) |
|
| 368 | ->setReturnNullable(true) |
|
| 369 | ->setBody( |
|
| 370 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
| 371 | ' return null;' . PHP_EOL . |
|
| 372 | '}' . PHP_EOL . |
|
| 373 | 'return array_pop($this->__' . $name . '__[0]);' |
|
| 374 | ); |
|
| 375 | return $this; |
|
| 376 | } |
|
| 377 | ||
| 378 | /** |
|
| 379 | * @param string $name |
|
| @@ 383-398 (lines=16) @@ | ||
| 380 | * @param string $type |
|
| 381 | * @return ClassGenerator |
|
| 382 | */ |
|
| 383 | public function generateArrayShift(string $name, string $type): ClassGenerator |
|
| 384 | { |
|
| 385 | $this->class |
|
| 386 | ->addMethod(static::camelCase('shift_' . $name)) |
|
| 387 | ->addComment( |
|
| 388 | '@return null|' . $this->getCommentTypeHint($type) |
|
| 389 | )->setReturnType($this->getTypeHint($type)) |
|
| 390 | ->setReturnNullable(true) |
|
| 391 | ->setBody( |
|
| 392 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
| 393 | ' return null;' . PHP_EOL . |
|
| 394 | '}' . PHP_EOL . |
|
| 395 | 'return array_shift($this->__' . $name . '__[0]);' |
|
| 396 | ); |
|
| 397 | return $this; |
|
| 398 | } |
|
| 399 | ||
| 400 | /** |
|
| 401 | * @param string $name |
|