@@ 152-167 (lines=16) @@ | ||
149 | * @param string $type |
|
150 | * @return ClassGenerator |
|
151 | */ |
|
152 | public function generateGet(string $name, string $type): ClassGenerator |
|
153 | { |
|
154 | $this->class |
|
155 | ->addMethod(static::camelCase('get_' . $name)) |
|
156 | ->addComment( |
|
157 | '@return null|' . $this->getCommentTypeHint($type) |
|
158 | )->setReturnType($this->getTypeHint($type)) |
|
159 | ->setReturnNullable(true) |
|
160 | ->setBody( |
|
161 | 'if (isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
162 | ' return $this->__' . $name . '__[0];' . PHP_EOL . |
|
163 | '}' . PHP_EOL . |
|
164 | 'return $this->__' . $name . '__[1];' |
|
165 | ); |
|
166 | return $this; |
|
167 | } |
|
168 | ||
169 | /** |
|
170 | * @param string $name |
|
@@ 433-448 (lines=16) @@ | ||
430 | * @param string $type |
|
431 | * @return ClassGenerator |
|
432 | */ |
|
433 | public function generateArrayPop(string $name, string $type): ClassGenerator |
|
434 | { |
|
435 | $this->class |
|
436 | ->addMethod(static::camelCase('pop_' . $name)) |
|
437 | ->addComment( |
|
438 | '@return null|' . $this->getCommentTypeHint($type) |
|
439 | )->setReturnType($this->getTypeHint($type)) |
|
440 | ->setReturnNullable(true) |
|
441 | ->setBody( |
|
442 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
443 | ' return null;' . PHP_EOL . |
|
444 | '}' . PHP_EOL . |
|
445 | 'return array_pop($this->__' . $name . '__[0]);' |
|
446 | ); |
|
447 | return $this; |
|
448 | } |
|
449 | ||
450 | /** |
|
451 | * @param string $name |
|
@@ 455-470 (lines=16) @@ | ||
452 | * @param string $type |
|
453 | * @return ClassGenerator |
|
454 | */ |
|
455 | public function generateArrayShift(string $name, string $type): ClassGenerator |
|
456 | { |
|
457 | $this->class |
|
458 | ->addMethod(static::camelCase('shift_' . $name)) |
|
459 | ->addComment( |
|
460 | '@return null|' . $this->getCommentTypeHint($type) |
|
461 | )->setReturnType($this->getTypeHint($type)) |
|
462 | ->setReturnNullable(true) |
|
463 | ->setBody( |
|
464 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
465 | ' return null;' . PHP_EOL . |
|
466 | '}' . PHP_EOL . |
|
467 | 'return array_shift($this->__' . $name . '__[0]);' |
|
468 | ); |
|
469 | return $this; |
|
470 | } |
|
471 | ||
472 | /** |
|
473 | * @param string $name |