Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] Bad phpdoc for $configurator in class Autoconfigure #59821

Copy link
Copy link
Closed
@jfranclin

Description

@jfranclin
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.