Code Duplication    Length = 18-18 lines in 2 locations

classes/ClassGenerator.php 2 locations

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