Skip to content

Commit 7a9a6fd

Browse files
georgebootd3v2a
authored andcommitted
Generate cleaner model mixin classes (barryvdh#1268)
* Generate cleaner model mixin classes * Fix test
1 parent b88a75c commit 7a9a6fd

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/Console/ModelsCommand.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,13 @@ protected function createPhpDocs($class)
929929
if (!$phpdocMixin->getText()) {
930930
$mixinDocComment = preg_replace("/\s\*\s*\n/", '', $mixinDocComment);
931931
}
932+
933+
foreach ($phpdoc->getTagsByName('mixin') as $tag) {
934+
if (Str::startsWith($tag->getContent(), 'IdeHelper')) {
935+
$phpdoc->deleteTag($tag);
936+
}
937+
}
938+
$docComment = $serializer->getDocComment($phpdoc);
932939
}
933940

934941
if ($this->write) {
@@ -950,11 +957,15 @@ protected function createPhpDocs($class)
950957
}
951958

952959
$classname = $this->write_mixin ? $mixinClassName : $classname;
953-
$output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} extends \Eloquent ";
960+
$output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}class {$classname} ";
961+
962+
if (!$this->write_mixin) {
963+
$output .= "extends \Eloquent ";
954964

955-
if ($interfaceNames) {
956-
$interfaces = implode(', \\', $interfaceNames);
957-
$output .= "implements \\{$interfaces} ";
965+
if ($interfaceNames) {
966+
$interfaces = implode(', \\', $interfaceNames);
967+
$output .= "implements \\{$interfaces} ";
968+
}
958969
}
959970

960971
return $output . "{}\n}\n\n";

tests/Console/ModelsCommand/GeneratePhpdocWithMixin/__snapshots__/Test__test__1.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,6 @@ class Post extends Model
183183
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value)
184184
* @mixin \Eloquent
185185
*/
186-
class IdeHelperPost extends \Eloquent {}
186+
class IdeHelperPost {}
187187
}
188188

0 commit comments

Comments
 (0)