How to cure the error "remove unused element"

The screenshot below shows that the funcB method is used, but the analyzer does not notice this. How to fix this without disabling the inspection?

 

2
4 comments
Avatar
Permanently deleted user

I originally came here to ask the same thing, but then realized: what this message indicates is that I haven't written any tests for this function, which is actually useful information. However, even if I do that, the test classes and methods still get flagged as unused (using Drupal's simpletest module), and I would like to suppress that message.

0

If you like, you may suppress the message with the same context menu as we see on your screenshot:

1
Avatar
Permanently deleted user

I know it's possible to do that, but doing it for every test class and method (or file) is rather annoying. I was hoping "Assume test declarations as entry points" would work, but it made no difference. Alternatively, the "Code patterns" could maybe be used to tell PhpStorm which of my functions are callback handlers, but the dialog behind that button is oblique, and I cannot figure out how to add anything to it.

 

0

No, unfortunately, there's no way of fixing it. The Unused Declaration inspection is only working up to its limits.

Your example is a bit oversimplified. We could theoretically search for a string variable if it's a method call and make a reference letting the inspection know what method is being used, but how often do you actually use string variables that are not returned by functions/methods?

And there's no way PhpStorm can know what a function/method returns without executing the code.

0

Please sign in to leave a comment.