Skip to content

Commit dc5041f

Browse files
author
Vitaliy
authored
Merge pull request #582 from bohdan-harniuk/567-develop-types-inspections-inside-type-tag
Develop types inspections inside type tag
2 parents c267602 + bb64f30 commit dc5041f

File tree

22 files changed

+596
-29
lines changed

22 files changed

+596
-29
lines changed

resources/META-INF/plugin.xml

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,64 +153,72 @@
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

207208
<localInspection language="XML" groupPath="XML"
208209
shortName="WebApiServiceInspection"
209-
displayName="Inspection for the Web API XML service declaration"
210-
groupName="Magento 2"
210+
bundle="magento2.inspection" key="inspection.displayName.WebApiServiceInspection"
211+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
211212
enabledByDefault="true" level="WARNING"
212213
implementationClass="com.magento.idea.magento2plugin.inspections.xml.WebApiServiceInspection"/>
213214

215+
<localInspection language="XML" groupPath="XML"
216+
shortName="InvalidDiTypeInspection"
217+
bundle="magento2.inspection" key="inspection.displayName.InvalidDiTypeInspection"
218+
groupBundle="magento2.inspection" groupKey="inspection.group.name"
219+
enabledByDefault="true" level="WARNING"
220+
implementationClass="com.magento.idea.magento2plugin.inspections.xml.InvalidDependencyInjectionTypeInspection"/>
221+
214222
<internalFileTemplate name="Magento Composer JSON"/>
215223
<internalFileTemplate name="Magento Registration PHP"/>
216224
<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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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.WebApiServiceInspection=Inspection for the Web API XML service declaration
10+
inspection.displayName.InvalidDiTypeInspection=Invalid type configuration in the `etc/di.xml` file
111
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
212
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.
313
inspection.plugin.disabledPluginDoesNotExist=This plugin does not exist to be disabled.
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)