Skip to content

Commit f3d9735

Browse files
authored
Merge pull request #1 from Vendic/fix/phpstan-2-compatibility
fix: PHPStan 2.0 compatibility - use RuleErrorBuilder instead of string returns
2 parents e2c68be + ad5d80c commit f3d9735

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Rules/Exceptions/EmptyExceptionRule.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Broker\Broker;
1010
use PHPStan\Rules\Rule;
11+
use PHPStan\Rules\RuleErrorBuilder;
1112
use function strpos;
1213

1314
/**
@@ -23,13 +24,14 @@ public function getNodeType(): string
2324
/**
2425
* @param \PhpParser\Node\Stmt\Catch_ $node
2526
* @param \PHPStan\Analyser\Scope $scope
26-
* @return string[]
27+
* @return \PHPStan\Rules\RuleError[]
2728
*/
2829
public function processNode(Node $node, Scope $scope): array
2930
{
3031
if ($this->isEmpty($node->stmts)) {
3132
return [
32-
'Empty catch block. If you are sure this is meant to be empty, please add a "// @ignoreException" comment in the catch block.'
33+
RuleErrorBuilder::message('Empty catch block. If you are sure this is meant to be empty, please add a "// @ignoreException" comment in the catch block.')
34+
->build()
3335
];
3436
}
3537

src/Rules/Exceptions/MustRethrowRule.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PHPStan\Analyser\Scope;
1313
use PHPStan\Broker\Broker;
1414
use PHPStan\Rules\Rule;
15+
use PHPStan\Rules\RuleErrorBuilder;
1516
use RuntimeException;
1617
use TheCodingMachine\PHPStan\Utils\PrefixGenerator;
1718
use Throwable;
@@ -32,7 +33,7 @@ public function getNodeType(): string
3233
/**
3334
* @param Catch_ $node
3435
* @param \PHPStan\Analyser\Scope $scope
35-
* @return string[]
36+
* @return \PHPStan\Rules\RuleError[]
3637
*/
3738
public function processNode(Node $node, Scope $scope): array
3839
{
@@ -82,7 +83,8 @@ public function isThrowFound(): bool
8283
$errors = [];
8384

8485
if (!$visitor->isThrowFound()) {
85-
$errors[] = sprintf('%scaught "%s" must be rethrown. Either catch a more specific exception or add a "throw" clause in the "catch" block to propagate the exception. More info: http://bit.ly/failloud', PrefixGenerator::generatePrefix($scope), $exceptionType);
86+
$errors[] = RuleErrorBuilder::message(sprintf('%scaught "%s" must be rethrown. Either catch a more specific exception or add a "throw" clause in the "catch" block to propagate the exception. More info: http://bit.ly/failloud', PrefixGenerator::generatePrefix($scope), $exceptionType))
87+
->build();
8688
}
8789

8890
return $errors;

0 commit comments

Comments
 (0)