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
5 changes: 5 additions & 0 deletions src/Php/PhpVersions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public function __construct(
{
}

public function supportsNoncapturingCatches(): TrinaryLogic
{
return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
}

public function producesWarningForFinalPrivateMethods(): TrinaryLogic
{
return IntegerRangeType::fromInterval(80000, null)->isSuperTypeOf($this->phpVersions)->result;
Expand Down
7 changes: 1 addition & 6 deletions src/Rules/Exceptions/NoncapturingCatchRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;

Expand All @@ -14,10 +13,6 @@
final class NoncapturingCatchRule implements Rule
{

public function __construct(private PhpVersion $phpVersion)
{
}

public function getNodeType(): string
{
return Node\Stmt\Catch_::class;
Expand All @@ -28,7 +23,7 @@ public function getNodeType(): string
*/
public function processNode(Node $node, Scope $scope): array
{
if ($this->phpVersion->supportsNoncapturingCatches()) {
if ($scope->getPhpVersion()->supportsNoncapturingCatches()->yes()) {
return [];
}

Expand Down
14 changes: 10 additions & 4 deletions tests/PHPStan/Rules/Exceptions/NoncapturingCatchRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use const PHP_VERSION_ID;

/**
* @extends RuleTestCase<NoncapturingCatchRule>
*/
class NoncapturingCatchRuleTest extends RuleTestCase
{

private PhpVersion $phpVersion;

protected function getRule(): Rule
{
return new NoncapturingCatchRule($this->phpVersion);
return new NoncapturingCatchRule();
}

public function dataRule(): array
Expand Down Expand Up @@ -49,7 +48,14 @@ public function dataRule(): array
*/
public function testRule(int $phpVersion, array $expectedErrors): void
{
$this->phpVersion = new PhpVersion($phpVersion);
$testVersion = new PhpVersion($phpVersion);
$runtimeVersion = new PhpVersion(PHP_VERSION_ID);
if (
$testVersion->getMajorVersionId() !== $runtimeVersion->getMajorVersionId()
|| $testVersion->getMinorVersionId() !== $runtimeVersion->getMinorVersionId()
) {
$this->markTestSkipped('Test requires PHP version ' . $testVersion->getMajorVersionId() . '.' . $testVersion->getMinorVersionId() . '.*');
}

$this->analyse([
__DIR__ . '/data/noncapturing-catch.php',
Expand Down
Loading