Skip to content

Commit 54d0cf0

Browse files
author
Vitaliy
authored
Merge branch '1.0.0-develop' into issue-45-plugin-method-generation
2 parents 735ee7d + d116462 commit 54d0cf0

File tree

31 files changed

+437
-86
lines changed

31 files changed

+437
-86
lines changed

resources/META-INF/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
<internalFileTemplate name="Magento Module Common Php Class"/>
157157
<internalFileTemplate name="Magento Observer Class"/>
158158
<internalFileTemplate name="Magento Module Events Xml"/>
159+
<internalFileTemplate name="Magento GraphQL Resolver Class"/>
159160
</extensions>
160161

161162
<extensions defaultExtensionNs="com.jetbrains.php">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">A resolver performs GraphQL request processing. In general, it is responsible
12+
for constructing a query, fetching data and performing any calculations, then transforming the fetched and
13+
calculated data into a GraphQL array format. Finally, it returns the results wrapped by a callable function.
14+
</font><br>
15+
</td>
16+
</tr>
17+
</table>
18+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
19+
<tr>
20+
<tr>
21+
<td><font face="verdana" size="-1">
22+
<a href="https://devdocs.magento.com/guides/v2.3/graphql/develop/resolvers.html">Read more</a> about GraphQL Resolver, including when those can be used.
23+
</font><br>
24+
</td>
25+
</tr>
26+
</tr>
27+
</table>
28+
</body>
29+
</html>

resources/fileTemplates/code/Magento GraphQL Resolver.php.html

Lines changed: 0 additions & 10 deletions
This file was deleted.

resources/fileTemplates/internal/Magento GraphQL Resolver Class.php.html

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,43 @@
66
-->
77
<html>
88
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">A resolver performs GraphQL request processing. In general, it is responsible
12+
for constructing a query, fetching data and performing any calculations, then transforming the fetched and
13+
calculated data into a GraphQL array format. Finally, it returns the results wrapped by a callable function.
14+
</font><br>
15+
</td>
16+
</tr>
17+
<tr>
18+
<td><font face="verdana" size="-1">A GraphQL resolver must implement interface Magento\Framework\GraphQl\Query\Resolver\BatchResolverInterface.
19+
This interface provides a way to resolve multiple branches/leaves at once (known as batching).
20+
Magento recommends using batch resolvers for queries because they improve performance by fetching information
21+
required to resolve multiple GraphQL requests with a single operation.
22+
</font><br>
23+
</td>
24+
</tr>
25+
<tr>
26+
<td><font face="verdana" size="-1">
27+
<a href="https://devdocs.magento.com/guides/v2.3/graphql/develop/resolvers.html">Read more</a> about GraphQL Resolver, including when those can be used.
28+
</font><br>
29+
</td>
30+
</tr>
31+
</table>
32+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
33+
<tr>
34+
<td colspan="3"><font face="verdana" size="-1">Template's variables:</font></td>
35+
</tr>
36+
<tr>
37+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAMESPACE}</b></font></nobr></td>
38+
<td width="10">&nbsp;</td>
39+
<td width="100%" valign="top"><font face="verdana" size="-1">Created PHP GraphQL resolver class namespace.</font></td>
40+
</tr>
41+
<tr>
42+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAME}</b></font></nobr></td>
43+
<td width="10">&nbsp;</td>
44+
<td width="100%" valign="top"><font face="verdana" size="-1">PHP class for the GraphQL resolver name.</font></td>
45+
</tr>
46+
</table>
947
</body>
10-
</html>
48+
</html>

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

Lines changed: 19 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import com.intellij.codeInspection.ProblemHighlightType;
99
import com.intellij.codeInspection.ProblemsHolder;
1010
import com.intellij.ide.highlighter.XmlFileType;
11-
import com.intellij.openapi.vfs.VfsUtil;
12-
import com.intellij.openapi.vfs.VirtualFile;
1311
import com.intellij.psi.*;
1412
import com.intellij.psi.search.GlobalSearchScope;
1513
import com.intellij.psi.util.PsiTreeUtil;
@@ -21,24 +19,21 @@
2119
import com.magento.idea.magento2plugin.bundles.InspectionBundle;
2220
import com.magento.idea.magento2plugin.indexes.PluginIndex;
2321
import com.magento.idea.magento2plugin.magento.files.ModuleDiXml;
24-
import com.magento.idea.magento2plugin.magento.files.ModuleXml;
2522
import com.magento.idea.magento2plugin.magento.packages.Package;
23+
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectory;
2624
import org.jetbrains.annotations.NotNull;
2725
import org.jetbrains.annotations.Nullable;
2826
import java.io.File;
29-
import java.net.MalformedURLException;
30-
import java.net.URL;
3127
import java.util.*;
28+
import com.intellij.openapi.util.Pair;
3229

