From c8f0f914e35b167308394494cab1bc8cb0a5ef8e Mon Sep 17 00:00:00 2001 From: Jefemy Date: Thu, 11 Aug 2022 06:39:26 -0400 Subject: [PATCH] Fix issue where \Eloquent is not included when using write_mixin (#1352) * Check for exact mixin name when writing * changelog * add mixin to test class Co-authored-by: Barry vd. Heuvel --- CHANGELOG.md | 1 + src/Console/ModelsCommand.php | 11 ++++++++++- .../GeneratePhpdocWithMixin/Models/Post.php | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b65ebc9..f2f1ad9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. ### Fixes - Fix return type of methods provided by `SoftDeletes` [#1345 / KentarouTakeda](https://github.com/barryvdh/laravel-ide-helper/pull/1345) - Handle PHP 8.1 deprecation warnings when passing `null` to `new \ReflectionClass` [#1351 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1351) +- Fix issue where \Eloquent is not included when using write_mixin [#1352 / Jefemy](https://github.com/barryvdh/laravel-ide-helper/pull/1352) - Fix model factory method arguments for Laravel >= 9 [#1361 / wimski](https://github.com/barryvdh/laravel-ide-helper/pull/1361) 2022-03-06, 2.12.3 diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 3d38806..563b045 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -926,10 +926,19 @@ class ModelsCommand extends Command $phpdoc->appendTag($tag); } - if ($this->write && !$phpdoc->getTagsByName('mixin')) { + if ($this->write) { $eloquentClassNameInModel = $this->getClassNameInDestinationFile($reflection, 'Eloquent'); + + // remove the already existing tag to prevent duplicates + foreach ($phpdoc->getTagsByName('mixin') as $tag) { + if($tag->getContent() === $eloquentClassNameInModel) { + $phpdoc->deleteTag($tag); + } + } + $phpdoc->appendTag(Tag::createInstance('@mixin ' . $eloquentClassNameInModel, $phpdoc)); } + if ($this->phpstorm_noinspections) { /** * Facades, Eloquent API diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/Models/Post.php b/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/Models/Post.php index 24d6981..1317c4d 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/Models/Post.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/Models/Post.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model; /** * @property $someProp * @method someMethod(string $method) + * @mixin IdeHelperPost */ class Post extends Model {