phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
581 stars 96 forks source link

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

Open julienfalque opened 4 years ago

julienfalque commented 4 years ago

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.
ondrejmirtes commented 4 years ago

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.

julienfalque commented 4 years ago

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?

ondrejmirtes commented 4 years ago

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