Skip to content
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

Add sniff for Restricted Database Classes. #615

Merged
merged 1 commit into from
Jul 19, 2016

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 18, 2016

  • Added AbstractClassRestrictionsSniff class which can sniff for the use of (namespaced) classes. The abstract class does currently not support use statement aliased namespaces.
  • Refactored the AbstractFunctionRestrictionsSniff somewhat to make parts more reusable and extended the AbstractClassRestrictionsSniff from this class.
    • This refactoring includes a small efficiency improvement where the function regular expressions are no longer rebuild for every token, but only build once.
  • Added DB/RestrictedClassesSniff to actually sniff for the Restricted DB Classes.
  • Added extensive unit tests which test both the DB/RestrictedClassesSniff as well as the complete functionality of the Abstract class.

If at some point in the future the AbstractFunctionRestrictionsSniff would need to support namespaces too, this will not be too hard to do. Some functions would need to be moved from the AbstractClassRestrictionsSniff to the AbstractFunctionRestrictionsSniff and the functionname determination would need to start using them, but the underlying logic has already been build.

This is the sister-PR to #612 which covers the function sniffing for direct DB calls.

@jrfnl
Copy link
Member Author

jrfnl commented Jul 19, 2016

Rebased for merge conflict (also done for the others which were conflicting)

* Add `AbstractClassRestrictionsSniff` which can sniff for the use of (namespaced) classes. The abstract class does currently not support `use` statement aliased namespaces.
* Refactored the `AbstractFunctionRestrictionsSniff` somewhat to make parts more reusable and extended the `AbstractClassRestrictionsSniff` from this class.
	* This refactoring includes a small efficiency improvement where the function regular expressions are no longer rebuild for every token, but only build once.
* Add `DB/RestrictedClassesSniff` to actually sniff for the Restricted DB Classes.
* Added extensive unit tests which test both the `DB/RestrictedClassesSniff` as well as the complete functionality of the Abstract class.

If at some point in the future the `AbstractFunctionRestrictionsSniff` would need to support namespaces too, this will not be too hard to do. Some functions would need to be moved from the `AbstractClassRestrictionsSniff`  to the `AbstractFunctionRestrictionsSniff` and the the functionname determination would need to start using them, but the underlying logic has already been build.
@jrfnl jrfnl force-pushed the WPCS/feature/no-direct-db-class-calls branch from 0cf39c1 to 3b9ae92 Compare July 19, 2016 21:02
@JDGrimes JDGrimes added this to the 0.10.0 milestone Jul 19, 2016
@JDGrimes JDGrimes merged commit 48d909d into develop Jul 19, 2016
@JDGrimes JDGrimes deleted the WPCS/feature/no-direct-db-class-calls branch July 19, 2016 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants