77use PharIo \Version \VersionConstraintParser ;
88use PHPStan \Analyser \Scope ;
99use PHPStan \BetterReflection \Reflection \ReflectionAttribute ;
10+ use PHPStan \Php \ConfiguredPhpVersionRangeHelper ;
1011use PHPStan \Php \PhpMinorVersionIterator ;
11- use PHPStan \Php \PhpVersion ;
1212use PHPStan \Rules \IdentifierRuleError ;
1313use PHPStan \Rules \RuleErrorBuilder ;
14- use PHPStan \Type \Constant \ConstantIntegerType ;
15- use PHPStan \Type \IntegerRangeType ;
1614use function count ;
1715use function is_numeric ;
1816use function preg_match ;
@@ -28,8 +26,6 @@ final class AttributeVersionRequirementHelper
2826
2927 private PHPUnitVersion $ PHPUnitVersion ;
3028
31- private PhpVersion $ fallbackPhpVersion ;
32-
3329 /**
3430 * When phpstan-deprecation-rules is installed, rule reports deprecated usages.
3531 */
@@ -42,19 +38,21 @@ final class AttributeVersionRequirementHelper
4238
4339 private bool $ bleedingEdge ;
4440
41+ private ConfiguredPhpVersionRangeHelper $ phpVersionRangeHelper ;
42+
4543 public function __construct (
4644 PHPUnitVersion $ PHPUnitVersion ,
47- PhpVersion $ phpVersion ,
45+ ConfiguredPhpVersionRangeHelper $ phpVersionRangeHelper ,
4846 bool $ deprecationRulesInstalled = false ,
4947 bool $ bleedingEdge = false ,
5048 bool $ warnAboutIncompleteVersion = true
5149 )
5250 {
5351 $ this ->PHPUnitVersion = $ PHPUnitVersion ;
5452 $ this ->deprecationRulesInstalled = $ deprecationRulesInstalled ;
55- $ this ->fallbackPhpVersion = $ phpVersion ;
5653 $ this ->warnAboutIncompleteVersion = $ warnAboutIncompleteVersion ;
5754 $ this ->bleedingEdge = $ bleedingEdge ;
55+ $ this ->phpVersionRangeHelper = $ phpVersionRangeHelper ;
5856 }
5957
6058 /**
@@ -64,11 +62,6 @@ public function __construct(
6462 */
6563 public function checkVersionRequirement (array $ attributes , Scope $ scope ): array
6664 {
67- $ phpstanPharIoVersions = $ this ->getAnalyzedPhpVersions ($ scope );
68- if ($ phpstanPharIoVersions === []) {
69- return [];
70- }
71-
7265 $ errors = [];
7366 $ parser = new VersionConstraintParser ();
7467 foreach ($ attributes as $ attr ) {
@@ -99,7 +92,7 @@ public function checkVersionRequirement(array $attributes, Scope $scope): array
9992
10093 $ pharIoVersions = strpos ($ attr ->getName (), 'RequiresPhpunit ' ) !== false
10194 ? $ this ->PHPUnitVersion ->getPharIoVersions ()
102- : $ phpstanPharIoVersions ;
95+ : $ this -> getAnalyzedPhpVersions () ;
10396 if ($ pharIoVersions === []) {
10497 continue ;
10598 }
@@ -168,29 +161,23 @@ public function checkVersionRequirement(array $attributes, Scope $scope): array
168161 /**
169162 * @return Version[]
170163 */
171- private function getAnalyzedPhpVersions (Scope $ scope ): array
164+ private function getAnalyzedPhpVersions (): array
172165 {
173- $ scopePhpVersion = $ scope ->getPhpVersion ()->getType ();
174- if ($ scopePhpVersion instanceof ConstantIntegerType) {
175- $ v = new PhpVersion ($ scopePhpVersion ->getValue ());
176- return [new Version ($ v ->getVersionString ())];
177- } elseif ($ scopePhpVersion instanceof IntegerRangeType) {
178- if ($ scopePhpVersion ->getMin () === null || $ scopePhpVersion ->getMax () === null ) {
179- return [];
180- }
181-
166+ // @phpstan-ignore phpstanApi.method
167+ [$ minVersion , $ maxVersion ] = $ this ->phpVersionRangeHelper ->getVersionRange ();
168+ if ($ minVersion !== null && $ maxVersion !== null ) {
182169 $ versions = [];
183170 $ minorVersionIterator = new PhpMinorVersionIterator (
184- new PhpVersion ( $ scopePhpVersion -> getMin ()) ,
185- new PhpVersion ( $ scopePhpVersion -> getMax ()) ,
171+ $ minVersion ,
172+ $ maxVersion ,
186173 );
187174 foreach ($ minorVersionIterator as $ phpstanVersion ) {
188175 $ versions [] = new Version ($ phpstanVersion ->getVersionString ());
189176 }
190177 return $ versions ;
191178 }
192179
193- return [new Version ( $ this -> fallbackPhpVersion -> getVersionString ()) ];
180+ return [];
194181 }
195182
196183 // see https://github.com/sebastianbergmann/phpunit/issues/6451
0 commit comments