Description
Symfony version(s) affected
7.1.*
Description
In https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/DependencyInjection/Attribute/Autoconfigure.php there is in my opinion an issue on the PHPDOC of $configurator which makes complaining PHPStan for example :
* @param array<class-string, string>|string|null $configurator A PHP function, reference or an array containing a class/Reference and a method to call after the service is fully initialized
The doc is asking for a class-string key and a string value. However, this is not always the case because the first parameter could be a service, like @foo
which is not a class-string. Moreover, the second parameter should not be empty.
Did I miss something ?
How to reproduce
Run a static analysis tool on a class holding an attribute autoconfigure like :
use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;
#[Autoconfigure(
lazy: true,
configurator: [
'@my_service',
'configure',
]
)]
class DummyConfigurableClient
{}
Give :
Line DummyConfigurableClient.php
13 Parameter $configurator of attribute class Symfony\Component\DependencyInjection\Attribute\Autoconfigure constructor expects array<class-string, string>|string|null, array<string, string> given.
Possible Solution
For me, the right PHPDoc should be :
@param array{non-empty-string|class-string, non-empty-string}|non-empty-string|null
Additional Context
I've opened a PR for demonstrating the fix : #59820