Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\DowngradePhp81\Rector\FuncCall\DowngradeHashAlgorithmXxHash\Fixture;

final class SkipCheckPHPVersionTernary
{
public function run($value)
{
return PHP_VERSION_ID >= 80100
? hash( 'xxh128', $value )
: hash( 'md4', $value );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Scalar\String_;
use PHPStan\Type\IntegerRangeType;
use Rector\NodeAnalyzer\ArgsAnalyzer;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\PHPStan\ScopeFetcher;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -108,7 +110,20 @@ private function shouldSkip(FuncCall $funcCall): bool
return true;
}

return ! $this->isName($funcCall, 'hash');
if (! $this->isName($funcCall, 'hash')) {
return true;
}

$scope = ScopeFetcher::fetch($funcCall);
$type = $scope->getPhpVersion()
->getType();

if (! $type instanceof IntegerRangeType) {
// next todo: check version_compare() and if() usage
return false;
}

return $type->getMin() === 80100;
}

/**
Expand Down