Skip to content

[New Rule] Proxies and interceptors MUST never be explicitly requested in constructors #18

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

Closed
lenaorobei opened this issue Jan 28, 2019 · 1 comment
Assignees
Labels
accepted New rule is accepted event: MageTestFest2019 MageTestFest contributions new rule New feature implementation Progress: good first issue Issues is easy to get started with technical guidelines The rule is based on Magento Technical Guidelines

Comments

@lenaorobei
Copy link
Contributor

lenaorobei commented Jan 28, 2019

Rule

Proxies and interceptors MUST never be explicitly requested in constructors.

Source - Magento Technical Guidelines

Description

Proxies are used for lazy-loading. Details on DevDocs.

Proxies should be configured via di.xml file.

<type name="FastLoading">
    <arguments>
        <argument name="slowLoading" xsi:type="object">SlowLoading\Proxy</argument>
    </arguments>
</type>

Plugins (interceptors) modify the behavior of public class functions by intercepting a function call and running code before, after, or around that function call. Details on DevDocs.

Plugins should be declared via di.xml file.

<config>
    <type name="{ObservedType}">
      <plugin name="{pluginName}" type="{PluginClassName}" sortOrder="1" disabled="false" />
    </type>
</config>

Implementation

Subscribe to the T_CLASS token and analyse __constructor arguments.

<severity>8</severity>
<type>warning</type>
@lenaorobei lenaorobei added proposal New rule proposal new rule New feature implementation labels Jan 28, 2019
@paliarush paliarush added accepted New rule is accepted and removed proposal New rule proposal labels Jan 29, 2019
@lenaorobei lenaorobei added the technical guidelines The rule is based on Magento Technical Guidelines label Feb 6, 2019
@lenaorobei lenaorobei added the Progress: good first issue Issues is easy to get started with label Mar 8, 2019
@larsroettig larsroettig self-assigned this Mar 8, 2019
@lenaorobei lenaorobei assigned maderlock and unassigned larsroettig Mar 8, 2019
@lenaorobei lenaorobei added the event: MageTestFest2019 MageTestFest contributions label Mar 8, 2019
@maderlock
Copy link
Contributor

After discussion in pull-request, the scope of this has changed slightly:

  1. This will output errors instead of warnings
  2. Rather than detect plugins, the interceptors themselves will be detected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted New rule is accepted event: MageTestFest2019 MageTestFest contributions new rule New feature implementation Progress: good first issue Issues is easy to get started with technical guidelines The rule is based on Magento Technical Guidelines
Projects
None yet
Development

No branches or pull requests

4 participants