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

Wrong error report with a property that accepts a set of values

Open julienfalque opened this issue 5 years ago • 3 comments

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.

julienfalque avatar Jul 01 '20 21:07 julienfalque

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.

ondrejmirtes avatar Jul 01 '20 22:07 ondrejmirtes

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?

julienfalque avatar Jul 02 '20 06:07 julienfalque

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...

ondrejmirtes avatar Jul 02 '20 14:07 ondrejmirtes