psalm-plugin-symfony icon indicating copy to clipboard operation
psalm-plugin-symfony copied to clipboard

False positive PrivateService issue for `doctrine` ID

Open ostrolucky opened this issue 1 year ago • 0 comments

In my case, plugin incorrectly claims doctrine service is private. After inspection, what I found is that plugin in my case analyzes these calls first

self::getContainer()->get(\Doctrine\Persistence\ManagerRegistry::class);

But because \Doctrine\Persistence\ManagerRegistry is not a service but there is an alias pointing to it, it finds that doctrine is aliased to it, retrieves doctrine definition and mutates its public flag to whatever is set on alias. This is because of https://github.com/psalm/psalm-plugin-symfony/blob/2aa596491c1ade315cb9ac14a29788e7466c8444/src/Symfony/ContainerMeta.php#L154-L167

In another words, in example such as

<service id="doctrine" class="Doctrine\Bundle\DoctrineBundle\Registry" public="true" />
<service id="Doctrine\Persistence\ManagerRegistry" alias="doctrine"/>

plugin will flip public of doctrine into false whenever Doctrine\Persistence\ManagerRegistry is fetched

ostrolucky avatar Jun 30 '23 16:06 ostrolucky