WordPress / WordPress/WordPress-Coding-Standards
WP/AlternativeFunctions: fails to detect namespaced and class-based function/constant calls
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
The sniff WordPress.WP.AlternativeFunctions checks for function calls and constants in the first parameter of file_get_contents() without differentiating global and non-global function calls and constants. It also fails to differentiate between functions/constants, and class methods/class constants. This leads to false negatives in some cases.
All the examples below don't trigger the sniff, but they should:
file_get_contents(MyNamespace\WP_Upload_Dir()['path'] . 'subdir/file.inc');
file_get_contents(\MyNamespace\WP_Upload_Dir()['path'] . 'subdir/file.inc');
file_get_contents(namespace\WP_Upload_Dir()['path'] . 'subdir/file.inc');
file_get_contents(MyNamespace\ABSPATH . 'wp-admin/css/some-file.css');
file_get_contents(\MyNamespace\ABSPATH . 'wp-admin/css/some-file.css');
file_get_contents(namespace\ABSPATH . 'wp-admin/css/some-file.css');
file_get_contents(MyClass::wp_upload_dir() . 'subdir/file.inc');
file_get_contents($this->wp_upload_dir() . 'subdir/file.inc');
file_get_contents(MyClass::ABSPATH . 'subdir/file.inc');
file_get_contents($this->ABSPATH . 'subdir/file.inc');
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 at the WordPress.WP.AlternativeFunctions sniff and reproduce the listed file_get_contents() examples. Trace how its first parameter is classified, distinguishing namespaced and global functions/constants from class methods, class constants, and $this-> calls. Done when the examples trigger the intended detection without introducing false positives.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100