mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-20 18:12:24 +00:00
[DeadCode] Skip UnwrapFutureCompatibleIfPhpVersionRector on higher than current php provider (#685)
This commit is contained in:
parent
9a7ce1bdf2
commit
5f28681b9f
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector\Fixture;
|
||||
|
||||
class SkipHigherCurrent
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
// $this->phpVersionProvider->provide() returns 10000 on test
|
||||
if (version_compare(PHP_VERSION, '11.0', '<')) {
|
||||
return 'a';
|
||||
} else {
|
||||
return 'b';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -9,12 +9,17 @@ use PhpParser\Node\Expr\BinaryOp\Identical;
|
|||
use PhpParser\Node\Expr\BinaryOp\NotEqual;
|
||||
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Rector\Core\Php\PhpVersionProvider;
|
||||
use Rector\DeadCode\Contract\ConditionInterface;
|
||||
use Rector\DeadCode\ValueObject\BinaryToVersionCompareCondition;
|
||||
use Rector\DeadCode\ValueObject\VersionCompareCondition;
|
||||
|
||||
final class ConditionEvaluator
|
||||
{
|
||||
public function __construct(private PhpVersionProvider $phpVersionProvider)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|int|null
|
||||
*/
|
||||
|
@ -31,10 +36,14 @@ final class ConditionEvaluator
|
|||
return null;
|
||||
}
|
||||
|
||||
private function evaluateVersionCompareCondition(VersionCompareCondition $versionCompareCondition): bool | int
|
||||
private function evaluateVersionCompareCondition(VersionCompareCondition $versionCompareCondition): bool | int | null
|
||||
{
|
||||
$compareSign = $versionCompareCondition->getCompareSign();
|
||||
if ($compareSign !== null) {
|
||||
if ($compareSign === '<' && $this->phpVersionProvider->provide() < $versionCompareCondition->getSecondVersion()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return version_compare(
|
||||
(string) $versionCompareCondition->getFirstVersion(),
|
||||
(string) $versionCompareCondition->getSecondVersion(),
|
||||
|
|
Loading…
Reference in New Issue
Block a user