Skip to content

Commit 2256a83

Browse files
Developed types inspections inside Type tag, covered by testcases
1 parent a622f2a commit 2256a83

File tree

18 files changed

+544
-14
lines changed

18 files changed

+544
-14
lines changed

resources/META-INF/plugin.xml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,57 +153,65 @@
153153
<directoryProjectConfigurator implementation="com.magento.idea.magento2plugin.project.ProjectDetector"/>
154154

155155
<localInspection language="PHP" groupPath="PHP"
156-
shortName="PluginInspection" displayName="Inspection for the Plugin declaration"
157-
groupName="Magento 2"
156+
shortName="PluginInspection"
157+
bundle="magento2.inspection" key="inspection.displayName.PluginInspection"
158+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
158159
enabledByDefault="true"
159160
level="ERROR"
160161
implementationClass="com.magento.idea.magento2plugin.inspections.php.PluginInspection"/>
161162

162163
<localInspection language="PHP" groupPath="PHP"
163164
shortName="ModuleDeclarationInRegistrationPhpInspection"
164-
displayName="Inspection for the Module declaration in the `registration.php` file"
165-
groupName="Magento 2"
165+
bundle="magento2.inspection" key="inspection.displayName.ModuleDeclarationInRegistrationPhpInspection"
166+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
166167
enabledByDefault="true"
167168
level="ERROR"
168169
implementationClass="com.magento.idea.magento2plugin.inspections.php.ModuleDeclarationInRegistrationPhpInspection"/>
169170

170171
<localInspection language="XML" groupPath="XML"
171172
shortName="ObserverDeclarationInspection"
172-
displayName="Duplicated Observer Usage in events XML"
173-
groupName="Magento 2"
173+
bundle="magento2.inspection" key="inspection.displayName.ObserverDeclarationInspection"
174+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
174175
enabledByDefault="true"
175176
level="WARNING"
176177
implementationClass="com.magento.idea.magento2plugin.inspections.xml.ObserverDeclarationInspection"/>
177178

178179
<localInspection language="XML" groupPath="XML"
179180
shortName="PluginDeclarationInspection"
180-
displayName="Duplicated Plugin Usage in di XML"
181-
groupName="Magento 2"
181+
bundle="magento2.inspection" key="inspection.displayName.PluginDeclarationInspection"
182+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
182183
enabledByDefault="true"
183184
level="WARNING"
184185
implementationClass="com.magento.idea.magento2plugin.inspections.xml.PluginDeclarationInspection"/>
185186

186187
<localInspection language="XML" groupPath="XML"
187188
shortName="CacheableFalseInDefaultLayoutInspection"
188-
displayName="Inspection for disabled cache site-wide"
189-
groupName="Magento 2"
189+
bundle="magento2.inspection" key="inspection.displayName.CacheableFalseInDefaultLayoutInspection"
190+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
190191
enabledByDefault="true" level="WARNING"
191192
implementationClass="com.magento.idea.magento2plugin.inspections.xml.CacheableFalseInDefaultLayoutInspection"/>
192193

193194
<localInspection language="XML" groupPath="XML"
194195
shortName="ModuleDeclarationInModuleXmlInspection"
195-
displayName="Inspection for the Module declaration in the `etc/module.xml` file"
196-
groupName="Magento 2"
196+
bundle="magento2.inspection" key="inspection.displayName.ModuleDeclarationInModuleXmlInspection"
197+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
197198
enabledByDefault="true" level="ERROR"
198199
implementationClass="com.magento.idea.magento2plugin.inspections.xml.ModuleDeclarationInModuleXmlInspection"/>
199200

200201
<localInspection language="XML" groupPath="XML"
201202
shortName="AclResourceXmlInspection"
202-
displayName="Inspection for the Title XML required attribute in the `etc/acl.xml` file"
203-
groupName="Magento 2"
203+
bundle="magento2.inspection" key="inspection.displayName.AclResourceXmlInspection"
204+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
204205
enabledByDefault="true" level="ERROR"
205206
implementationClass="com.magento.idea.magento2plugin.inspections.xml.AclResourceXmlInspection"/>
206207

208+
<localInspection language="XML" groupPath="XML"
209+
shortName="InvalidDiTypeInspection"
210+
bundle="magento2.inspection" key="inspection.displayName.InvalidDiTypeInspection"
211+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
212+
enabledByDefault="true" level="WARNING"
213+
implementationClass="com.magento.idea.magento2plugin.inspections.xml.InvalidDependencyInjectionTypeInspection"/>
214+
207215
<internalFileTemplate name="Magento Composer JSON"/>
208216
<internalFileTemplate name="Magento Registration PHP"/>
209217
<internalFileTemplate name="Magento Module XML"/>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<p>
10+
Validates if all types inside the &lt;type/&gt; tag of di.xml files contains valid classes,
11+
interfaces, factories, proxies or virtual type names.
12+
</p>
13+
<p>This inspection checks name attribute of the &lt;type/&gt; tag and all arguments recursively which has xsi:type attribute value as object.</p>
14+
<p>This inspection supports next types:</p>
15+
<ul>
16+
<li>PHP classes</li>
17+
<li>PHP interfaces</li>
18+
<li>PHP classes or interfaces with added Factory or \Proxy suffixes</li>
19+
<li>Magento 2 Virtual Types names</li>
20+
</ul>
21+
</body>
22+
</html>

