magento / magento/magento-coding-standard

Magento2\Sniffs\Legacy\RestrictedCodeSniff doesn't catch namespaced classes

Open
#444 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug Progress: ready for grooming
Dominant language
PHP
Stars
375
Forks
165
PR merge metrics
No merged PRs in 30d

Description

Preconditions
  1. Magento 2.4.5-p1
  2. Magento Coding Standard v29
Steps to reproduce
  1. Create a php file, where you include any namespaced class from restricted_classes.php for example \Magento\Framework\Serialize\Serializer\Serialize in the constructor or any other place
  2. Run code sniffer on that file.
Expected result
  1. Sniffer caught the class
Actual result
  1. Sniffer didn't catch the class
Notes

Registered tokens contain only partial values for classes, they transmit parts of this class in turn, Magento, then Framework, then Serialize, and so on, but the whole class is not transmitted. Therefore, the sniffer only works for classes that consist of a single word or are combined with an underscore _.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Magento2/Sniffs/Legacy/RestrictedCodeSniff.php and inspect the registered tokens referenced in the issue, then compare them with the fully qualified names in Magento2/Sniffs/Legacy/_files/restricted_classes.php. Run CodeSniffer against a PHP file using a namespaced restricted class such as Magento\Framework\Serialize\Serializer\Serialize; done means the sniffer reports that class.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.