File tree Expand file tree Collapse file tree 3 files changed +16
-10
lines changed
tests/PHPStan/Rules/Exceptions Expand file tree Collapse file tree 3 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ public function __construct(
1818 {
1919 }
2020
21+ public function supportsNoncapturingCatches (): TrinaryLogic
22+ {
23+ return IntegerRangeType::fromInterval (80000 , null )->isSuperTypeOf ($ this ->phpVersions )->result ;
24+ }
25+
2126 public function producesWarningForFinalPrivateMethods (): TrinaryLogic
2227 {
2328 return IntegerRangeType::fromInterval (80000 , null )->isSuperTypeOf ($ this ->phpVersions )->result ;
Original file line number Diff line number Diff line change 44
55use PhpParser \Node ;
66use PHPStan \Analyser \Scope ;
7- use PHPStan \Php \PhpVersion ;
87use PHPStan \Rules \Rule ;
98use PHPStan \Rules \RuleErrorBuilder ;
109
1413final class NoncapturingCatchRule implements Rule
1514{
1615
17- public function __construct (private PhpVersion $ phpVersion )
18- {
19- }
20-
2116 public function getNodeType (): string
2217 {
2318 return Node \Stmt \Catch_::class;
@@ -28,7 +23,7 @@ public function getNodeType(): string
2823 */
2924 public function processNode (Node $ node , Scope $ scope ): array
3025 {
31- if ($ this -> phpVersion ->supportsNoncapturingCatches ()) {
26+ if ($ scope -> getPhpVersion () ->supportsNoncapturingCatches ()-> yes ()) {
3227 return [];
3328 }
3429
Original file line number Diff line number Diff line change 55use PHPStan \Php \PhpVersion ;
66use PHPStan \Rules \Rule ;
77use PHPStan \Testing \RuleTestCase ;
8+ use const PHP_VERSION_ID ;
89
910/**
1011 * @extends RuleTestCase<NoncapturingCatchRule>
1112 */
1213class NoncapturingCatchRuleTest extends RuleTestCase
1314{
1415
15- private PhpVersion $ phpVersion ;
16-
1716 protected function getRule (): Rule
1817 {
19- return new NoncapturingCatchRule ($ this -> phpVersion );
18+ return new NoncapturingCatchRule ();
2019 }
2120
2221 public function dataRule (): array
@@ -49,7 +48,14 @@ public function dataRule(): array
4948 */
5049 public function testRule (int $ phpVersion , array $ expectedErrors ): void
5150 {
52- $ this ->phpVersion = new PhpVersion ($ phpVersion );
51+ $ testVersion = new PhpVersion ($ phpVersion );
52+ $ runtimeVersion = new PhpVersion (PHP_VERSION_ID );
53+ if (
54+ $ testVersion ->getMajorVersionId () !== $ runtimeVersion ->getMajorVersionId ()
55+ || $ testVersion ->getMinorVersionId () !== $ runtimeVersion ->getMinorVersionId ()
56+ ) {
57+ $ this ->markTestSkipped ('Test requires PHP version ' . $ testVersion ->getMajorVersionId () . '. ' . $ testVersion ->getMinorVersionId () . '.* ' );
58+ }
5359
5460 $ this ->analyse ([
5561 __DIR__ . '/data/noncapturing-catch.php ' ,
You can’t perform that action at this time.
0 commit comments