phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
573 stars 95 forks source link

Array of enums not supported #320

Open ThomasLandauer opened 2 years ago

ThomasLandauer commented 2 years ago

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.

seb-jean commented 1 year ago

I have the same problem

jeffreymoelands commented 1 year ago

Same problem here on doctrine/orm 2.14.1

janklan commented 9 months ago

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.                                 
 ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
amalricBzh commented 2 months ago

Still present with doctrine/orm 3.1.3

ServerExe commented 3 weeks ago

Still present on doctrine/orm 3.2.0

psprokofiev commented 4 days ago

Still present...

"doctrine/orm": "3.2.1",
"phpstan/phpstan": "1.11.17",
"phpstan/phpstan-doctrine": "1.4.5",