phpstan-doctrine
phpstan-doctrine copied to clipboard
Array of enums not supported
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.
I have the same problem
Same problem here on doctrine/orm 2.14.1
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.
------ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------