phpstan-doctrine
phpstan-doctrine copied to clipboard
Wrong error report with a property that accepts a set of values
With the property:
class Foo {
/**
* @var 1|2|3
*
* @ORM\Column(type="smallint", options={"unsigned": true})
*/
private $foo;
}
The following error is reported:
Property Foo::$foo type mapping mismatch: database can contain int but property expects int.
Yeah, the message needs to be fixed but what's PHPStan telling you is that when you manually enter 4 into the database, your model is broken.
True, but I don't see a more suitable native Doctrine DBAL type for this example. Would a custom type mapping to e.g. ENUM be supported?
Yes, would be better to have a custom Doctrine type with the correct return typehints for convertToPHPValue/convertToDatabaseValue. It's a matter of custom DoctrineTypeDescriptor on what phpstan-doctrine thinks about your types...