Skip to content

False positive warning for valid relation injection #2421

Open
@Grzyb9k

Description

@Grzyb9k

Hi,
I'm encountering a false positive warning in PHPStorm when using a standard Symfony Doctrine relation in an entity constructor.
The plugin displays:

Symfony: You probably don't want to inject a "AdvertiserReportMappingProcess" here

This happens even though the injection is fully valid and recommended in Symfony's documentation.
Here's a simplified snippet:

public function __construct(
    #[ORM\ManyToOne(targetEntity: AdvertiserReportMappingProcess::class)]
    #[ORM\JoinColumn(name: 'mapping_process_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
    private AdvertiserReportMappingProcess $mappingProcess,
    // other arguments...
) {}

The target class is another Doctrine entity. It is a ManyToOne relation, but the same is true for any other relationship.
No warning should be shown in this context.

Symfony Support 2024.1.276
PHPStorm 2024.3.5
Symfony 7.2.4
PHP 8.3

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