phpstan-symfony
phpstan-symfony copied to clipboard
Allow service subscriber to have non-service name keys under certain circumstances.
You can define service subscribers with non-service name keys, e.g.
class SubmissionStrategyFactory implements ServiceSubscriberInterface
{
public function __construct(private readonly ContainerInterface $locator)
{
}
public function getStrategy(IllustrationSubmission $submission): SubmissionStrategyInterface
{
if ($submission->getIllustrationFile()) {
return $this->locator->get('upload');
}
return $this->locator->get('url');
}
public static function getSubscribedServices(): iterable
{
yield 'upload' => UploadStrategy::class;
yield 'url' => UrlStrategy::class;
}
}
phpstan currently reports this as Service "upload" is not registered in the container.
This PR allows non-service argument names when the argument is a container and its called within a ServiceLocator.
Maybe, this is also related to #89
As is, this won't solve #89. For that, you would have to do the same detection of ServiceSubscriberInterface in the ContainerInterfacePrivateServiceRule.