Method parameter amount inspector doesn't work on anonymous class

I have a method return an anonymous class, but PHPStorm keeps highlighting it with the message "Method call is provided 1 parameters, but the method signature uses 0 parameters."

The constructor of the anonymous class expects one parameter but PHPStorm seems to take the definition of the attribute (that is passed as a parameter) as the method definition.



I'm running:
PhpStorm 2020.3.2
Build #PS-203.7148.74, built on January 27, 2021
Licensed to ----me----
Subscription is active ----some-future-date----.
Runtime version: 11.0.9.1+11-b1145.77 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 16
Registry: run.processes.with.pty=TRUE
Non-Bundled Plugins: com.dubreuia, Statistic, com.alayouni.ansiHighlight, mobi.hsz.idea.gitignore

Edit:
I forgot to mention, that this highlight also does not have any tooltip actions so it isn't even suppressable. Also copying the appropriate suppress comment (@noinspection PhpMethodParametersCountMismatchInspection) doesn't work. The only way to get rid of this wrong highlight is by suppressing the inspector for the whole file.

0
6 comments

Could you please share a code sample that reproduces this? Tried reproducing this using some generic code but without success:

0
Avatar
Permanently deleted user

Thank you for your reply. Here's a sample:

0

Thanks, reproduced! Reported as https://youtrack.jetbrains.com/issue/WI-58882 - feel free to vote for or comment it in order to get notified about its updates.

As for suppression problem - that's a known bug: https://youtrack.jetbrains.com/issue/WI-55305.

0
Avatar
Permanently deleted user

Hello, it turns out, I'm an idiot and defined the constructor wrong.

//correct
function __construct(){}
//incorrect
function __constructor(){}

My application didn't throw any errors so I didn't notice but of course PHPStorm didn't take the wrong definition for a class constructor.

Once I corrected my mistake, the wrong inspector warning went away.

I'm sorry for having wasted your time here, but still want to say thank you for your replies.

Is there maybe a way to have PHPStorm warn me that "__constructor" is probably not what I was looking for? The inspector warning should have given it away, but given it cites the attribute definition as constructor definition I was very confused.

0

Thanks for the follow up! 

There's unfortunately no inspection/warning for the construct-constructor wording as far as I can see. 

0

Upd: we've created a corresponding feature request:https://youtrack.jetbrains.com/issue/WI-58941

0

Please sign in to leave a comment.