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,15 @@ 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 = i != 0 ;
225
+ String typeHint = this .getTypeHint (element , globalType );
208
226
if (typeHint != null && !typeHint .isEmpty ()) {
209
227
buf .append (typeHint ).append (' ' );
210
228
}
@@ -257,21 +275,20 @@ protected String getReturnVariables(@NotNull Plugin.PluginType type) {
257
275
}
258
276
259
277
@ Nullable
260
- private String getTypeHint (@ NotNull PhpNamedElement element ) {
278
+ private String getTypeHint (@ NotNull PhpNamedElement element , Boolean globalType ) {
261
279
PhpType filedType = element .getType ().global (this .pluginClass .getProject ());
262
280
Set <String > typeStrings = filedType .getTypes ();
263
281
String typeString = null ;
264
282
if (typeStrings .size () == 1 ) {
265
- typeString = this .convertTypeToString (element , typeStrings );
283
+ typeString = this .convertTypeToString (element , typeStrings , globalType );
266
284
}
267
285
268
286
if (typeStrings .size () == 2 ) {
269
287
PhpType filteredNullType = filterNullCaseInsensitive (filedType );
270
288
if (filteredNullType .getTypes ().size () == 1 ) {
289
+ typeString = this .convertTypeToString (element , filteredNullType .getTypes (), globalType );
271
290
if (PhpLanguageFeature .NULLABLES .isSupported (element .getProject ())) {
272
- typeString = "?" + this .convertTypeToString (element , filteredNullType .getTypes ());
273
- } else {
274
- typeString = this .convertTypeToString (element , filteredNullType .getTypes ());
291
+ typeString = "?" + typeString ;
275
292
}
276
293
}
277
294
}
@@ -280,11 +297,11 @@ private String getTypeHint(@NotNull PhpNamedElement element) {
280
297
}
281
298
282
299
@ Nullable
283
- private String convertTypeToString (@ NotNull PhpNamedElement element , Set <String > typeStrings ) {
300
+ private String convertTypeToString (@ NotNull PhpNamedElement element , Set <String > typeStrings , Boolean globalType ) {
284
301
String simpleType = typeStrings .iterator ().next ();
285
302
simpleType = StringUtil .trimStart (simpleType , "\\ " );
286
303
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 ()));
304
+ String typeString = simpleType .endsWith ("]" ) ? "array" : this .getFieldTypeString (element , filterNullCaseInsensitive (element .getType ()), globalType );
288
305
if (!typeString .isEmpty ()) {
289
306
return typeString ;
290
307
}
@@ -293,8 +310,9 @@ private String convertTypeToString(@NotNull PhpNamedElement element, Set<String>
293
310
return null ;
294
311
}
295
312
296
- private String getFieldTypeString (PhpNamedElement element , @ NotNull PhpType type ) {
297
- return PhpDocUtil .getTypePresentation (this .pluginClass .getProject (), type , PhpCodeInsightUtil .findScopeForUseOperator (element ));
313
+ private String getFieldTypeString (PhpNamedElement element , @ NotNull PhpType type , Boolean globalType ) {
314
+ PhpPsiElement scope = (globalType ) ? PhpCodeInsightUtil .findScopeForUseOperator (element ) : null ;
315
+ return PhpDocUtil .getTypePresentation (this .pluginClass .getProject (), type , scope );
298
316
}
299
317
300
318
private static PhpType filterNullCaseInsensitive (PhpType filedType ) {
0 commit comments