18
18
import com .jetbrains .php .lang .psi .elements .Parameter ;
19
19
import com .jetbrains .php .lang .psi .elements .PhpClass ;
20
20
import com .jetbrains .php .lang .psi .visitors .PhpElementVisitor ;
21
+ import com .magento .idea .magento2plugin .bundles .InspectionBundle ;
21
22
import com .magento .idea .magento2plugin .inspections .php .util .PhpClassImplementsInterfaceUtil ;
22
23
import com .magento .idea .magento2plugin .magento .files .Plugin ;
23
24
import com .magento .idea .magento2plugin .magento .packages .Package ;
@@ -32,15 +33,9 @@ public class PluginInspection extends PhpInspection {
32
33
@ Override
33
34
public PsiElementVisitor buildVisitor (@ NotNull ProblemsHolder problemsHolder , boolean b ) {
34
35
return new PhpElementVisitor () {
35
- private static final String pluginOnNotPublicMethodProblemDescription = "You can't declare a plugin for a not public method" ;
36
- private static final String pluginOnFinalClassProblemDescription = "You can't declare a plugin for a final class!" ;
37
- private static final String pluginOnFinalMethodProblemDescription = "You can't declare a plugin for a final method!" ;
38
- private static final String pluginOnStaticMethodProblemDescription = "You can't declare a plugin for a static method!" ;
39
- private static final String pluginOnConstructorMethodProblemDescription = "You can't declare a plugin for a __construct method!" ;
40
- private static final String redundantParameterProblemDescription = "Redundant parameter" ;
41
- private static final String possibleTypeIncompatibilityProblemDescription = "Possible type incompatibility. Consider changing the parameter according to the target method." ;
42
36
private final Integer beforePluginExtraParamsStart = 2 ;
43
37
private final Integer afterAndAroundPluginExtraParamsStart = 3 ;
38
+ private InspectionBundle inspectionBundle = new InspectionBundle ();
44
39
45
40
private String getPluginPrefix (Method pluginMethod ) {
46
41
String pluginMethodName = pluginMethod .getName ();
@@ -99,23 +94,43 @@ private void checkTargetClass(PsiElement currentClassNameIdentifier, PhpClass ta
99
94
ProblemDescriptor [] currentResults = problemsHolder .getResultsArray ();
100
95
int finalClassProblems = getFinalClassProblems (currentResults );
101
96
if (finalClassProblems == 0 ) {
102
- problemsHolder .registerProblem (currentClassNameIdentifier , pluginOnFinalClassProblemDescription , ProblemHighlightType .ERROR );
97
+ problemsHolder .registerProblem (
98
+ currentClassNameIdentifier ,
99
+ inspectionBundle .message ("inspection.plugin.error.finalClass" ),
100
+ ProblemHighlightType .ERROR
101
+ );
103
102
}
104
103
}
105
104
}
106
105
107
106
private void checkTargetMethod (Method pluginMethod , String targetClassMethodName , Method targetMethod ) {
108
107
if (targetClassMethodName .equals (Plugin .constructMethodName )) {
109
- problemsHolder .registerProblem (pluginMethod .getNameIdentifier (), pluginOnConstructorMethodProblemDescription , ProblemHighlightType .ERROR );
108
+ problemsHolder .registerProblem (
109
+ pluginMethod .getNameIdentifier (),
110
+ inspectionBundle .message ("inspection.plugin.error.constructMethod" ),
111
+ ProblemHighlightType .ERROR
112
+ );
110
113
}
111
114
if (targetMethod .isFinal ()) {
112
- problemsHolder .registerProblem (pluginMethod .getNameIdentifier (), pluginOnFinalMethodProblemDescription , ProblemHighlightType .ERROR );
115
+ problemsHolder .registerProblem (
116
+ pluginMethod .getNameIdentifier (),
117
+ inspectionBundle .message ("inspection.plugin.error.finalMethod" ),
118
+ ProblemHighlightType .ERROR
119
+ );
113
120
}
114
121
if (targetMethod .isStatic ()) {
115
- problemsHolder .registerProblem (pluginMethod .getNameIdentifier (), pluginOnStaticMethodProblemDescription , ProblemHighlightType .ERROR );
122
+ problemsHolder .registerProblem (
123
+ pluginMethod .getNameIdentifier (),
124
+ inspectionBundle .message ("inspection.plugin.error.staticMethod" ),
125
+ ProblemHighlightType .ERROR
126
+ );
116
127
}
117
128
if (!targetMethod .getAccess ().toString ().equals (Plugin .publicAccess )) {
118
- problemsHolder .registerProblem (pluginMethod .getNameIdentifier (), pluginOnNotPublicMethodProblemDescription , ProblemHighlightType .ERROR );
129
+ problemsHolder .registerProblem (
130
+ pluginMethod .getNameIdentifier (),
131
+ inspectionBundle .message ("inspection.plugin.error.nonPublicMethod" ),
132
+ ProblemHighlightType .ERROR
133
+ );
119
134
}
120
135
}
121
136
@@ -134,7 +149,11 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
134
149
problemsHolder .registerProblem (pluginMethodParameter , PhpBundle .message ("inspection.wrong_param_type" , new Object []{declaredType , targetClassFqn }), ProblemHighlightType .ERROR );
135
150
}
136
151
if (!checkPossibleTypeIncompatibility (targetClassFqn , declaredType , phpIndex )) {
137
- problemsHolder .registerProblem (pluginMethodParameter , possibleTypeIncompatibilityProblemDescription , ProblemHighlightType .WEAK_WARNING );
152
+ problemsHolder .registerProblem (
153
+ pluginMethodParameter ,
154
+ inspectionBundle .message ("inspection.plugin.error.typeIncompatibility" ),
155
+ ProblemHighlightType .WEAK_WARNING
156
+ );
138
157
}
139
158
continue ;
140
159
}
@@ -154,7 +173,11 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
154
173
problemsHolder .registerProblem (pluginMethodParameter , PhpBundle .message ("inspection.wrong_param_type" , new Object []{declaredType , targetMethod .getDeclaredType ().toString ()}), ProblemHighlightType .ERROR );
155
174
}
156
175
if (!checkPossibleTypeIncompatibility (targetMethod .getDeclaredType ().toString (), declaredType , phpIndex )) {
157
- problemsHolder .registerProblem (pluginMethodParameter , possibleTypeIncompatibilityProblemDescription , ProblemHighlightType .WEAK_WARNING );
176
+ problemsHolder .registerProblem (
177
+ pluginMethodParameter ,
178
+ inspectionBundle .message ("inspection.plugin.error.typeIncompatibility" ),
179
+ ProblemHighlightType .WEAK_WARNING
180
+ );
158
181
}
159
182
continue ;
160
183
}
@@ -172,7 +195,11 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
172
195
beforePluginExtraParamsStart :
173
196
afterAndAroundPluginExtraParamsStart );
174
197
if (targetMethodParameters .length <= targetParameterKey ) {
175
- problemsHolder .registerProblem (pluginMethodParameter , redundantParameterProblemDescription , ProblemHighlightType .ERROR );
198
+ problemsHolder .registerProblem (
199
+ pluginMethodParameter ,
200
+ inspectionBundle .message ("inspection.plugin.error.redundantParameter" ),
201
+ ProblemHighlightType .ERROR
202
+ );
176
203
continue ;
177
204
}
178
205
Parameter targetMethodParameter = targetMethodParameters [targetParameterKey ];
@@ -182,7 +209,11 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
182
209
problemsHolder .registerProblem (pluginMethodParameter , PhpBundle .message ("inspection.wrong_param_type" , new Object []{declaredType , targetMethodParameterDeclaredType }), ProblemHighlightType .ERROR );
183
210
}
184
211
if (!checkPossibleTypeIncompatibility (targetMethodParameterDeclaredType , declaredType , phpIndex )) {
185
- problemsHolder .registerProblem (pluginMethodParameter , possibleTypeIncompatibilityProblemDescription , ProblemHighlightType .WEAK_WARNING );
212
+ problemsHolder .registerProblem (
213
+ pluginMethodParameter ,
214
+ inspectionBundle .message ("inspection.plugin.error.typeIncompatibility" ),
215
+ ProblemHighlightType .WEAK_WARNING
216
+ );
186
217
}
187
218
}
188
219
}
@@ -204,7 +235,7 @@ private String getTargetMethodName(Method pluginMethod, String pluginPrefix) {
204
235
private int getFinalClassProblems (ProblemDescriptor [] currentResults ) {
205
236
int finalClassProblems = 0 ;
206
237
for (ProblemDescriptor currentProblem : currentResults ) {
207
- if (currentProblem .getDescriptionTemplate ().equals (pluginOnFinalClassProblemDescription )) {
238
+ if (currentProblem .getDescriptionTemplate ().equals (inspectionBundle . message ( "inspection.plugin.error.finalClass" ) )) {
208
239
finalClassProblems ++;
209
240
}
210
241
}
0 commit comments