Open jacekkarczmarczyk opened 1 year ago
Hey @jacekkarczmarczyk, can you reproduce the issue on https://psalm.dev ?
I found these snippets:
You can use regular expressions in referencedMethod
element. Either of the following should work:
<issueHandlers>
<PossiblyUnusedMethod>
<errorLevel type="suppress">
<referencedMethod name="*::__construct" />
<referencedMethod name="/.*::__construct/" />
<errorLevel>
</PossiblyUnusedMethod>
</issueHandlers>
Does @psalm-api
work only for classes? Maybe we could use it for methods/functions, too...
Does @psalm-api work only for classes?
Since 5.8.0 it's processed on methods as well.
Since there can be only one constructor in PHP - can't we just assume that if there is a (not unused) code that is using Dependency
class then the constructor must have been called somehow?
Actually UnusedConstructor
already exists: https://psalm.dev/docs/running_psalm/issues/UnusedConstructor/
We may consider emitting it instead of *UnusedMethod
for non-private constructors as well
Hi there,
I'd like to request support for the UnusedConstructor issue in Psalm. Currently, Psalm does not check for unused constructors in PHP classes.
The issue arises when constructors are created indirectly through dependency injection containers. In such cases, Psalm is not able to detect the usage of the constructor and marks it as unused, even though it is being used.
Here's a sample code snippet that illustrates the issue:
In this example, Psalm will report that the Example constructor is unused, even though it is being called indirectly through the container.
I think it would be useful to have support for the UnusedConstructor issue in Psalm to avoid false positives in such scenarios.