vimeo / psalm

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

@template for class type instead of class instance to support extended classes #10311

Open kkmuffme opened 10 months ago

kkmuffme commented 10 months ago

https://psalm.dev/r/1a0ddeeef2

There's currently no way to annotate a function that modifies an object and returns the object.

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

I found these snippets:

https://psalm.dev/r/1a0ddeeef2 ```php id = fromApi( $arg ); return $arg; } function fromApi( A $arg ): int { return rand( 0, 1000 ); } $b = new B(); $x = $b->id; /** @psalm-trace $x */; $r = add( $b ); $y = $r->id; /** @psalm-trace $y */; $b->id = 1234; $z = $b->id; /** @psalm-trace $z */; ``` ``` Psalm output (using commit 147505c): INFO: Trace - 30:23 - $x: int|null INFO: Trace - 34:23 - $y: int|null INFO: Trace - 38:23 - $z: 1234 ```