vimeo / psalm

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

Assertions in array used as foreach value are repeated #9708

Open danog opened 1 year ago

danog commented 1 year ago

https://psalm.dev/r/49f28433b0

Not too sure how to fix, since the foreach expression is analyzed multiple times the assertion is also repeated multiple times, can't really think of a simple way to fix.

psalm-github-bot[bot] commented 1 year ago

I found these snippets:

https://psalm.dev/r/49f28433b0 ```php _id * * @return int */ public function getIdAssert(): int { $id = $this->_id; assert($id !== null); return $id; } } function test(a $set): void { foreach ([$set->getIdAssert()] as $_) { } } ``` ``` Psalm output (using commit 1a43956): ERROR: RedundantConditionGivenDocblockType - 20:18 - Docblock-defined type int for $set->_id is never null ```