phpstan/phpstan-symfony

Support for DI config in PHP file format

Wirone opened this issue · 1 comments

Symfony supports PHP format for configuration (it's even default one now), so it would be great if this plugin could help with verifying DI configs. Assume we have:

class Foo
{
    public function __construct(Bar $bar, Baz $baz)
    {
    }
}
return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();

    $services->set(Foo::class)
        ->public()
        ->args([Bar::class]);
});

Plugin should warn that Baz $baz argument is missing in the Foo service definition.

Similarly it should support:

  • factories like ->factory([service(FooFactory::class), 'create'])
    • if factory's service exists
    • if factory's class has such method
  • fetching parameters (like ->args(['%foo%']))
  • named args (like ->arg('$bar', service(Bar::class))
  • expressions (using expr())

That would really help with keeping quality in DI definitions with PHP format 🙂

Nice!