phar icon indicating copy to clipboard operation
phar copied to clipboard

Unexpected RedundantCondition

Open dzentota opened this issue 4 years ago • 1 comments

Consider the following code:

<?php
function check(string $filename): bool
{
    if (strpos($filename, ".suback.php") !== false || strpos($filename, "_backup") !== false) {
        // we'll ignore .suback files, they are old upgrade backups
        return false;
    }
    return true;
}

The latest psalm/phar 4.12.0 returns:

ERROR: RedundantCondition - t.php:4:9 - int can never contain false (see https://psalm.dev/122) if (strpos($filename, ".suback.php") !== false || strpos($filename, "_backup") !== false) { ERROR: RedundantCondition - t.php:4:55 - int can never contain false (see https://psalm.dev/122) if (strpos($filename, ".suback.php") !== false || strpos($filename, "_backup") !== false) {

While psalm.dev returns expected result

https://psalm.dev/r/0cc1635fe5

dzentota avatar Nov 15 '21 12:11 dzentota

I found these snippets:

https://psalm.dev/r/0cc1635fe5
<?php
function check(string $filename): bool
{
    if (strpos($filename, ".suback.php") !== false || strpos($filename, "_backup") !== false) {
        // we'll ignore .suback files, they are old upgrade backups
 		return false;
    }
    return true;
}
Psalm output (using commit 608e8d1):

No issues!

psalm-github-bot[bot] avatar Nov 15 '21 12:11 psalm-github-bot[bot]