3330
public class PluginDeclarationInspection extends PhpInspection {
3431

3532
@NotNull
3633
@Override
3734
public PsiElementVisitor buildVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
3835
return new XmlElementVisitor() {
39-
private final String moduleXmlFileName = ModuleXml.getInstance().getFileName();
4036
private InspectionBundle inspectionBundle = new InspectionBundle();
41-
private HashMap<String, VirtualFile> loadedFileHash = new HashMap<>();
4237
private final ProblemHighlightType errorSeverity = ProblemHighlightType.WARNING;
4338

4439
@Override
@@ -86,7 +81,7 @@ public void visitFile(PsiFile file) {
8681
}
8782

8883
String pluginTypeName = pluginTypeNameAttribute.getValue();
89-
String pluginTypeKey = pluginNameAttributeValue.concat("_").concat(pluginTypeName);
84+
String pluginTypeKey = pluginNameAttributeValue.concat(Package.VENDOR_MODULE_NAME_SEPARATOR).concat(pluginTypeName);
9085
if (targetPluginHash.containsKey(pluginTypeKey)) {
9186
problemsHolder.registerProblem(
9287
pluginTypeNameAttribute.getValueElement(),
@@ -96,12 +91,12 @@ public void visitFile(PsiFile file) {
9691
}
9792
targetPluginHash.put(pluginTypeKey, pluginTypeXmlTag);
9893

99-
List<HashMap<String, String>> modulesWithSamePluginName = fetchModuleNamesWhereSamePluginNameUsed(pluginNameAttributeValue, pluginTypeName, pluginIndex, file);
100-
for (HashMap<String, String> moduleEntry: modulesWithSamePluginName) {
101-
Map.Entry<String, String> module = moduleEntry.entrySet().iterator().next();
102-
String moduleName = module.getKey();
103-
String scope = module.getValue();
104-
String problemKey = pluginTypeKey.concat("_").concat(moduleName).concat("_").concat(scope);
94+
List<Pair<String, String>> modulesWithSamePluginName = fetchModuleNamesWhereSamePluginNameUsed(pluginNameAttributeValue, pluginTypeName, pluginIndex, file);
95+
for (Pair<String, String> moduleEntry: modulesWithSamePluginName) {
96+
String scope = moduleEntry.getFirst();
97+
String moduleName = moduleEntry.getSecond();
98+
String problemKey = pluginTypeKey.concat(Package.VENDOR_MODULE_NAME_SEPARATOR)
99+
.concat(moduleName).concat(Package.VENDOR_MODULE_NAME_SEPARATOR).concat(scope);
105100
if (!pluginProblems.containsKey(problemKey)){
106101
problemsHolder.registerProblem(
107102
pluginTypeNameAttribute.getValueElement(),
@@ -121,8 +116,8 @@ public void visitFile(PsiFile file) {
121116
}
122117
}
123118

124-
private List<HashMap<String, String>> fetchModuleNamesWhereSamePluginNameUsed(String pluginNameAttributeValue, String pluginTypeName, PluginIndex pluginIndex, PsiFile file) {
125-
List<HashMap<String, String>> modulesName = new ArrayList<>();
119+
private List<Pair<String, String>> fetchModuleNamesWhereSamePluginNameUsed(String pluginNameAttributeValue, String pluginTypeName, PluginIndex pluginIndex, PsiFile file) {
120+
List<Pair<String, String>> modulesName = new ArrayList<>();
126121
String currentFileDirectory = file.getContainingDirectory().toString();
127122
String currentFileFullPath = currentFileDirectory.concat(File.separator).concat(file.getName());
128123

@@ -184,65 +179,15 @@ private List<XmlTag> fetchPluginTagsFromPluginTag(XmlTag pluginXmlTag) {
184179
return result;
185180
}
186181

187-
private void addModuleNameWhereSamePluginUsed(List<HashMap<String, String>> modulesName, PsiFile indexedFile, String scope) {
188-
XmlTag moduleDeclarationTag = getModuleDeclarationTagByConfigFile(indexedFile);
189-
if (moduleDeclarationTag == null) return;
182+
private void addModuleNameWhereSamePluginUsed(
183+
List<Pair<String, String>> modulesName,
184+
PsiFile indexedFile,
185+
String scope
186+
) {
187+
String moduleName = GetModuleNameByDirectory.getInstance(problemsHolder.getProject())
188+
.execute(indexedFile.getContainingDirectory());
190189

191-
if (!moduleDeclarationTag.getName().equals("module")) {
192-
return;
193-
}
194-
XmlAttribute moduleNameAttribute = moduleDeclarationTag.getAttribute(ModuleXml.MODULE_ATTR_NAME);
195-
if (moduleNameAttribute == null) {
196-
return;
197-
}
198-
199-
HashMap<String, String> moduleEntry = new HashMap<>();
200-
201-
moduleEntry.put(moduleNameAttribute.getValue(), scope);
202-
modulesName.add(moduleEntry);
203-
}
204-
205-
@Nullable
206-
private XmlTag getModuleDeclarationTagByConfigFile(PsiFile file) {
207-
String fileDirectory = file.getContainingDirectory().toString();
208-
String fileArea = file.getContainingDirectory().getName();
209-
String moduleXmlFilePath = getModuleXmlFilePathByConfigFileDirectory(fileDirectory, fileArea);
210-
211-
VirtualFile virtualFile = getFileByPath(moduleXmlFilePath);
212-
if (virtualFile == null) return null;
213-
214-
PsiFile moduleDeclarationFile = PsiManager.getInstance(file.getProject()).findFile(virtualFile);
215-
XmlTag[] moduleDeclarationTags = getFileXmlTags(moduleDeclarationFile);
216-
if (moduleDeclarationTags == null) {
217-
return null;
218-
}
219-
return moduleDeclarationTags[0];
220-
}
221-
222-
@Nullable
223-
private VirtualFile getFileByPath(String moduleXmlFilePath) {
224-
if (loadedFileHash.containsKey(moduleXmlFilePath)) {
225-
return loadedFileHash.get(moduleXmlFilePath);
226-
}
227-
VirtualFile virtualFile;
228-
try {
229-
virtualFile = VfsUtil.findFileByURL(new URL(moduleXmlFilePath));
230-
} catch (MalformedURLException e) {
231-
return null;
232-
}
233-
if (virtualFile == null) {
234-
return null;
235-
}
236-
loadedFileHash.put(moduleXmlFilePath, virtualFile);
237-
return virtualFile;
238-
}
239-
240-
private String getModuleXmlFilePathByConfigFileDirectory(String fileDirectory, String fileArea) {
241-
String moduleXmlFile = fileDirectory.replace(fileArea, "").concat(moduleXmlFileName);
242-
if (fileDirectory.endsWith(Package.MODULE_BASE_AREA_DIR)) {
243-
moduleXmlFile = fileDirectory.concat(File.separator).concat(moduleXmlFileName);
244-
}
245-
return moduleXmlFile.replace("PsiDirectory:", "file:");
190+
modulesName.add(Pair.create(scope, moduleName));
246191
}
247192

248193
@Nullable

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class GraphQlResolverPhp implements ModuleFileInterface {
1111
public static String TEMPLATE = "Magento GraphQL Resolver Class";
1212
public static String DEFAULT_DIR = "Model";
13-
public static final String GRAPHQL_RESOLVER_TEMPLATE_NAME = "Magento GraphQL Resolver";
13+
public static final String GRAPHQL_RESOLVER_TEMPLATE_NAME = "Magento GraphQL Resolver Method Resolve";
1414

1515
private String fileName;
1616

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<type name="Magento\Backend\App\AbstractAction">
4+
<plugin name=<warning descr="The plugin name \"adminAuthentication\" for targeted \"Magento\Backend\App\AbstractAction\" class is already used in the module \"Magento_Backend\" (adminhtml scope). For more details see Inspection Description.">"adminAuthentication"</warning> type="Vendor\Module\Plugin\Authentication" />
5+
</type>
6+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<type name="Magento\CatalogRule\Model\Rule">
4+
<plugin name=<warning descr="The plugin name \"configurableChildValidation\" for targeted \"Magento\CatalogRule\Model\Rule\" class is already used in the module \"Magento_CatalogRuleConfigurable\" (crontab scope). For more details see Inspection Description.">"configurableChildValidation"</warning> type="Magento\CatalogRuleConfigurable\Plugin\CatalogRule\Model\Rule\Validation"/>
5+
</type>
6+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<config>
3+
<type name="Magento\Framework\View\Layout">
4+
<plugin name=<warning descr="The plugin name \"catalog-session-depersonalize\" for targeted \"Magento\Framework\View\Layout\" class is already used in the module \"Magento_Catalog\" (frontend scope). For more details see Inspection Description.">"catalog-session-depersonalize"</warning> type="Vendor\Module\Plugin\Layout" />
5+
</type>
6+
</config>

0 commit comments

Comments
 (0)