-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forbidden Classes Sniff #1360
base: 3.0
Are you sure you want to change the base?
Forbidden Classes Sniff #1360
Conversation
…es found inside a function declaration (ref #1360)
…ments/extends statements
Latest commit supports multi-import use-statements. Also, the usage types can be configured, in which contexts the sniff should apply to (e.g. if you don't want to apply the check to extends/implements statements). Support for traits/extends/implements not finished yet. |
Do you plan to check for forbidden classes appearance in PHPDoc?
From https://github.com/squizlabs/PHP_CodeSniffer/blob/2.8.0/CodeSniffer.php#L1529 it looks like you can call |
Now supports trait imports, implements and extends. @orlangur Haven't thought about PHPDoc yet. Will give it a try next. |
PHPDoc support as requested. Do I need to check some more PHPDoc tags as the ones implemented? Also added the check for function return types, which have been added in PHP7. Would be nice to get some feedback from the devs, especially how to configure sniffs in unit-tests. The suggested |
See In your class extended from this one you should do something like
|
@orlangur Unfortunately not in the 3.0 version branch :( |
You're right! On the first glance it looks to me that unlike the So, technically you can specify those global keys in |
Hey guys! I know this PR is a bit old already but seems to be still mergeable. What is missing for it? Can I support you somehow? |
Curious about this as well. Anything else needed before it can be merged in? |
The biggest issue with merging in new sniffs is always ensuring they've covered all the edge cases so they don't get merged in and then immediately produce a series of bug reports that cause development to slow down. If you (or anyone) can grab the sniff and test it on your projects, that would be very helpful. |
Hello, would you be interested in a code sniff to forbid usage of certain classes? I'm writing that one for a project where we want to keep developers from using certain classes (e.g. deprcated ones) and suggesting alternatives instead. It looks for class usages in:
Then resolves the fully qualified class name and checks it against the configurable forbidden classes list. To resolve the fully qualified name, the sniff is taking namespace, class imports and namespace/class aliases into account. So it heavily relies on the namespace features of PHP and therefore I target the 3.0 branch with this PR.
Current limitations are:
Also, and that's something where you could help me, I'm wondering how I can configure the $forbiddenClasses parameter for the unit tests. Currently the forbidden class used for testing is hardcoded in the sniff, which is certainly not the best solution.
I hope to get some feedback!