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