resources/magento2/inspection.properties

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
inspection.group.name=Magento 2
2+
inspection.displayName.PluginInspection=Inspection for the Plugin declaration
3+
inspection.displayName.ModuleDeclarationInRegistrationPhpInspection=Inspection for the Module declaration in the `registration.php` file
4+
inspection.displayName.ObserverDeclarationInspection=Duplicated Observer Usage in events XML
5+
inspection.displayName.PluginDeclarationInspection=Duplicated Plugin Usage in di XML
6+
inspection.displayName.CacheableFalseInDefaultLayoutInspection=Inspection for disabled cache site-wide
7+
inspection.displayName.ModuleDeclarationInModuleXmlInspection=Inspection for the Module declaration in the `etc/module.xml` file
8+
inspection.displayName.AclResourceXmlInspection=Inspection for the Title XML required attribute in the `etc/acl.xml` file
9+
inspection.displayName.InvalidDiTypeInspection=Invalid type configuration in the `etc/di.xml` file
110
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
211
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.
312
inspection.plugin.disabledPluginDoesNotExist=This plugin does not exist to be disabled.
@@ -22,3 +31,5 @@ inspection.moduleDeclaration.warning.wrongModuleName=Provided module name "{0}"
2231
inspection.moduleDeclaration.fix=Fix module name
2332
inspection.aclResource.error.missingAttribute=Attribute "{0}" is required
2433
inspection.aclResource.error.idAttributeCanNotBeEmpty=Attribute value "{0}" can not be empty
34+
inspection.warning.class.does.not.exist=The class "{0}" doesn't exist
35+
inspection.error.idAttributeCanNotBeEmpty=Attribute value "{0}" can not be empty
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.inspections.validator;
7+
8+
/**
9+
* All Inspections validators should implement this validator.
10+
*/
11+
public interface InspectionValidator {
12+
13+
/**
14+
* Validate if provided value acceptable by concrete validator implementation.
15+
*
16+
* @param value String
17+
*
18+
* @return boolean
19+
*/
20+
boolean validate(final String value);
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.inspections.validator;
7+
8+
public class NotEmptyValidator implements InspectionValidator {
9+
10+
@Override
11+
public boolean validate(final String value) {
12+
return value != null && !value.isEmpty();
13+
}
14+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.inspections.validator;
7+
8+
import com.intellij.openapi.project.Project;
9+
import com.jetbrains.php.PhpIndex;
10+
import com.jetbrains.php.lang.psi.elements.PhpClass;
11+
import java.util.Collection;
12+
import org.jetbrains.annotations.NotNull;
13+
14+
public class PhpClassExistenceValidator implements InspectionValidator {
15+
16+
private final PhpIndex phpIndex;
17+
18+
public PhpClassExistenceValidator(final @NotNull Project project) {
19+
phpIndex = PhpIndex.getInstance(project);
20+
}
21+
22+
@Override
23+
public boolean validate(final String value) {
24+
if (value == null) {
25+
return false;
26+
}
27+
final @NotNull Collection<PhpClass> classes = phpIndex.getClassesByFQN(value);
28+
final @NotNull Collection<PhpClass> interfaces = phpIndex.getInterfacesByFQN(value);
29+
30+
return !classes.isEmpty() || !interfaces.isEmpty();
31+
}
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.inspections.validator;
7+
8+
import com.intellij.openapi.project.Project;
9+
import com.intellij.psi.search.GlobalSearchScope;
10+
import com.intellij.util.indexing.FileBasedIndex;
11+
import com.magento.idea.magento2plugin.stubs.indexes.VirtualTypeIndex;
12+
import java.util.Collection;
13+
import org.jetbrains.annotations.NotNull;
14+
15+
public class VirtualTypeExistenceValidator implements InspectionValidator {
16+
17+
private final Project project;
18+
19+
public VirtualTypeExistenceValidator(final @NotNull Project project) {
20+
this.project = project;
21+
}
22+
23+
@Override
24+
public boolean validate(final String value) {
25+
if (value == null) {
26+
return false;
27+
}
28+
final @NotNull Collection<String> virtualTypes = FileBasedIndex.getInstance().getValues(
29+
VirtualTypeIndex.KEY,
30+
value,
31+
GlobalSearchScope.allScope(project)
32+
);
33+
34+
return !virtualTypes.isEmpty();
35+
}
36+
}

0 commit comments

Comments
 (0)