psalm-plugin-doctrine icon indicating copy to clipboard operation
psalm-plugin-doctrine copied to clipboard

Doctrine's array of enums not supported

Open ThomasLandauer opened this issue 1 year ago • 0 comments

doctrine/orm 2.12.0 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 = [];

With the setter/getter set up like this:

/**
 * @return array<int,Foo>
 */
public function getFoo(): array
{
    return $this->foo;
}

/**
 * @param array<int,Foo> $foo
 */
public function setFoo(array $foo): self
{
    $this->foo = $foo;
    return $this;
}

... psalm is reporting:

ERROR: MixedReturnTypeCoercion - The declared return type 'array<int, Foo>' for Entity::getFoo is more specific than the inferred return type 'array<array-key, mixed>' (see https://psalm.dev/197)
     * @return array<int, Foo>


ERROR: MixedReturnTypeCoercion - The type 'array<array-key, mixed>' is more general than the declared return type 'array<int, Foo>' for Entity::getFoo (see https://psalm.dev/197)
        return $this->foo;

ThomasLandauer avatar Dec 13 '23 14:12 ThomasLandauer