mirror of
https://github.com/danog/psalm-plugin-symfony.git
synced 2024-11-26 20:04:58 +01:00
prevent service subscribers overwriting already known service definitions (#194)
fixes #193
This commit is contained in:
parent
7693ae692f
commit
7d7a06209c
@ -188,9 +188,11 @@ class ContainerHandler implements AfterMethodCallAnalysisInterface, AfterClassLi
|
||||
$key = $arrayItem->key;
|
||||
$serviceId = $key instanceof String_ ? $key->value : $className;
|
||||
|
||||
$service = new Service($serviceId, $className);
|
||||
$service->setIsPublic(true);
|
||||
self::$containerMeta->add($service);
|
||||
if (null === self::$containerMeta->get($className)) {
|
||||
$service = new Service($serviceId, $className);
|
||||
$service->setIsPublic(true);
|
||||
self::$containerMeta->add($service);
|
||||
}
|
||||
|
||||
$codebase->queueClassLikeForScanning($className);
|
||||
$fileStorage->referenced_classlikes[strtolower($className)] = $className;
|
||||
|
@ -81,3 +81,41 @@ Feature: Service Subscriber
|
||||
| Type | Message |
|
||||
| Trace | $entityManager: Doctrine\ORM\EntityManagerInterface |
|
||||
And I see no other errors
|
||||
|
||||
Scenario: Asserting psalm recognizes return type of services defined in getSubscribedServices, already defined as an alias in containerXml
|
||||
Given I have the following code
|
||||
"""
|
||||
<?php
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
|
||||
class SomeController implements ServiceSubscriberInterface
|
||||
{
|
||||
private $container;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function __invoke()
|
||||
{
|
||||
/** @psalm-trace $kernel */
|
||||
$kernel = $this->container->get('http_kernel');
|
||||
}
|
||||
|
||||
public static function getSubscribedServices(): array
|
||||
{
|
||||
return [
|
||||
'http_kernel' => HttpKernelInterface::class,
|
||||
];
|
||||
}
|
||||
}
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see these errors
|
||||
| Type | Message |
|
||||
| Trace | $kernel: Symfony\Component\HttpKernel\HttpKernel |
|
||||
And I see no other errors
|
||||
|
Loading…
Reference in New Issue
Block a user