[DeadCode] Anonymous class implementing an interface doesn't respect interface signature #1367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found this while running the dead code level on a code base. I don't have a fix for it yet, but thought I'd open a PR so long with a failing test case while I investigate further (and maybe get some pointers to the right solution)
When instantiating an anonymous class that implements an interface, and the methods in the class is empty, then all the parameters in the method signature is removed. The signature that comes from the interface isn't respected. When running the test case in the PR, I get the following failure:
but I expect the test to pass, since the function
bar
matches the signature in the interface it implements.The strange thing, though, is that in the
RemoveUnusedParameterRector
class, the line$classNode = $node->getAttribute(AttributeKey::CLASS_NODE);
returns the current class node, and not the anonymous class node. So I think the issue might lie when traversing the nodes, and not with the actual rector class. I'm still digging through everything, but any nudge in the right direction would be appreciated.