Do not allow non class functions in a class file
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
I like the idea of this sniff but would it be overbearing? Would it be best if it was only a warning level item?
While I prefer classes to have no side effects and also no functions outside the class scope I do see this pattern used (misused?) often and I think fixing it would be burden for some projects and quite a rework might need to happen for a lot of them to resolve this.
Yes a warning level would be perfectly fine.