psalm / psalm-plugin-symfony

Psalm Plugin for Symfony
MIT License
228 stars 53 forks source link

PossiblyUnusedMethod __construct for dependency injected classes #291

Closed OwnerOfThisIsle closed 1 year ago

OwnerOfThisIsle commented 1 year ago

I have a symfony project and just started to use psalm and this plugin. I activated findUnusedCode="true" and now have dozens of false posives, like

ERROR: PossiblyUnusedMethod - src/Service/DataService/MedicationBuilder.php:18:21 - Cannot find any calls to method App\Service\DataService\MedicationBuilder::__construct (see https://psalm.dev/087)
    public function __construct(

is this something this plugin should handle?

seferov commented 1 year ago

@OwnerOfThisIsle thanks for the report! Yes, plugin handles such errors if you configured containerXml. Please see https://github.com/psalm/psalm-plugin-symfony#configuration Feel free to reopen the issue with more details if you still have the error.

OwnerOfThisIsle commented 1 year ago

I was not clear about this: I am already using the psalm-plugin-symfony and followed the configuration instructions. I think it is partly working because without the plugin config psalm reports some additional errors (PropertyNotSetInConstructor, PossiblyInvalidArgument, UndefinedDocblockClass), but still with the plugin and that configuration:

<plugins>
      <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin">
          <containerXml>var/cache/dev/App_KernelDevDebugContainer.xml</containerXml>
          <containerXml>var/cache/test/App_KernelTestDebugContainer.xml</containerXml>
      </pluginClass>
</plugins>

there are plenty PossiblyUnusedMethod Errors (as mentioned in more detail in the question above). They are dependency injected classes, so there is no call to their constructor.