laravel-ide-helper
laravel-ide-helper copied to clipboard
Bug: `ide-helper:models --write` breaks @SuppressWarnings(PHPMD.*) notation
When php artisan ide-helper:models --write is runned, notations like @SuppressWarnings(PHPMD.ExcessiveClassComplexity) was changed to @SuppressWarnings (PHPMD.ExcessiveClassComplexity) (check space before ().
Original model
/**
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class SomeModel extends Model
{
public function childrens()
{
return $this->hasMany(Document::class);
}
}
After ide-helper:models
/**
* App\Models\SomeModel
*
* @SuppressWarnings (PHPMD.ExcessiveClassComplexity)
* @property-read \App\Collection|\App\Models\Document[] $childrens
* @mixin \Eloquent
*/
class SomeModel extends Model
{
public function childrens()
{
return $this->hasMany(Document::class);
}
}
Diff
- * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
+ * @SuppressWarnings (PHPMD.ExcessiveClassComplexity)
I can still reproduce this :-/ I suspect the problem is within https://github.com/barryvdh/ReflectionDocBlock though I could be wrong
I think we might nee a custom tag for that.
Is there a workaround for this while a fix is implemented?
We have some problems like this, not just PHPMD. Then you can add and customize a script on your composer.json:
"scripts": {
"ide-helper-models":[
"php artisan migrate",
"php artisan ide-helper:models --write",
"find app/* -type f -print0 | xargs -0 sed -i 's/@SuppressWarnings (/@SuppressWarnings(/g'",
"find app/* -type f -print0 | xargs -0 sed -i 's/@property \\\\Illuminate\\\\Support\\\\Carbon/@property \\\\Carbon\\\\Carbon/g'",
"find app/* -type f -print0 | xargs -0 sed -i '/* @property int.null $.*_count/d'",
"find app/* -type f -print0 | xargs -0 sed -i '/* @property-read int.null $.*_count/d'",
"find app/* -type f -print0 | xargs -0 sed -i -r '/^ \\\\* @method static.*Builder\\\\|\\w+ where\\w+\\(\\$value\\)$/d'"
],
...
Feel free to add or remove lines. For example we remove all where* magic methods, _count properties and change Illuminate\Support\Carbon to Carbon\Carbon
Those changes in the composer file feel like a hack rather than a real fix.
Why do the SuppressWarning lines get changed in the first place?
I have opened an MR that should fix this issue. It is a very small change, so hopefully it can get merged and a new point release will get made :crossed_fingers:
MR has been merged, so after a version bump has been tagged, it should work without needing any workarounds. Can't believe a 4+ year old bug could be fixed with, basically, a single line change 😅
Oh, I think this issue can be closed now. The MR for https://github.com/barryvdh/ReflectionDocBlock was merged ages ago, and now https://github.com/barryvdh/laravel-ide-helper has had a new release too.