Skip to content

Commit 3a93548

Browse files
Fixed issue with interface adding in the new line
1 parent 9be3aa5 commit 3a93548

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/com/magento/idea/magento2plugin/inspections/php/fix/PhpImplementResolverClassQuickFix.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.intellij.openapi.command.WriteCommandAction;
1111
import com.intellij.openapi.project.Project;
1212
import com.intellij.openapi.ui.DialogBuilder;
13+
import com.intellij.psi.codeStyle.CodeStyleManager;
1314
import com.intellij.psi.PsiElement;
1415
import com.jetbrains.php.lang.psi.PhpPsiElementFactory;
1516
import com.jetbrains.php.lang.psi.elements.PhpClass;
@@ -36,10 +37,16 @@ public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descri
3637
DialogBuilder dialogBox = createDialogBox(expectedInterfaceDropdown, project);
3738
if (dialogBox.showAndGet()) {
3839
String getSelectedInterface = expectedInterfaceDropdown.getSelectedItem().toString();
39-
PsiElement correctInterface = PhpPsiElementFactory.createImplementsList(project, getSelectedInterface);
40-
PhpClass graphQlResolverClass = (PhpClass) descriptor.getPsiElement().getParent();
41-
WriteCommandAction.writeCommandAction(project).run(() -> {
42-
graphQlResolverClass.getImplementsList().replace(correctInterface);
40+
final PsiElement erroredElement = descriptor.getPsiElement();
41+
final PsiElement correctInterface = PhpPsiElementFactory.createImplementsList(project, getSelectedInterface);
42+
final PhpClass graphQlResolverClass = (PhpClass) erroredElement.getParent();
43+
String[] implementedInterfaceNames = graphQlResolverClass.getInterfaceNames();
44+
WriteCommandAction.runWriteCommandAction(project, () -> {
45+
if (implementedInterfaceNames.length == 0) {
46+
graphQlResolverClass.getImplementsList().addAfter(correctInterface, erroredElement);
47+
} else {
48+
graphQlResolverClass.getImplementsList().replace(correctInterface);
49+
}
4350
});
4451
}
4552
}

0 commit comments

Comments
 (0)