You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @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.
…toconfigure attribute (jfranclin)
This PR was merged into the 7.2 branch.
Discussion
----------
[DependencyInjection] Fix phpdoc for $configurator in Autoconfigure attribute
| Q | A
| ------------- | ---
| Branch? | 7.2
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix#59821
| License | MIT
Since SF7.1, in Autoconfigure attribute, the $configurator phpdoc seems wrong :
` * `@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.
Commits
-------
ce03562 [DependencyInjection] Fix phpdoc for $configurator in Autoconfigure attribute
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 :
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
The text was updated successfully, but these errors were encountered: