rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.71k stars 687 forks source link

False positive in ExplicitBoolCompareRector #7008

Closed rajyan closed 2 years ago

rajyan commented 2 years ago

Bug Report

Subject Details
Rector version last dev-master
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.org/demo/1ec8f958-96c5-6650-8257-fd28361f8358

<?php

/**
* @return int
*/
function test()
{
    return '';
}

if (test()) {}

Responsible rules

Expected Behavior

Want rector to handle return type ignoring PHPDoc (strictly), or skip.

https://github.com/rectorphp/rector/issues/7007 seems related.

Maybe adding a configure like AddVoidReturnTypeWhereNoReturnRector for all rules to use PHPDoc or not when handling types is useful. https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#addvoidreturntypewherenoreturnrector

rajyan commented 2 years ago

Same issue for RecastingRemovalRector https://getrector.org/demo/1ec8facc-7ae1-6fa4-bacf-b3706afb5415

rajyan commented 2 years ago

Created failing test cases for each demo https://github.com/rectorphp/rector-src/pull/1827 https://github.com/rectorphp/rector-src/pull/1828

TomasVotruba commented 2 years ago

We depends on PHPStan types here, see https://github.com/rectorphp/rector-src/pull/1828#issuecomment-1048834130