Skip to content

Commit becb816

Browse files
author
Vitaliy
authored
Merge branch '1.0.0-develop' into mftf-selector-fix-and-test-coverage
2 parents b723ad8 + c56f546 commit becb816

File tree

18 files changed

+148
-25
lines changed

18 files changed

+148
-25
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
2-
inspection.plugin.duplicateInOtherPlaces=The plugin name "{0}" for targeted "{1}" class is already used in the module "{2}" ({3} scope). For more details see Inspection Description.
2+
inspection.plugin.duplicateInOtherPlaces=The plugin name "{0}" for targeted "{1}" class is already used in the module "{2}" ({3} scope). For more details see Inspection Description.
3+
inspection.graphql.resolver.mustImplement=Class must implements any of the following interfaces: \\Magento\\Framework\\GraphQl\\Query\\ResolverInterface, \\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchResolverInterface, \\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchServiceContractResolverInterface

src/com/magento/idea/magento2plugin/inspections/php/GraphQlResolverInspection.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.jetbrains.php.lang.inspections.PhpInspection;
1313
import com.jetbrains.php.lang.psi.elements.PhpClass;
1414
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;
15+
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
1516
import com.magento.idea.magento2plugin.inspections.php.fix.PhpImplementResolverClassQuickFix;
1617
import com.magento.idea.magento2plugin.util.magento.graphql.GraphQlUsagesCollector;
1718
import com.magento.idea.magento2plugin.util.magento.graphql.GraphQlUtil;
@@ -21,7 +22,7 @@
2122

