psalm
psalm copied to clipboard
DocblockTypeContradiction after first value-of<Enum> @property test
https://psalm.dev/r/d629b4ca4e
I found these snippets:
https://psalm.dev/r/d629b4ca4e
<?php
enum Foo: string {
case Bar = 'bar';
case Lee = 'lee';
};
/** @property value-of<Foo> $attr */
class Bar
{
public function __set(string $name, mixed $value) {}
public function __get(string $name): mixed { return null; }
public function doSomething(): void
{
if ($this->attr === Foo::Bar->value) {
echo 'Is Bar';
return;
}
if ($this->attr === Foo::Lee->value) {
echo 'Is Lee';
return;
}
}
}
Psalm output (using commit 16b24bd):
ERROR: DocblockTypeContradiction - 21:13 - 'lee' does not contain value-of<Foo>
ERROR: DocblockTypeContradiction - 21:13 - Docblock-defined type value-of<Foo> for $this->attr is never =string(lee)
Hope this info is useful: just noticed that replacing the second if with elseif makes the warning go away.