File tree 3 files changed +16
-10
lines changed
tests/PHPStan/Rules/Exceptions
3 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,11 @@ public function __construct(
18
18
{
19
19
}
20
20
21
+ public function supportsNoncapturingCatches (): TrinaryLogic
22
+ {
23
+ return IntegerRangeType::fromInterval (80000 , null )->isSuperTypeOf ($ this ->phpVersions )->result ;
24
+ }
25
+
21
26
public function producesWarningForFinalPrivateMethods (): TrinaryLogic
22
27
{
23
28
return IntegerRangeType::fromInterval (80000 , null )->isSuperTypeOf ($ this ->phpVersions )->result ;
Original file line number Diff line number Diff line change 4
4
5
5
use PhpParser \Node ;
6
6
use PHPStan \Analyser \Scope ;
7
- use PHPStan \Php \PhpVersion ;
8
7
use PHPStan \Rules \Rule ;
9
8
use PHPStan \Rules \RuleErrorBuilder ;
10
9
14
13
final class NoncapturingCatchRule implements Rule
15
14
{
16
15
17
- public function __construct (private PhpVersion $ phpVersion )
18
- {
19
- }
20
-
21
16
public function getNodeType (): string
22
17
{
23
18
return Node \Stmt \Catch_::class;
@@ -28,7 +23,7 @@ public function getNodeType(): string
28
23
*/
29
24
public function processNode (Node $ node , Scope $ scope ): array
30
25
{
31
- if ($ this -> phpVersion ->supportsNoncapturingCatches ()) {
26
+ if ($ scope -> getPhpVersion () ->supportsNoncapturingCatches ()-> yes ()) {
32
27
return [];
33
28
}
34
29
Original file line number Diff line number Diff line change 5
5
use PHPStan \Php \PhpVersion ;
6
6
use PHPStan \Rules \Rule ;
7
7
use PHPStan \Testing \RuleTestCase ;
8
+ use const PHP_VERSION_ID ;
8
9
9
10
/**
10
11
* @extends RuleTestCase<NoncapturingCatchRule>
11
12
*/
12
13
class NoncapturingCatchRuleTest extends RuleTestCase
13
14
{
14
15
15
- private PhpVersion $ phpVersion ;
16
-
17
16
protected function getRule (): Rule
18
17
{
19
- return new NoncapturingCatchRule ($ this -> phpVersion );
18
+ return new NoncapturingCatchRule ();
20
19
}
21
20
22
21
public function dataRule (): array
@@ -49,7 +48,14 @@ public function dataRule(): array
49
48
*/
50
49
public function testRule (int $ phpVersion , array $ expectedErrors ): void
51
50
{
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
+ }
53
59
54
60
$ this ->analyse ([
55
61
__DIR__ . '/data/noncapturing-catch.php ' ,
You can’t perform that action at this time.
0 commit comments