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

Never Extend from Magento\Framework\App\Helper\AbstractHelper #60

Open
larsroettig opened this issue Aug 6, 2018 · 2 comments
Open

Comments

@larsroettig
Copy link
Contributor

Rule

Never Extend from Magento\Framework\App\Helper\AbstractHelper

Reason

The AbstractHelper has many dependy that you never need for your helper implementation.
Also it breacks your helper if you use the ScopeConfigInterface and upgrade 2.1 to 2.2.

Implementation

@davidverholen
Copy link

there is one limitation if you do not extend it (although I totally agree with you, best case do not use helpers at all anymore).

\Magento\Framework\View\TemplateEngine\Php::helper($className) throws an Exception if it is not extended from AbstractHelper.

Before view models have been introduced this function could save a lot of time in some cases. I'm not proud of it but we might still have 1 or 2 of them in older code.

@jissereitsma
Copy link
Contributor

True. I would rather say that a helper should not exist at all or that the constructor should not be overridden. You could define a helper that only extends from the parent, just for the sake of using the helper in PHTML templates. But extending the constructor of a helper-that-inherits-from-parent leads to the mess that @larsroettig describes. So maybe we flag it if it does NOT match the following:

  • A helper class that does not extend from any other class.
  • A helper class that extends a parent but does not override the constructor.

And the notes can tell anyway that helpers are deprecated and it is better to create a specific class per set of helper-methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants