phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
595 stars 97 forks source link

Add support for enums on mapped object properties #246

Closed mbabker closed 2 years ago

mbabker commented 2 years ago

ORM 2.11 added support for PHP 8.1 enums (and there is an open feature request for the MongoDB ODM for a similar addition). It would be nice if PHPStan could support these at some point down the line as well. Right now, you get type mapping mismatch errors when using them:

 ------ -------------------------------------------------------------------------------------------------------------------------
  Line   Entity/Event.php
 ------ -------------------------------------------------------------------------------------------------------------------------
  xx     Property App\Entity\Event::$type type mapping mismatch: database can contain string but property expects App\EventType.
  xx     Property App\Entity\Event::$type type mapping mismatch: property can contain App\EventType but database expects string.
ondrejmirtes commented 2 years ago

Please post a piece of code that reports these errors.

mbabker commented 2 years ago

https://github.com/mbabker/phpstan-doctrine-enum has the minimal code to show this.

ondrejmirtes commented 2 years ago

Implemented: https://github.com/phpstan/phpstan-doctrine/commit/820606a0e6116c4566871e44e22949815a3e36a8

And released: https://github.com/phpstan/phpstan-doctrine/releases/tag/1.0.3

Feel free to sponsor PHPStan ;) https://github.com/sponsors/ondrejmirtes

Or get PHPStan Pro: https://phpstan.org/blog/introducing-phpstan-pro

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.