Skip to content

Invalid finding: Auto-Generated ID is never assigned int Β #610

Closed
@kevinpapst

Description

@kevinpapst

Expected:
PHPStand understands that such a definition is valid and that $id is set to int by Doctrine.

Actual:

Property HelloWorld::$id (int|null) is never assigned int so it can be removed from the property type.

    #[ORM\Column(name: 'id', type: 'integer')]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
    private ?int $id = null;

    public function __clone()
    {
        if ($this->id !== null) {
            $this->id = null;
        }
        // ...
     }
}

Only happens when I have that clone method in place, which says that id is not null 😁

Playground: https://phpstan.org/r/ed1ce389-72ab-4deb-a1bc-6d570db17f87
But in that case it makes sense, as there is no Doctrine annotation/bridge available.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions