magento / magento/magento-coding-standard

Add description why php functions marked as discouraged and give alternatives

Open
#102 6 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Preconditions

N/A

Steps to reproduce
  1. Make PR to Magento with changed file, that don't have like about ignoring discouraged pathinfo function or run magneto coding standard against some file.
Expected result
  1. You should get understandable message what's wrong with your code, message The use of function pathinfo() is discouraged isn't clean enough
  2. For case when some function marked as discouraged - there should be some information that shows reason of it, what is best practice
  3. That's actually relevant for all rules

Good example: https://github.com/extdn/extdn-phpcs/blob/master/Extdn/Sniffs/Classes/StrictTypesSniff.md

Actual result
  1. I'm getting result like this:
    Errors is quite clear, but not warnings
PHP Code Sniffer detected 2 violation(s): 

FILE: /var/www/html/app/code/Magento/Deploy/Service/DeployPackage.php
----------------------------------------------------------------------
FOUND 2 ERRORS AND 2 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------
 109 | ERROR   | [x] Missing short description
 110 | ERROR   | [x] There must be exactly one blank line before tags
 224 | WARNING | [ ] The use of function pathinfo() is discouraged
 225 | WARNING | [ ] The use of function pathinfo() is discouraged
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------



Failed asserting that 2 matches expected 0.

Related question on stack overflow, answer not seems to me correct.
https://magento.stackexchange.com/questions/192978/the-use-of-function-pathinfo-is-discouraged-magento-2

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 by inspecting the PHP CodeSniffer rules that emit discouraged-function warnings, including the pathinfo() message, and compare their guidance with the linked Extdn StrictTypesSniff documentation. Done means affected warnings explain why the function or rule is discouraged and identify a preferred alternative, with the approach applied consistently where feasible.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.