Skip to content
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

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

Open
kevinpapst opened this issue Sep 17, 2024 · 0 comments
Open

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

kevinpapst opened this issue Sep 17, 2024 · 0 comments

Comments

@kevinpapst
Copy link
Contributor

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 kevinpapst changed the title Auto-Generated ID treated as: is never assigned int Invalid finding: Auto-Generated ID is never assigned int Sep 17, 2024
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