magento / magento/magento-coding-standard
Is there any reason why function `parse_url` is Discouraged?
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 375
- Forks
- 165
- PR merge metrics
- No merged PRs in 30d
Description
When I use parse_url() function - phpcs shows me the following error:
39 | WARNING | The use of function parse_url() is discouraged
Is there any reason why I should not use this function?
I don't see any.
Do I have any alternative functions to use?
It was possible to use \Zend\Uri\Http but it's removed starting from Magento 2.4.1.
Can I somehow remove it from the Discouraged function list using a custom ruleset?
Seems like I can't.
Update: I have disabled it using the following sentence, but not sure whether it right way
<rule ref="Magento2.Functions.DiscouragedFunction">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="!parse_url" value="null"/>
</property>
</properties>
</rule>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with Magento2/Sniffs/Functions/DiscouragedFunctionSniff.php at the referenced line and review how forbiddenFunctions is configured. Determine whether the parse_url warning and the shown custom-ruleset override are documented; done means the rationale, alternatives, and supported configuration behavior are clearly recorded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Documentation
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100