Skip to content

Commit 5d17773

Browse files
committed
RuleErrorTransformer - accept only IdentifierRuleError
1 parent 0b2d872 commit 5d17773

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

src/Analyser/RuleErrorTransformer.php

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
use PHPStan\Rules\LineRuleError;
99
use PHPStan\Rules\MetadataRuleError;
1010
use PHPStan\Rules\NonIgnorableRuleError;
11-
use PHPStan\Rules\RuleError;
1211
use PHPStan\Rules\TipRuleError;
13-
use function is_string;
1412

1513
final class RuleErrorTransformer
1614
{
@@ -19,7 +17,7 @@ final class RuleErrorTransformer
1917
* @param class-string<Node> $nodeType
2018
*/
2119
public function transform(
22-
string|RuleError $ruleError,
20+
IdentifierRuleError $ruleError,
2321
Scope $scope,
2422
string $nodeType,
2523
int $nodeLine,
@@ -31,51 +29,43 @@ public function transform(
3129
$filePath = $scope->getFile();
3230
$traitFilePath = null;
3331
$tip = null;
34-
$identifier = null;
3532
$metadata = [];
3633
if ($scope->isInTrait()) {
3734
$traitReflection = $scope->getTraitReflection();
3835
if ($traitReflection->getFileName() !== null) {
3936
$traitFilePath = $traitReflection->getFileName();
4037
}
4138
}
42-
if (is_string($ruleError)) {
43-
$message = $ruleError;
44-
} else {
45-
$message = $ruleError->getMessage();
46-
if (
47-
$ruleError instanceof LineRuleError
48-
&& $ruleError->getLine() !== -1
49-
) {
50-
$line = $ruleError->getLine();
51-
}
52-
if (
53-
$ruleError instanceof FileRuleError
54-
&& $ruleError->getFile() !== ''
55-
) {
56-
$fileName = $ruleError->getFileDescription();
57-
$filePath = $ruleError->getFile();
58-
$traitFilePath = null;
59-
}
6039

61-
if ($ruleError instanceof TipRuleError) {
62-
$tip = $ruleError->getTip();
63-
}
40+
if (
41+
$ruleError instanceof LineRuleError
42+
&& $ruleError->getLine() !== -1
43+
) {
44+
$line = $ruleError->getLine();
45+
}
46+
if (
47+
$ruleError instanceof FileRuleError
48+
&& $ruleError->getFile() !== ''
49+
) {
50+
$fileName = $ruleError->getFileDescription();
51+
$filePath = $ruleError->getFile();
52+
$traitFilePath = null;
53+
}
6454

65-
if ($ruleError instanceof IdentifierRuleError) {
66-
$identifier = $ruleError->getIdentifier();
67-
}
55+
if ($ruleError instanceof TipRuleError) {
56+
$tip = $ruleError->getTip();
57+
}
6858

69-
if ($ruleError instanceof MetadataRuleError) {
70-
$metadata = $ruleError->getMetadata();
71-
}
59+
if ($ruleError instanceof MetadataRuleError) {
60+
$metadata = $ruleError->getMetadata();
61+
}
7262

73-
if ($ruleError instanceof NonIgnorableRuleError) {
74-
$canBeIgnored = false;
75-
}
63+
if ($ruleError instanceof NonIgnorableRuleError) {
64+
$canBeIgnored = false;
7665
}
66+
7767
return new Error(
78-
$message,
68+
$ruleError->getMessage(),
7969
$fileName,
8070
$line,
8171
$canBeIgnored,
@@ -84,7 +74,7 @@ public function transform(
8474
$tip,
8575
$nodeLine,
8676
$nodeType,
87-
$identifier,
77+
$ruleError->getIdentifier(),
8878
$metadata,
8979
);
9080
}

0 commit comments

Comments
 (0)