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

Array of enums not supported

Open ThomasLandauer opened this issue 2 years ago • 5 comments

doctrine/orm 2.12.0 now supports arrays of enums, see https://github.com/doctrine/orm/pull/9497

This is the syntax:

#[ORM\Column(type: Types::SIMPLE_ARRAY, length: 255, nullable: true, enumType: Foo::class)]
private array $foo = [];

phpstan is reporting:

Property App\Entity\User::$foo type mapping mismatch: backing type string of enum App\Enum\Foo does not match database type array. Property App\Entity\User::$foo type mapping mismatch: database can contain App\Enum\Foo|null but property expects array. Property App\Entity\User::$foo type mapping mismatch: property can contain array but database expects App\Enum\Foo|null.

ThomasLandauer avatar Apr 20 '22 16:04 ThomasLandauer

I have the same problem

seb-jean avatar Sep 21 '22 08:09 seb-jean

Same problem here on doctrine/orm 2.14.1

jeffreymoelands avatar Mar 07 '23 10:03 jeffreymoelands

It also applies to other types:

/**
 * @var ViewSettingsEnum[]
 */
#[ORM\Column(type: 'json', nullable: true, enumType: ViewSettingsEnum::class)]
private ?array $viewSettings = null;

results in

 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   src/Entity/Employee.php                                                                                                                                                                                            
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  96     Property App\Entity\Employee::$viewSettings type mapping mismatch: backing type string of enum App\Enum\ViewSettingsEnum does not match database type array|bool|float|int|JsonSerializable|stdClass|string|null.  
  96     Property App\Entity\Employee::$viewSettings type mapping mismatch: database can contain App\Enum\ViewSettingsEnum|null but property expects array<App\Enum\ViewSettingsEnum>|null.                                 
  96     Property App\Entity\Employee::$viewSettings type mapping mismatch: property can contain array<App\Enum\ViewSettingsEnum>|null but database expects App\Enum\ViewSettingsEnum|null.                                 
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 

janklan avatar Sep 24 '23 22:09 janklan