@@ 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 |
|
@@ 398-413 (lines=16) @@ | ||
395 | * @param string $type |
|
396 | * @return ClassGenerator |
|
397 | */ |
|
398 | public function generateArrayShift(string $name, string $type): ClassGenerator |
|
399 | { |
|
400 | $this->class |
|
401 | ->addMethod(static::camelCase('shift_' . $name)) |
|
402 | ->addComment( |
|
403 | '@return null|' . $this->getCommentTypeHint($type) |
|
404 | )->setReturnType($this->getTypeHint($type)) |
|
405 | ->setReturnNullable(true) |
|
406 | ->setBody( |
|
407 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
408 | ' return null;' . PHP_EOL . |
|
409 | '}' . PHP_EOL . |
|
410 | 'return array_shift($this->__' . $name . '__[0]);' |
|
411 | ); |
|
412 | return $this; |
|
413 | } |
|
414 | ||
415 | /** |
|
416 | * @param string $name |
|
@@ 376-391 (lines=16) @@ | ||
373 | * @param string $type |
|
374 | * @return ClassGenerator |
|
375 | */ |
|
376 | public function generateArrayPop(string $name, string $type): ClassGenerator |
|
377 | { |
|
378 | $this->class |
|
379 | ->addMethod(static::camelCase('pop_' . $name)) |
|
380 | ->addComment( |
|
381 | '@return null|' . $this->getCommentTypeHint($type) |
|
382 | )->setReturnType($this->getTypeHint($type)) |
|
383 | ->setReturnNullable(true) |
|
384 | ->setBody( |
|
385 | 'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL . |
|
386 | ' return null;' . PHP_EOL . |
|
387 | '}' . PHP_EOL . |
|
388 | 'return array_pop($this->__' . $name . '__[0]);' |
|
389 | ); |
|
390 | return $this; |
|
391 | } |
|
392 | ||
393 | /** |
|
394 | * @param string $name |