File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
rules-tests/DowngradePhp81/Rector/FuncCall/DowngradeHashAlgorithmXxHash/Fixture
rules/DowngradePhp81/Rector/FuncCall Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \DowngradePhp81 \Rector \FuncCall \DowngradeHashAlgorithmXxHash \Fixture ;
4+
5+ final class SkipCheckPHPVersionTernary
6+ {
7+ public function run ($ value )
8+ {
9+ return PHP_VERSION_ID >= 80100
10+ ? hash ( 'xxh128 ' , $ value )
11+ : hash ( 'md4 ' , $ value );
12+ }
13+ }
Original file line number Diff line number Diff line change 99use PhpParser \Node \Expr \ConstFetch ;
1010use PhpParser \Node \Expr \FuncCall ;
1111use PhpParser \Node \Scalar \String_ ;
12+ use PHPStan \Type \IntegerRangeType ;
1213use Rector \NodeAnalyzer \ArgsAnalyzer ;
1314use Rector \PhpParser \Node \Value \ValueResolver ;
15+ use Rector \PHPStan \ScopeFetcher ;
1416use Rector \Rector \AbstractRector ;
1517use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
1618use Symplify \RuleDocGenerator \ValueObject \RuleDefinition ;
@@ -108,7 +110,20 @@ private function shouldSkip(FuncCall $funcCall): bool
108110 return true ;
109111 }
110112
111- return ! $ this ->isName ($ funcCall , 'hash ' );
113+ if (! $ this ->isName ($ funcCall , 'hash ' )) {
114+ return true ;
115+ }
116+
117+ $ scope = ScopeFetcher::fetch ($ funcCall );
118+ $ type = $ scope ->getPhpVersion ()
119+ ->getType ();
120+
121+ if (! $ type instanceof IntegerRangeType) {
122+ // next todo: check version_compare() and if() usage
123+ return false ;
124+ }
125+
126+ return $ type ->getMin () === 80100 ;
112127 }
113128
114129 /**
You can’t perform that action at this time.
0 commit comments