phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
565 stars 93 forks source link

Autogenerated id column should be positive-int #567

Open javaDeveloperKid opened 1 month ago

javaDeveloperKid commented 1 month ago

I want to mark a Doctrine entity $id field that is autogenerated by database engine as @var positive-int. However PHPStan complains.

class Entity
{
    /**
     * @var positive-int|null
     */
    #[ORM\Column(type: 'integer', options: ['unsigned' => true])]
    #[ORM\Id]
    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
    private ?int $id;
}

PHPStan output: Property App\Rma\Domain\Rma\Rma::$id type mapping mismatch: database can contain int but property expects int<1, max>|null.

janedbal commented 1 month ago

['unsigned' => true] does not work for all drivers (e.g. in postgres)

javaDeveloperKid commented 1 month ago

['unsigned' => true] does not work for all drivers (e.g. in postgres)

@janedbal how is it related to my issue?

janedbal commented 1 month ago

If support would be added, it needs to be driver-aware.

javaDeveloperKid commented 1 month ago

Still don't understand. Is there any database that uses non-positive id?