vimeo / psalm

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

Possible ArgumentTypeCoercion false positive. #7907

Open vafadarnaghi opened 2 years ago

vafadarnaghi commented 2 years ago

Hi,

It seems trimming strings breaks psalm enum type.

Please, take a look to snippet:

https://psalm.dev/r/68e999caa5 https://psalm.dev/r/41e5416030

Thank you.

Edit: fixed URLs

psalm-github-bot[bot] commented 2 years ago

I found these snippets:

https://psalm.dev/r/68e999caa5 ```php testType($t); ``` ``` Psalm output (using commit f960d71): ERROR: ArgumentTypeCoercion - 16:14 - Argument 1 of B::testType expects 'float'|'int'|'string', parent type string provided ```
https://psalm.dev/r/41e5416030 ```php testType($t); ``` ``` Psalm output (using commit f960d71): No issues! ```
AndrolGenhald commented 2 years ago

This could be supported by adding a return type provider for trim if you want to give it a shot. Might as well do ltrim and rtrim at the same time.