8
8
use PHPStan \Rules \LineRuleError ;
9
9
use PHPStan \Rules \MetadataRuleError ;
10
10
use PHPStan \Rules \NonIgnorableRuleError ;
11
- use PHPStan \Rules \RuleError ;
12
11
use PHPStan \Rules \TipRuleError ;
13
- use function is_string ;
14
12
15
13
final class RuleErrorTransformer
16
14
{
@@ -19,7 +17,7 @@ final class RuleErrorTransformer
19
17
* @param class-string<Node> $nodeType
20
18
*/
21
19
public function transform (
22
- string | RuleError $ ruleError ,
20
+ IdentifierRuleError $ ruleError ,
23
21
Scope $ scope ,
24
22
string $ nodeType ,
25
23
int $ nodeLine ,
@@ -31,51 +29,43 @@ public function transform(
31
29
$ filePath = $ scope ->getFile ();
32
30
$ traitFilePath = null ;
33
31
$ tip = null ;
34
- $ identifier = null ;
35
32
$ metadata = [];
36
33
if ($ scope ->isInTrait ()) {
37
34
$ traitReflection = $ scope ->getTraitReflection ();
38
35
if ($ traitReflection ->getFileName () !== null ) {
39
36
$ traitFilePath = $ traitReflection ->getFileName ();
40
37
}
41
38
}
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
- }
60
39
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
+ }
64
54
65
- if ($ ruleError instanceof IdentifierRuleError ) {
66
- $ identifier = $ ruleError ->getIdentifier ();
67
- }
55
+ if ($ ruleError instanceof TipRuleError ) {
56
+ $ tip = $ ruleError ->getTip ();
57
+ }
68
58
69
- if ($ ruleError instanceof MetadataRuleError) {
70
- $ metadata = $ ruleError ->getMetadata ();
71
- }
59
+ if ($ ruleError instanceof MetadataRuleError) {
60
+ $ metadata = $ ruleError ->getMetadata ();
61
+ }
72
62
73
- if ($ ruleError instanceof NonIgnorableRuleError) {
74
- $ canBeIgnored = false ;
75
- }
63
+ if ($ ruleError instanceof NonIgnorableRuleError) {
64
+ $ canBeIgnored = false ;
76
65
}
66
+
77
67
return new Error (
78
- $ message ,
68
+ $ ruleError -> getMessage () ,
79
69
$ fileName ,
80
70
$ line ,
81
71
$ canBeIgnored ,
@@ -84,7 +74,7 @@ public function transform(
84
74
$ tip ,
85
75
$ nodeLine ,
86
76
$ nodeType ,
87
- $ identifier ,
77
+ $ ruleError -> getIdentifier () ,
88
78
$ metadata ,
89
79
);
90
80
}
0 commit comments