laravel-ide-helper icon indicating copy to clipboard operation
laravel-ide-helper copied to clipboard

Bug: `ide-helper:models --write` breaks @SuppressWarnings(PHPMD.*) notation

Open pablorsk opened this issue 7 years ago • 5 comments

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)

pablorsk avatar May 24 '18 18:05 pablorsk

I can still reproduce this :-/ I suspect the problem is within https://github.com/barryvdh/ReflectionDocBlock though I could be wrong

mfn avatar Jun 26 '20 22:06 mfn

I think we might nee a custom tag for that.

barryvdh avatar Jun 27 '20 10:06 barryvdh

Is there a workaround for this while a fix is implemented?

EspadaV8 avatar Sep 15 '21 03:09 EspadaV8

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

pablorsk avatar Sep 27 '21 13:09 pablorsk

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?

EspadaV8 avatar Sep 27 '21 14:09 EspadaV8

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:

EspadaV8 avatar Nov 03 '22 10:11 EspadaV8

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 😅

EspadaV8 avatar Nov 25 '22 13:11 EspadaV8

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.

EspadaV8 avatar Feb 08 '24 00:02 EspadaV8