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

The type integration does not properly support enumType on an array-based type

Open stof opened this issue 1 year ago • 2 comments

Currently, the resolution of doctrine types considers that any field that uses enumType will have a PHP type of new ObjectType($enumType) (potentially nullable depending on the nullability of the field).

This is a wrong assumption about the way this feature works in the Doctrine ORM. The enumType feature supports 2 cases:

  • if the converted field value (based on the DBAL type of the field) is a scalar, it gets turned into an enum instance
  • if the converted field value is an array, each value of the array gets turned into an enum instance

That second case is not supported by phpstan-doctrine, reporting the wrong type. Both QueryResultTypeWalker and EntityColumnRule are impacted by that.

stof avatar Oct 18 '23 10:10 stof

This is easy to fix, the right code in EntityColumnRule will make it work.

ondrejmirtes avatar Nov 21 '23 14:11 ondrejmirtes

And yeah, you'll have to touch QueryResultTypeWalker too

ondrejmirtes avatar Nov 21 '23 14:11 ondrejmirtes