phpstan / phpstan-doctrine

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

Array of enums as Json array not supported #628

Open maximecolin opened 2 weeks ago

maximecolin commented 2 weeks ago

With Doctrine, we can define an array of enum as a json array column using Types::JSON with enumType option.

/** @var Foobar[] $foobars */
#[ORM\Column(type: Types::JSON, enumType: Foobar::class, options: ['default' => '[]'])]
private array $foobars = [];

This result in the following phpstan error:

Property App\Entity\User::$foobars type mapping mismatch: backing type string of enum App\Enums\Foobar does not match value type mixed of the database type array|bool|float|int|JsonSerializable|stdClass|string|null.
🪪 doctrine.enumType

If I switch to Types::SIMPLE_ARRAY, no error anymore.

I guess the rule does not handle json array yet.