Skip to content

bug: False positive when adding the Request in private constructor #2423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Crovitche-1623 opened this issue Apr 16, 2025 · 0 comments
Open

Comments

@Crovitche-1623
Copy link

Context

I have a service where autowiring is disabled:

<?php

namespace App\Foo;

use Symfony\Component\DependencyInjection\Attribute\Autoconfigure;

#[Autoconfigure(autowiring: disabled)]
class Foo
{
    // ...
}

because the services MUST not be injected automatically and the class must be instantiated manually. To do so, I decided to instantiate the class only through a static function and to use a private constructor.

Problem

When I add a Symfony\Component\HttpFoundation\Request in a private constructor, I do have the following warning :

Symfony: You probably dont want to inject a "Request" here

I think this warning should be disabled when a private constructor is used.

Workaround I found

Put the service in a folder that is excluded from autowiring in config/services.yml (this make the warning disappear but I think the PHP attribute should be processed too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant