vimeo / psalm

A static analysis tool for finding errors in PHP applications
https://psalm.dev
MIT License
5.55k stars 660 forks source link

key-of<properties-of<>> miss templates support. #10831

Open hlib-kuznetsov opened 7 months ago

hlib-kuznetsov commented 7 months ago

https://psalm.dev/r/d7da8093d2

psalm-github-bot[bot] commented 7 months ago

I found these snippets:

https://psalm.dev/r/d7da8093d2 ```php > $key */ public function get(string $key): mixed { return $this->object->{$key}; } } ``` ``` Psalm output (using commit ef3b018): ERROR: InvalidDocblock - 17:16 - Untemplated key-of param properties-of should be an array in docblock for Box::get ```
hlib-kuznetsov commented 7 months ago

And more specific https://psalm.dev/r/f571e1b77c

psalm-github-bot[bot] commented 7 months ago

I found these snippets:

https://psalm.dev/r/f571e1b77c ```php */ public function find(): QueryBuilder { return new QueryBuilder($this); } } /** @psalm-suppress MissingConstructor */ class Entity { public int $id; public string $name; } /** @template-extends AbstractRepository */ class EntityRepository extends AbstractRepository {} /** * @template E of object */ class QueryBuilder { /** @param AbstractRepository $repository */ public function __construct( private readonly AbstractRepository $repository ) { } /** @param key-of> $key */ public function where(string $key, mixed $value): static { return $this; } } /** @psalm-trace $queryBuilder */ $queryBuilder = (new EntityRepository)->find(); $queryBuilder->where('id', 5); // shouldn't raise issue $queryBuilder->where('notExistingProperty', 5); // should raise issue ``` ``` Psalm output (using commit ef3b018): INFO: Trace - 39:1 - $queryBuilder: QueryBuilder ERROR: InvalidDocblock - 31:16 - Untemplated key-of param properties-of should be an array in docblock for QueryBuilder::where ```