From dd12b7cdcb3134d3823e4a3aacfeb661f108b462 Mon Sep 17 00:00:00 2001 From: George Boot <884482+georgeboot@users.noreply.github.com> Date: Mon, 25 Oct 2021 13:44:43 +0200 Subject: [PATCH] Generate cleaner model mixin classes (#1268) * Generate cleaner model mixin classes * Fix test --- src/Console/ModelsCommand.php | 19 +++++++++++++++---- .../__snapshots__/Test__test__1.php | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 651f37e..6873df7 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -918,6 +918,13 @@ class ModelsCommand extends Command if (!$phpdocMixin->getText()) { $mixinDocComment = preg_replace("/\s\*\s*\n/", '', $mixinDocComment); } + + foreach ($phpdoc->getTagsByName('mixin') as $tag) { + if (Str::startsWith($tag->getContent(), 'IdeHelper')) { + $phpdoc->deleteTag($tag); + } + } + $docComment = $serializer->getDocComment($phpdoc); } if ($this->write) { @@ -939,11 +946,15 @@ class ModelsCommand extends Command } $classname = $this->write_mixin ? $mixinClassName : $classname; - $output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} extends \Eloquent "; + $output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} "; - if ($interfaceNames) { - $interfaces = implode(', \\', $interfaceNames); - $output .= "implements \\{$interfaces} "; + if (!$this->write_mixin) { + $output .= "extends \Eloquent "; + + if ($interfaceNames) { + $interfaces = implode(', \\', $interfaceNames); + $output .= "implements \\{$interfaces} "; + } } return $output . "{}\n}\n\n"; diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php index 872469a..88e7eb6 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php @@ -183,6 +183,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi * @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value) * @mixin \Eloquent */ - class IdeHelperPost extends \Eloquent {} + class IdeHelperPost {} }