How to make certain magic methods not trigger "unused declaration" inspection?

PHP magic methods are quite common, and they usually trigger the "unused declaration" inspection in PHPStorm.

I saw there's an "Entry points" setting, but I'm not sure it's suited to fix those cases.

For instance, I'm using Laravel's Eloquent, and every method beginning with "scope" inside a class inheriting from Eloquent\Model is suited to a magic call.

Is it possible to do that, or should I fill a feature request?


Basically, there is a generic feature request ticket for the "Unused declaration" in Laravel reported already:

Please feel free to leave a comment with examples there.




Igor Santos Yes, it is possible to disable that inspection by using the `Entry points`.

In the PHPStorm, go to:

Settings > Editor > Inspections > PHP > Unused > Unused declaration > Entry points > CODE PATTERNS;

And add this pattern:

  • Class: \App\* (or \App\Models\*);
  • Member: scope*;

After that, all scope* methods in the specified namespace would be ignored by that inspection.

I hope it helps!



Please sign in to leave a comment.