2223
public class GraphQlResolverInspection extends PhpInspection {
2324

24-
public static final String GraphQlResolverProblemDescription = "Class must implements \\Magento\\Framework\\GraphQl\\Query\\ResolverInterface";
25+
private final InspectionBundle inspectionBundle = new InspectionBundle();
2526

2627
@NotNull
2728
@Override
@@ -32,11 +33,13 @@ public void visitPhpClass(PhpClass resolverClass) {
3233
GraphQlUsagesCollector collector = new GraphQlUsagesCollector();
3334
results = collector.getGraphQLUsages(resolverClass);
3435
if (results.size() > 0 ) {
35-
if (GraphQlUtil.isResolver(resolverClass)) {
36+
if (!GraphQlUtil.isResolver(resolverClass)) {
3637
PsiElement currentClassNameIdentifier = resolverClass.getNameIdentifier();
3738
assert currentClassNameIdentifier != null;
3839
problemsHolder.registerProblem(currentClassNameIdentifier,
39-
GraphQlResolverProblemDescription,
40+
inspectionBundle.message(
41+
"inspection.graphql.resolver.mustImplement"
42+
),
4043
ProblemHighlightType.ERROR,
4144
new PhpImplementResolverClassQuickFix());
4245
}

src/com/magento/idea/magento2plugin/inspections/php/PluginInspection.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor;
2121
import com.magento.idea.magento2plugin.inspections.php.util.PhpClassImplementsInterfaceUtil;
2222
import com.magento.idea.magento2plugin.magento.files.Plugin;
23+
import com.magento.idea.magento2plugin.magento.packages.Package;
2324
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
2425
import com.magento.idea.magento2plugin.util.magento.plugin.GetTargetClassNamesByPluginClassName;
2526
import org.jetbrains.annotations.NotNull;
@@ -128,7 +129,7 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
128129
String declaredType = pluginMethodParameter.getDeclaredType().toString();
129130

130131
if (index == 1) {
131-
String targetClassFqn = "\\".concat(targetClassName);
132+
String targetClassFqn = Package.FQN_SEPARATOR.concat(targetClassName);
132133
if (!checkTypeIncompatibility(targetClassFqn, declaredType, phpIndex)) {
133134
problemsHolder.registerProblem(pluginMethodParameter, PhpBundle.message("inspection.wrong_param_type", new Object[]{declaredType, targetClassFqn}), ProblemHighlightType.ERROR);
134135
}
@@ -138,7 +139,8 @@ private void checkParametersCompatibility(Method pluginMethod, String pluginPref
138139
continue;
139140
}
140141
if (index == 2 && pluginPrefix.equals(Plugin.PluginType.around.toString())) {
141-
if (!checkTypeIncompatibility("callable", declaredType, phpIndex)) {
142+
if (!checkTypeIncompatibility(Plugin.CALLABLE_PARAM, declaredType, phpIndex) &&
143+
!checkTypeIncompatibility(Package.FQN_SEPARATOR.concat(Plugin.CLOSURE_PARAM), declaredType, phpIndex)) {
142144
problemsHolder.registerProblem(pluginMethodParameter, PhpBundle.message("inspection.wrong_param_type", new Object[]{declaredType, "callable"}), ProblemHighlightType.ERROR);
143145
}
144146
continue;

src/com/magento/idea/magento2plugin/inspections/xml/ObserverDeclarationInspection.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public void visitFile(PsiFile file) {
7171
}
7272

7373
List<XmlTag> targetObservers = fetchObserverTagsFromEventTag(eventXmlTag);
74+
if (targetObservers.isEmpty()) {
75+
continue;
76+
}
7477

7578
for (XmlTag observerXmlTag: targetObservers) {
7679
XmlAttribute observerNameAttribute = observerXmlTag.getAttribute("name");

src/com/magento/idea/magento2plugin/linemarker/php/GraphQlResolverUsageLineMarkerProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNu
3939
if (psiElement instanceof PhpClass) {
4040
List<? extends PsiElement> results;
4141

42-
if (GraphQlUtil.isResolver((PhpClass) psiElement)) {
42+
if (!GraphQlUtil.isResolver((PhpClass) psiElement)) {
4343
return;
4444
}
4545
GraphQlUsagesCollector collector = new GraphQlUsagesCollector();

src/com/magento/idea/magento2plugin/magento/files/GraphQlResolver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66

77
public class GraphQlResolver {
88
public static final String RESOLVER_INTERFACE = "\\Magento\\Framework\\GraphQl\\Query\\ResolverInterface";
9+
public static final String BATCH_RESOLVER_INTERFACE = "\\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchResolverInterface";
10+
public static final String BATCH_SERVICE_CONTRACT_RESOLVER_INTERFACE = "\\Magento\\Framework\\GraphQl\\Query\\Resolver\\BatchServiceContractResolverInterface";
911
public static final String CLASS_ARGUMENT = "class";
1012
}

src/com/magento/idea/magento2plugin/magento/files/Plugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class Plugin implements ModuleFileInterface {
1212
private static final String AROUND_METHOD_TEMPLATE_NAME = "Magento Plugin Around Method";
1313
private static final String AFTER_METHOD_TEMPLATE_NAME = "Magento Plugin After Method";
1414

15+
public static final String CALLABLE_PARAM = "callable";
16+
public static final String CLOSURE_PARAM = "Closure";
17+
1518
public enum PluginType {
1619
before,
1720
after,

src/com/magento/idea/magento2plugin/util/magento/graphql/GraphQlUtil.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@ public static GraphQLStringValue fetchResolverQuotedStringFromArgument(PsiElemen
4444
return argumentStringValue;
4545
}
4646

47-
public static boolean isResolver(PhpClass psiElement) {
47+
public static boolean isResolver(PhpClass psiElement) {
4848
PhpClass[] implementedInterfaces = psiElement.getImplementedInterfaces();
4949
for (PhpClass implementedInterface: implementedInterfaces) {
50-
if (!implementedInterface.getFQN().equals(GraphQlResolver.RESOLVER_INTERFACE)) {
51-
continue;
50+
if (implementedInterface.getFQN().equals(
51+
GraphQlResolver.RESOLVER_INTERFACE
52+
) || implementedInterface.getFQN().equals(
53+
GraphQlResolver.BATCH_RESOLVER_INTERFACE
54+
) || implementedInterface.getFQN().equals(
55+
GraphQlResolver.BATCH_SERVICE_CONTRACT_RESOLVER_INTERFACE
56+
)) {
57+
return true;
5258
}
53-
return false;
5459
}
55-
return true;
60+
return false;
5661
}
5762
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66
namespace Magento\Test;
77
use Magento\Framework\GraphQl\Query\InvalidInterface;
8-
class <error descr="Class must implements \Magento\Framework\GraphQl\Query\ResolverInterface">InvalidResolverTest</error> implements InvalidInterface
8+
9+
class ResolverTest implements InvalidInterface
910
{
1011
}
1112
?>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Test;
7+
class ResolverTest implements \Magento\Framework\GraphQl\Query\Resolver\BatchResolverInterface
8+
{
9+
}
10+
?>

0 commit comments

Comments
 (0)