Skip to content

Commit c8f0f91

Browse files
Jefemybarryvdh
andauthored
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 <[email protected]>
1 parent 07f5eae commit c8f0f91

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
@@ -926,10 +926,19 @@ protected function createPhpDocs($class)
926926
$phpdoc->appendTag($tag);
927927
}
928928

929-
if ($this->write && !$phpdoc->getTagsByName('mixin')) {
929+
if ($this->write) {
930930
$eloquentClassNameInModel = $this->getClassNameInDestinationFile($reflection, 'Eloquent');
931+
932+
// remove the already existing tag to prevent duplicates
933+
foreach ($phpdoc->getTagsByName('mixin') as $tag) {
934+
if($tag->getContent() === $eloquentClassNameInModel) {
935+
$phpdoc->deleteTag($tag);
936+
}
937+
}
938+
931939
$phpdoc->appendTag(Tag::createInstance('@mixin ' . $eloquentClassNameInModel, $phpdoc));
932940
}
941+
933942
if ($this->phpstorm_noinspections) {
934943
/**
935944
* 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)