Skip to content

False positive PrivateService issue for doctrine ID #317

@ostrolucky

Description

@ostrolucky

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

try {
$definition = $this->container->getDefinition($id);
} catch (ServiceNotFoundException $serviceNotFoundException) {
try {
$alias = $this->container->getAlias($id);
} catch (InvalidArgumentException $e) {
throw $serviceNotFoundException;
}
$definition = $this->container->getDefinition((string) $alias);
$definition->setPublic($alias->isPublic());
}
return $definition;

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions