Skip to content

Commit

Permalink
Merge pull request #448 from magento/445-NoninterceptableInterface
Browse files Browse the repository at this point in the history
445: Covered the NoninterceptableInterface case by plugin inspection …
  • Loading branch information
Vitaliy authored Jan 11, 2021
2 parents b240fac + 88827f3 commit 2e6a81e
Show file tree
Hide file tree
Showing 15 changed files with 526 additions and 209 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0).

## 3.0.4

### Fixed

- Overriding the interface that generates invalid php code
- Overriding a template from the base area
- Disabled the ability to create a plugin for a class that implements `\Magento\Framework\ObjectManager\NoninterceptableInterface`

### Added

- `NoninterceptableInterface` case warning to the plugin inspection

## 3.0.3

### Fixed
Expand Down
1 change: 1 addition & 0 deletions resources/magento2/inspection.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ inspection.graphql.resolver.fix.title=Select one of the following interface
inspection.graphql.schema.resolver.fix.family=Create GraphQL Resolver
inspection.plugin.error.nonPublicMethod=You can't declare a plugin for a not public method.
inspection.plugin.error.finalClass=You can't declare a plugin for a final class.
inspection.plugin.error.noninterceptableInterface=You can't declare a plugin for a class that implements Magento\\Framework\\ObjectManager\\NoninterceptableInterface.
inspection.plugin.error.finalMethod=You can't declare a plugin for a final method.
inspection.plugin.error.staticMethod=You can't declare a plugin for a static method.
inspection.plugin.error.constructMethod=You can't declare a plugin for a __construct method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import com.jetbrains.php.lang.psi.elements.PhpClass;
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.CreateAPluginDialog;
import com.magento.idea.magento2plugin.inspections.php.util.PhpClassImplementsNoninterceptableInterfaceUtil;
import com.magento.idea.magento2plugin.project.Settings;
import com.magento.idea.magento2plugin.util.GetFirstClassOfFile;
import com.magento.idea.magento2plugin.util.magento.plugin.IsPluginAllowedForMethod;
import com.magento.idea.magento2plugin.util.magento.plugin.IsPluginAllowedForMethodUtil;
import org.jetbrains.annotations.NotNull;

public class CreateAPluginAction extends DumbAwareAction {
public static final String ACTION_NAME = "Create a new Plugin for this method";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Plugin";
private final IsPluginAllowedForMethod isPluginAllowed;// NOPMD
private final GetFirstClassOfFile getFirstClassOfFile;
private Method targetMethod;
private PhpClass targetClass;
Expand All @@ -36,7 +36,6 @@ public class CreateAPluginAction extends DumbAwareAction {
*/
public CreateAPluginAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
this.isPluginAllowed = IsPluginAllowedForMethod.getInstance();
this.getFirstClassOfFile = GetFirstClassOfFile.getInstance();
}

Expand All @@ -55,6 +54,7 @@ public void update(final AnActionEvent event) {
if (phpClass == null
|| !(psiFile instanceof PhpFile)
|| phpClass.isFinal()
|| PhpClassImplementsNoninterceptableInterfaceUtil.execute(phpClass)
|| this.targetMethod == null
) {
this.setStatus(event, false);
Expand Down Expand Up @@ -110,13 +110,13 @@ private void fetchTargetMethod(
return;
}
if (element instanceof Method && element.getParent()
== phpClass && isPluginAllowed.check((Method) element)) {
== phpClass && IsPluginAllowedForMethodUtil.check((Method) element)) {
this.targetMethod = (Method) element;
return;
}
final PsiElement parent = element.getParent();
if (parent instanceof Method && parent.getParent()
== phpClass && isPluginAllowed.check((Method) parent)) {
== phpClass && IsPluginAllowedForMethodUtil.check((Method) parent)) {
this.targetMethod = (Method) parent;
}
}
Expand Down
Loading

0 comments on commit 2e6a81e

Please sign in to comment.