magento-coding-standard icon indicating copy to clipboard operation
magento-coding-standard copied to clipboard

RestrictedCodeSniff suggests Laminas\Filter\FilterInterface, which is not required by Magento 2.4.5-p1 anymore

Open norgeindian opened this issue 3 years ago • 7 comments
trafficstars

Preconditions

  1. Magento 2.4.5-p1
  2. Magento Coding Standard, 26

Steps to reproduce

  1. Create a file, where you include \Zend_Filter_Interface in the constructor
  2. Run vendor/bin/phpcs --standard=dev/tests/static/framework/Magento on that file.

Expected result

  1. RestrictedCodeSniff should suggest a class, which exists in a clean Magento instance

Actual result

  1. The following error comes up: ERROR | Class 'Zend_Filter_Interface' is restricted in XXX. Suggested replacement: Laminas\Filter\FilterInterface

norgeindian avatar Nov 18 '22 10:11 norgeindian

Hi @norgeindian. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this


m2-assistant[bot] avatar Nov 18 '22 10:11 m2-assistant[bot]

Hi @norgeindian, Could you please provide us an example of such behavior, and what would you expect?

ihor-sviziev avatar Apr 13 '23 11:04 ihor-sviziev

@ihor-sviziev , my class looks like this:

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Zend_Filter_Interface;

class Top extends Template
{
    protected Zend_Filter_Interface $templateProcessor;

    public function __construct(
        Context $context,
        Zend_Filter_Interface $templateProcessor,
        array $data = []
    ) {
        $this->templateProcessor = $templateProcessor;
        $this->helper            = $helper;
        parent::__construct($context, $data);
    }

Like I said, as soon as I run vendor/bin/phpcs --standard=dev/tests/static/framework/Magento I get the following error message:

ERROR | Class 'Zend_Filter_Interface' is restricted in XXX. Suggested replacement: Laminas\Filter\FilterInterface

But since Magento 2.4.5-p1, Laminas is not included anymore by the Magento Core. So I would expect to get a suggestion about a model, which is actually included and can be used.

norgeindian avatar Aug 01 '23 08:08 norgeindian

@norgeindian the laminas filter is actually included in Magento 2.4.6 and 2.4.6-p1, and your custom extension can also add to requreiments the package you need https://github.com/magento/magento2/blob/2.4.6-p1/composer.json#L56 https://github.com/magento/magento2/blob/2.4.6/composer.json#L56

ihor-sviziev avatar Aug 01 '23 12:08 ihor-sviziev

@ihor-sviziev , thanks for pointing that out, but it's not included in any 2.4.5 version (see https://github.com/magento/magento2/blob/2.4.5-p4/composer.json). This is why this hint is misleading for these versions. Do you see any good solution for that in general? Maybe the coding standard should then be required in a fixed version in the root composer.json of magento/project-community-edition?

norgeindian avatar Sep 11 '23 07:09 norgeindian

@ihor-sviziev , what's your opinion here?

norgeindian avatar Oct 09 '23 07:10 norgeindian

@norgeindian in my opinion, if your extension depends on some laminas library, it should declare such dependence in require section. Otherwise you'll see such errors. I don't think this should be somehow accepted to coding standard, not through dependency (which coding standard don't have) not through additional sniff.

ihor-sviziev avatar Oct 09 '23 07:10 ihor-sviziev