| @@ 310-327 (lines=18) @@ | ||
| 307 | * @param string $type |
|
| 308 | * @return ClassGenerator |
|
| 309 | */ |
|
| 310 | public function generateListPush(string $name, string $type): ClassGenerator |
|
| 311 | { |
|
| 312 | $this->class |
|
| 313 | ->addMethod(static::camelCase('push_' . $name)) |
|
| 314 | ->addComment( |
|
| 315 | '@param ' . $this->getCommentTypeHint($type) . ' $value' . PHP_EOL . |
|
| 316 | '@return ' . $this->class->getName() |
|
| 317 | )->setReturnType($this->getCanonicalClassName()) |
|
| 318 | ->setBody( |
|
| 319 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
| 320 | ' $this->__' . $name . '__[0] = [];' . PHP_EOL . |
|
| 321 | '}' . PHP_EOL . |
|
| 322 | 'array_push($this->__' . $name . '__[0], $value);' . PHP_EOL . |
|
| 323 | 'return $this;' |
|
| 324 | )->addParameter('value') |
|
| 325 | ->setTypeHint($this->getTypeHint($type)); |
|
| 326 | return $this; |
|
| 327 | } |
|
| 328 | ||
| 329 | /** |
|
| 330 | * @param string $name |
|
| @@ 334-351 (lines=18) @@ | ||
| 331 | * @param string $type |
|
| 332 | * @return ClassGenerator |
|
| 333 | */ |
|
| 334 | public function generateListUnshift(string $name, string $type): ClassGenerator |
|
| 335 | { |
|
| 336 | $this->class |
|
| 337 | ->addMethod(static::camelCase('unshift_' . $name)) |
|
| 338 | ->addComment( |
|
| 339 | '@param ' . $this->getCommentTypeHint($type) . ' $value' . PHP_EOL . |
|
| 340 | '@return ' . $this->class->getName() |
|
| 341 | )->setReturnType($this->getCanonicalClassName()) |
|
| 342 | ->setBody( |
|
| 343 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
| 344 | ' $this->__' . $name . '__[0] = [];' . PHP_EOL . |
|
| 345 | '}' . PHP_EOL . |
|
| 346 | 'array_unshift($this->__' . $name . '__[0], $value);' . PHP_EOL . |
|
| 347 | 'return $this;' |
|
| 348 | )->addParameter('value') |
|
| 349 | ->setTypeHint($this->getTypeHint($type)); |
|
| 350 | return $this; |
|
| 351 | } |
|
| 352 | ||
| 353 | /** |
|
| 354 | * @param string $name |
|