-
-
Notifications
You must be signed in to change notification settings - Fork 82
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
DrupalKernel
registers 3 synthetic services and instantly hardcodes aliases for two of them.
mglaman\PHPStanDrupal\Drupal\DrupalAutoloader::register()
only provides information about services defined in the *.services.yml
file, so those two services aren't detected.
This simple example triggers a problem:
<?php
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Foo implements ContainerInjectionInterface {
public function __construct(
private ContainerInterface $container,
) {}
public static function create(ContainerInterface $container): self {
return new self(
$container->get(ContainerInterface::class),
);
}
}
produces on PHPStan level 7:
14 Parameter #1 $container of class Foo constructor expects Symfony\Component\DependencyInjection\ContainerInterface, object given.
🪪 argument.type
If create is replaced by:
return new self(
$container,
);
there is no error.
This is a kind of edge case scenario, but it raises a question: should this package handle it in some way? Considering that the services are not detected, this means that anything that is registered or changed by a service provider or compiler pass will not be detected. Perhaps it would be possible to improve things in general, rather than just this specific case?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request