Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop types inspections inside type tag #582

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,64 +153,72 @@
<directoryProjectConfigurator implementation="com.magento.idea.magento2plugin.project.ProjectDetector"/>

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

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

<localInspection language="XML" groupPath="XML"
shortName="ObserverDeclarationInspection"
displayName="Duplicated Observer Usage in events XML"
groupName="Magento 2"
bundle="magento2.inspection" key="inspection.displayName.ObserverDeclarationInspection"
groupBundle="magento2.inspection" groupKey="inspection.group.name"
enabledByDefault="true"
level="WARNING"
implementationClass="com.magento.idea.magento2plugin.inspections.xml.ObserverDeclarationInspection"/>

<localInspection language="XML" groupPath="XML"
shortName="PluginDeclarationInspection"
displayName="Duplicated Plugin Usage in di XML"
groupName="Magento 2"
bundle="magento2.inspection" key="inspection.displayName.PluginDeclarationInspection"
groupBundle="magento2.inspection" groupKey="inspection.group.name"
enabledByDefault="true"
level="WARNING"
implementationClass="com.magento.idea.magento2plugin.inspections.xml.PluginDeclarationInspection"/>

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

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

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

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

<localInspection language="XML" groupPath="XML"
shortName="InvalidDiTypeInspection"
bundle="magento2.inspection" key="inspection.displayName.InvalidDiTypeInspection"
groupBundle="magento2.inspection" groupKey="inspection.group.name"
enabledByDefault="true" level="WARNING"
implementationClass="com.magento.idea.magento2plugin.inspections.xml.InvalidDependencyInjectionTypeInspection"/>

<internalFileTemplate name="Magento Composer JSON"/>
<internalFileTemplate name="Magento Registration PHP"/>
<internalFileTemplate name="Magento Module XML"/>
Expand Down
22 changes: 22 additions & 0 deletions resources/inspectionDescriptions/InvalidDiTypeInspection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<html>
<body>
<p>
Validates if all types inside the &lt;type/&gt; tag of di.xml files contains valid classes,
interfaces, factories, proxies or virtual type names.
</p>
<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>
<p>This inspection supports next types:</p>
<ul>
<li>PHP classes</li>
<li>PHP interfaces</li>
<li>PHP classes or interfaces with added Factory or \Proxy suffixes</li>
<li>Magento 2 Virtual Types names</li>
</ul>
</body>
</html>
10 changes: 10 additions & 0 deletions resources/magento2/inspection.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
inspection.group.name=Magento 2
inspection.displayName.PluginInspection=Inspection for the Plugin declaration
inspection.displayName.ModuleDeclarationInRegistrationPhpInspection=Inspection for the Module declaration in the `registration.php` file
inspection.displayName.ObserverDeclarationInspection=Duplicated Observer Usage in events XML
inspection.displayName.PluginDeclarationInspection=Duplicated Plugin Usage in di XML
inspection.displayName.CacheableFalseInDefaultLayoutInspection=Inspection for disabled cache site-wide
inspection.displayName.ModuleDeclarationInModuleXmlInspection=Inspection for the Module declaration in the `etc/module.xml` file
inspection.displayName.AclResourceXmlInspection=Inspection for the Title XML required attribute in the `etc/acl.xml` file
inspection.displayName.WebApiServiceInspection=Inspection for the Web API XML service declaration
inspection.displayName.InvalidDiTypeInspection=Invalid type configuration in the `etc/di.xml` file
inspection.plugin.duplicateInSameFile=The plugin name already used in this file. For more details see Inspection Description.
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.
inspection.plugin.disabledPluginDoesNotExist=This plugin does not exist to be disabled.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.inspections.validator;

/**
* All Inspections validators should implement this validator.
*/
public interface InspectionValidator {

/**
* Validate if provided value acceptable by concrete validator implementation.
*
* @param value String
*
* @return boolean
*/
boolean validate(final String value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.inspections.validator;

public class NotEmptyValidator implements InspectionValidator {

@Override
public boolean validate(final String value) {
return value != null && !value.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.inspections.validator;

import com.intellij.openapi.project.Project;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;

public class PhpClassExistenceValidator implements InspectionValidator {

private final PhpIndex phpIndex;

public PhpClassExistenceValidator(final @NotNull Project project) {
phpIndex = PhpIndex.getInstance(project);
}

@Override
public boolean validate(final String value) {
if (value == null) {
return false;
}
final @NotNull Collection<PhpClass> classes = phpIndex.getClassesByFQN(value);
final @NotNull Collection<PhpClass> interfaces = phpIndex.getInterfacesByFQN(value);

return !classes.isEmpty() || !interfaces.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.inspections.validator;

import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.indexing.FileBasedIndex;
import com.magento.idea.magento2plugin.stubs.indexes.VirtualTypeIndex;
import java.util.Collection;
import org.jetbrains.annotations.NotNull;

public class VirtualTypeExistenceValidator implements InspectionValidator {

private final Project project;

public VirtualTypeExistenceValidator(final @NotNull Project project) {
this.project = project;
}

@Override
public boolean validate(final String value) {
if (value == null) {
return false;
}
final @NotNull Collection<String> virtualTypes = FileBasedIndex.getInstance().getValues(
VirtualTypeIndex.KEY,
value,
GlobalSearchScope.allScope(project)
);

return !virtualTypes.isEmpty();
}
}
Loading