| @@ 339-356 (lines=18) @@ | ||
| 336 | * @param string $type |
|
| 337 | * @return ClassGenerator |
|
| 338 | */ |
|
| 339 | public function generateArrayPush(string $name, string $type): ClassGenerator |
|
| 340 | { |
|
| 341 | $this->class |
|
| 342 | ->addMethod(static::camelCase('push_' . $name)) |
|
| 343 | ->addComment( |
|
| 344 | '@param ' . $this->getCommentTypeHint($type) . ' $value' . PHP_EOL . |
|
| 345 | '@return ' . $this->class->getName() |
|
| 346 | )->setReturnType($this->getCanonicalClassName()) |
|
| 347 | ->setBody( |
|
| 348 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
| 349 | ' $this->__' . $name . '__[0] = [];' . PHP_EOL . |
|
| 350 | '}' . PHP_EOL . |
|
| 351 | 'array_push($this->__' . $name . '__[0], $value);' . PHP_EOL . |
|
| 352 | 'return $this;' |
|
| 353 | )->addParameter('value') |
|
| 354 | ->setTypeHint($this->getTypeHint($type)); |
|
| 355 | return $this; |
|
| 356 | } |
|
| 357 | ||
| 358 | /** |
|
| 359 | * @param string $name |
|
| @@ 363-380 (lines=18) @@ | ||
| 360 | * @param string $type |
|
| 361 | * @return ClassGenerator |
|
| 362 | */ |
|
| 363 | public function generateArrayUnshift(string $name, string $type): ClassGenerator |
|
| 364 | { |
|
| 365 | $this->class |
|
| 366 | ->addMethod(static::camelCase('unshift_' . $name)) |
|
| 367 | ->addComment( |
|
| 368 | '@param ' . $this->getCommentTypeHint($type) . ' $value' . PHP_EOL . |
|
| 369 | '@return ' . $this->class->getName() |
|
| 370 | )->setReturnType($this->getCanonicalClassName()) |
|
| 371 | ->setBody( |
|
| 372 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
| 373 | ' $this->__' . $name . '__[0] = [];' . PHP_EOL . |
|
| 374 | '}' . PHP_EOL . |
|
| 375 | 'array_unshift($this->__' . $name . '__[0], $value);' . PHP_EOL . |
|
| 376 | 'return $this;' |
|
| 377 | )->addParameter('value') |
|
| 378 | ->setTypeHint($this->getTypeHint($type)); |
|
| 379 | return $this; |
|
| 380 | } |
|
| 381 | ||
| 382 | /** |
|
| 383 | * @param string $name |
|