Skip to content

Commit

Permalink
Fix issue where \Eloquent is not included when using write_mixin (bar…
Browse files Browse the repository at this point in the history
…ryvdh#1352)

* Check for exact mixin name when writing

* changelog

* add mixin to test class

Co-authored-by: Barry vd. Heuvel <barry@fruitcake.nl>
  • Loading branch information
2 people authored and d3v2a committed Feb 16, 2024
1 parent d9d5d03 commit c29165a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,10 +937,19 @@ protected function createPhpDocs($class)
$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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/**
* @property $someProp
* @method someMethod(string $method)
* @mixin IdeHelperPost
*/
class Post extends Model
{
Expand Down

0 comments on commit c29165a

Please # to comment.