Skip to content

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

Open
@Crovitche-1623

Description

@Crovitche-1623

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions