phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

Invalid finding: Auto-Generated ID is never assigned int

Open kevinpapst opened this issue 1 year ago • 0 comments

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.

kevinpapst avatar Sep 17 '24 14:09 kevinpapst