Skip to content

Commit c29165a

Browse files
Jefemybarryvdh
authored andcommitted
Fix issue where \Eloquent is not included when using write_mixin (barryvdh#1352)
* Check for exact mixin name when writing * changelog * add mixin to test class Co-authored-by: Barry vd. Heuvel <[email protected]>
1 parent d9d5d03 commit c29165a

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
### Fixes
99
- Fix return type of methods provided by `SoftDeletes` [#1345 / KentarouTakeda](https://github.com/barryvdh/laravel-ide-helper/pull/1345)
1010
- Handle PHP 8.1 deprecation warnings when passing `null` to `new \ReflectionClass` [#1351 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1351)
11+
- Fix issue where \Eloquent is not included when using write_mixin [#1352 / Jefemy](https://github.com/barryvdh/laravel-ide-helper/pull/1352)
1112
- Fix model factory method arguments for Laravel >= 9 [#1361 / wimski](https://github.com/barryvdh/laravel-ide-helper/pull/1361)
1213

1314
2022-03-06, 2.12.3

src/Console/ModelsCommand.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -937,10 +937,19 @@ protected function createPhpDocs($class)
937937
$phpdoc->appendTag($tag);
938938
}
939939

940-
if ($this->write && !$phpdoc->getTagsByName('mixin')) {
940+
if ($this->write) {
941941
$eloquentClassNameInModel = $this->getClassNameInDestinationFile($reflection, 'Eloquent');
942+
943+
// remove the already existing tag to prevent duplicates
944+
foreach ($phpdoc->getTagsByName('mixin') as $tag) {
945+
if($tag->getContent() === $eloquentClassNameInModel) {
946+
$phpdoc->deleteTag($tag);
947+
}
948+
}
949+
942950
$phpdoc->appendTag(Tag::createInstance('@mixin ' . $eloquentClassNameInModel, $phpdoc));
943951
}
952+
944953
if ($this->phpstorm_noinspections) {
945954
/**
946955
* Facades, Eloquent API

tests/Console/ModelsCommand/GeneratePhpdocWithMixin/Models/Post.php

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/**
1010
* @property $someProp
1111
* @method someMethod(string $method)
12+
* @mixin IdeHelperPost
1213
*/
1314
class Post extends Model
1415
{

0 commit comments

Comments
 (0)