17
17
import com .jetbrains .php .lang .psi .resolve .types .PhpType ;
18
18
import com .magento .idea .magento2plugin .actions .generation .data .code .PluginMethodData ;
19
19
import com .magento .idea .magento2plugin .magento .files .Plugin ;
20
+ import com .magento .idea .magento2plugin .magento .packages .Package ;
20
21
import org .jetbrains .annotations .NotNull ;
21
22
import org .jetbrains .annotations .Nullable ;
23
+
22
24
import java .util .*;
23
25
import java .util .regex .Pattern ;
24
26
@@ -152,7 +154,17 @@ private String getParameterDoc(Collection<PsiElement> parameters, @NotNull Plugi
152
154
}
153
155
154
156
sb .append ("* @param " );
155
- String typeStr = PhpDocUtil .getTypePresentation (project , element .getType (), PhpCodeInsightUtil .findScopeForUseOperator (element ));
157
+
158
+ String typeStr ;
159
+ if (i == 0 ) {
160
+ typeStr = PhpDocUtil .getTypePresentation (project , element .getType (), null );
161
+ } else {
162
+ typeStr = PhpDocUtil .getTypePresentation (project , element .getType (), PhpCodeInsightUtil .findScopeForUseOperator (element ));
163
+ if (typeStr .indexOf (Package .FQN_SEPARATOR , 1 ) > 0 ) {
164
+ String [] fqnArray = typeStr .split ("\\ \\ " );
165
+ typeStr = fqnArray [fqnArray .length - 1 ];
166
+ }
167
+ }
156
168
157
169
if (!typeStr .isEmpty ()) {
158
170
sb .append (typeStr ).append (' ' );
@@ -202,9 +214,19 @@ protected String getParameterList(Collection<PsiElement> parameters, @NotNull Pl
202
214
}
203
215
204
216
if (element instanceof Parameter ) {
205
- buf .append (PhpCodeUtil .paramToString (element ));
217
+ String parameterText = PhpCodeUtil .paramToString (element );
218
+ if (parameterText .indexOf (Package .FQN_SEPARATOR , 1 ) > 0 ) {
219
+ String [] fqnArray = parameterText .split ("\\ \\ " );
220
+ parameterText = fqnArray [fqnArray .length - 1 ];
221
+ }
222
+ buf .append (parameterText );
206
223
} else {
207
- String typeHint = this .getTypeHint (element );
224
+ Boolean globalType = true ;
225
+ if (i == 0 ) {
226
+ globalType = false ;
227
+ }
228
+
229
+ String typeHint = this .getTypeHint (element , globalType );
208
230
if (typeHint != null && !typeHint .isEmpty ()) {
209
231
buf .append (typeHint ).append (' ' );
210
232
}
@@ -257,21 +279,21 @@ protected String getReturnVariables(@NotNull Plugin.PluginType type) {
257
279
}
258
280
259
281
@ Nullable
260
- private String getTypeHint (@ NotNull PhpNamedElement element ) {
282
+ private String getTypeHint (@ NotNull PhpNamedElement element , Boolean globalType ) {
261
283
PhpType filedType = element .getType ().global (this .pluginClass .getProject ());
262
284
Set <String > typeStrings = filedType .getTypes ();
263
285
String typeString = null ;
264
286
if (typeStrings .size () == 1 ) {
265
- typeString = this .convertTypeToString (element , typeStrings );
287
+ typeString = this .convertTypeToString (element , typeStrings , globalType );
266
288
}
267
289
268
290
if (typeStrings .size () == 2 ) {
269
291
PhpType filteredNullType = filterNullCaseInsensitive (filedType );
270
292
if (filteredNullType .getTypes ().size () == 1 ) {
271
293
if (PhpLanguageFeature .NULLABLES .isSupported (element .getProject ())) {
272
- typeString = "?" + this .convertTypeToString (element , filteredNullType .getTypes ());
294
+ typeString = "?" + this .convertTypeToString (element , filteredNullType .getTypes (), globalType );
273
295
} else {
274
- typeString = this .convertTypeToString (element , filteredNullType .getTypes ());
296
+ typeString = this .convertTypeToString (element , filteredNullType .getTypes (), globalType );
275
297
}
276
298
}
277
299
}
@@ -280,11 +302,11 @@ private String getTypeHint(@NotNull PhpNamedElement element) {
280
302
}
281
303
282
304
@ Nullable
283
- private String convertTypeToString (@ NotNull PhpNamedElement element , Set <String > typeStrings ) {
305
+ private String convertTypeToString (@ NotNull PhpNamedElement element , Set <String > typeStrings , Boolean globalType ) {
284
306
String simpleType = typeStrings .iterator ().next ();
285
307
simpleType = StringUtil .trimStart (simpleType , "\\ " );
286
308
if (!PhpType .isPrimitiveType (simpleType ) || PhpLanguageFeature .SCALAR_TYPE_HINTS .isSupported (element .getProject ()) || "array" .equalsIgnoreCase (simpleType ) || "callable" .equalsIgnoreCase (simpleType )) {
287
- String typeString = simpleType .endsWith ("]" ) ? "array" : this .getFieldTypeString (element , filterNullCaseInsensitive (element .getType ()));
309
+ String typeString = simpleType .endsWith ("]" ) ? "array" : this .getFieldTypeString (element , filterNullCaseInsensitive (element .getType ()), globalType );
288
310
if (!typeString .isEmpty ()) {
289
311
return typeString ;
290
312
}
@@ -293,8 +315,9 @@ private String convertTypeToString(@NotNull PhpNamedElement element, Set<String>
293
315
return null ;
294
316
}
295
317
296
- private String getFieldTypeString (PhpNamedElement element , @ NotNull PhpType type ) {
297
- return PhpDocUtil .getTypePresentation (this .pluginClass .getProject (), type , PhpCodeInsightUtil .findScopeForUseOperator (element ));
318
+ private String getFieldTypeString (PhpNamedElement element , @ NotNull PhpType type , Boolean globalType ) {
319
+ PhpPsiElement scope = (globalType ) ? PhpCodeInsightUtil .findScopeForUseOperator (element ) : null ;
320
+ return PhpDocUtil .getTypePresentation (this .pluginClass .getProject (), type , scope );
298
321
}
299
322
300
323
private static PhpType filterNullCaseInsensitive (PhpType filedType ) {
0 commit comments