WordPress / WordPress/WordPress-Coding-Standards
Do not allow non class functions in a class file
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
Is your feature request related to a problem?
When a file contains a class, it should not allow any functions that are outside of this class.
Since WPCS requires renaming files to include the class name, I think it would be consistent to not allow any functions that are not part of this class to be in this file.
Describe the solution you'd like
file: class-my-test.php
class my_test {
}
function do_something() {
echo "hello";
}
Should get flagged for do_something, as its the file for my_test
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
Search the PHP_CodeSniffer rules for the check that enforces class-file naming and trace how class and function declarations are inspected. Add coverage for a file containing a class plus an unrelated global function, with completion defined as that function being flagged while class members remain allowed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100