psalm
psalm copied to clipboard
Greater > and Less Than < comparisons with non-numeric, non-string, non-resource types should report error
e.g. https://psalm.dev/r/e63cef6890 this is a redundant condition but isn't reported, or https://psalm.dev/r/29eb392672 which causes a PHP notice.
However there are tons of things one can do wrong with those operators: https://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.types and it would take an immense amount of time to figure out all possible cases and all report them as separate errors.
As a first, I suggest to report all > and < operations that contain an array, object, probably even null and bool as possible error - and refine this if e.g. there are too many false positives for some cases (e.g. int|false > 100
)
I found these snippets:
https://psalm.dev/r/e63cef6890
<?php
$a = array();
if ( $a > PHP_INT_MAX ) {
echo "yes";
}
Psalm output (using commit ef3b018):
No issues!
https://psalm.dev/r/29eb392672
<?php
$a = new stdClass();
if ( $a > PHP_INT_MAX ) {
echo "yes";
}
Psalm output (using commit ef3b018):
No issues!