diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml
index ef32d53de..c22b26d43 100644
--- a/resources/META-INF/plugin.xml
+++ b/resources/META-INF/plugin.xml
@@ -501,6 +501,13 @@
enabledByDefault="false"
level="WARNING"
implementationClass="com.magento.idea.magento2uct.inspections.php.api.PossibleDependencyOnImplDetails"/>
+
[1449] Called non-interface method (that is present in implementation).
+ +The purpose of this inspection is to find places where there is called a method that is not declared in the interface.
+ + diff --git a/resources/uct/bundle/inspection.properties b/resources/uct/bundle/inspection.properties index f9fb116a0..d51e8fdc2 100644 --- a/resources/uct/bundle/inspection.properties +++ b/resources/uct/bundle/inspection.properties @@ -37,6 +37,7 @@ inspection.displayName.ImplementedNonApiInterface=Implemented non Adobe Commerce inspection.displayName.ExtendedNonApiClass=Extended non Adobe Commerce API class inspection.displayName.InheritedNonApiInterface=Inherited non Adobe Commerce API interface inspection.displayName.PossibleDependencyOnImplDetails=Possible dependency on implementation details +inspection.displayName.CalledNonInterfaceMethod=Called non-interface method customCode.warnings.deprecated.1131=[1131] Extended class ''{0}'' that is @deprecated in the ''{1}'' customCode.warnings.deprecated.1132=[1132] Imported class ''{0}'' that is @deprecated in the ''{1}'' customCode.warnings.deprecated.1134=[1134] Used class ''{0}'' that is @deprecated in the ''{1}'' @@ -72,3 +73,4 @@ customCode.errors.api.1328=[1328] Implemented interface ''{0}'' is not marked as customCode.errors.api.1121=[1121] Extended class ''{0}'' is not marked as an API customCode.errors.api.1327=[1327] Inherited interface ''{0}'' is not marked as an API customCode.errors.api.1428=[1428] Possible dependency on implementation details. Consider using the interface ''{0}'' +customCode.errors.api.1449=[1449] Called non-interface method. Consider using only methods declared in ''{0}'' diff --git a/src/com/magento/idea/magento2uct/inspections/php/api/CalledNonInterfaceMethod.java b/src/com/magento/idea/magento2uct/inspections/php/api/CalledNonInterfaceMethod.java new file mode 100644 index 000000000..2667ec9f1 --- /dev/null +++ b/src/com/magento/idea/magento2uct/inspections/php/api/CalledNonInterfaceMethod.java @@ -0,0 +1,89 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2uct.inspections.php.api; + +import com.intellij.codeInspection.ProblemHighlightType; +import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.openapi.project.Project; +import com.jetbrains.php.PhpIndex; +import com.jetbrains.php.actions.PhpExpressionTypeProvider; +import com.jetbrains.php.lang.psi.elements.Method; +import com.jetbrains.php.lang.psi.elements.MethodReference; +import com.jetbrains.php.lang.psi.elements.PhpClass; +import com.magento.idea.magento2plugin.inspections.php.util.PhpClassImplementsInterfaceUtil; +import com.magento.idea.magento2uct.inspections.UctProblemsHolder; +import com.magento.idea.magento2uct.inspections.php.CallMethodInspection; +import com.magento.idea.magento2uct.packages.IssueSeverityLevel; +import com.magento.idea.magento2uct.packages.SupportedIssue; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; +import org.jetbrains.annotations.NotNull; + +public class CalledNonInterfaceMethod extends CallMethodInspection { + + private final PhpExpressionTypeProvider typeProvider = new PhpExpressionTypeProvider(); + + @Override + protected void execute( + final Project project, + final @NotNull ProblemsHolder problemsHolder, + final MethodReference methodReference, + final Method method + ) { + final PhpClass parentClass = method.getContainingClass(); + + if (parentClass == null) { + return; + } + final String informationHint = typeProvider.getInformationHint(methodReference); + + if (informationHint.isEmpty()) { + return; + } + final Collection