From 7549f58a30cd64ff0516b9640194bc2dbf7d5508 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 28 Oct 2024 12:21:53 +0100 Subject: [PATCH] Smarter reset (#1603) * Smarter reset * Changelog * Fix phpdocs --- CHANGELOG.md | 3 ++- src/Console/ModelsCommand.php | 12 +++++++++--- .../ResetAndSmartReset/Models/Simple.php | 6 ++++++ .../__snapshots__/Test__testNoReset__1.php | 5 +++++ .../__snapshots__/Test__testReset__1.php | 2 ++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f473a14..0d323e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ All notable changes to this project will be documented in this file. -------------- ### Changed -Add support for multiple pivot types when using the same accessor. +- Add support for multiple pivot types when using the same accessor. +- Smarter reset, keep tags that IDE helper doesn't use 2024-10-18, 3.2.0 -------------- diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index b915e03..ddf1dea 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -945,13 +945,19 @@ class ModelsCommand extends Command $reflection->getParentClass()->getInterfaceNames() ); + $phpdoc = new DocBlock($reflection, new Context($namespace)); if ($this->reset) { - $phpdoc = new DocBlock('', new Context($namespace)); $phpdoc->setText( (new DocBlock($reflection, new Context($namespace)))->getText() ); - } else { - $phpdoc = new DocBlock($reflection, new Context($namespace)); + foreach ($phpdoc->getTags() as $tag) { + if ( + in_array($tag->getName(), ['property', 'property-read', 'property-write', 'method', 'mixin']) + || ($tag->getName() === 'noinspection' && in_array($tag->getContent(), ['PhpUnnecessaryFullyQualifiedNameInspection', 'PhpFullyQualifiedNameUsageInspection'])) + ) { + $phpdoc->deleteTag($tag); + } + } } $properties = []; diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/Models/Simple.php b/tests/Console/ModelsCommand/ResetAndSmartReset/Models/Simple.php index 86646d3..86d86bf 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/Models/Simple.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/Models/Simple.php @@ -9,7 +9,13 @@ use Illuminate\Database\Eloquent\Model; /** * Text of existing phpdoc * + * @implements \ArrayAccess + * @noinspection PhpUnreachableStatementInspection + * @noinspection PhpUnnecessaryFullyQualifiedNameInspection * @property string $foo + * @property-read string $bar + * @method fooBar() + * @mixin \Eloquent */ class Simple extends Model { diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php index 21a8199..ed7be44 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php @@ -9,7 +9,12 @@ use Illuminate\Database\Eloquent\Model; /** * Text of existing phpdoc * + * @implements \ArrayAccess + * @noinspection PhpUnreachableStatementInspection + * @noinspection PhpUnnecessaryFullyQualifiedNameInspection * @property string $foo + * @property-read string $bar + * @method fooBar() * @property int $id * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php index e00f9e9..390bbf1 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php @@ -9,6 +9,8 @@ use Illuminate\Database\Eloquent\Model; /** * Text of existing phpdoc * + * @implements \ArrayAccess + * @noinspection PhpUnreachableStatementInspection * @property int $id * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery()