phpstan-doctrine
phpstan-doctrine copied to clipboard
Autogenerated id column should be positive-int
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.
['unsigned' => true] does not work for all drivers (e.g. in postgres)
['unsigned' => true]does not work for all drivers (e.g. in postgres)
@janedbal how is it related to my issue?
If support would be added, it needs to be driver-aware.
Still don't understand. Is there any database that uses non-positive id?
@javaDeveloperKid database will still allow you to write your own value in the field instead of using the default generated value, which is then only constrained by the type of the field (so you can write -2 in an id field if the DB field is a signed integer type)