Download the PHP package sirbrillig/phpcs-no-get-current-user without Composer
On this page you can find all versions of the php package sirbrillig/phpcs-no-get-current-user. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sirbrillig/phpcs-no-get-current-user
More information about sirbrillig/phpcs-no-get-current-user
Files in sirbrillig/phpcs-no-get-current-user
Package phpcs-no-get-current-user
Short Description A phpcs sniff to disallow get_current_user.
License BSD-2-Clause
Informations about the package phpcs-no-get-current-user
NoGetCurrentUser
A phpcs sniff to disallow using get_current_user()
.
Particularly when using a PHP framework like WordPress, it's very unlikely that most code will want to use the PHP function get_current_user()
. It can also easily be confused with other framework functions like WordPress's wp_get_current_user()
. This sniff makes using the function an error, although legitimate uses can still be made if the sniff is disabled for specific lines.
Installation
To use these rules in a project which is set up using composer, we recommend using the phpcodesniffer-composer-installer library which will automatically use all installed standards in the current project with the composer type phpcodesniffer-standard
when you run phpcs.
Configuration
When installing sniff standards in a project, you edit a phpcs.xml
file with the rule
tag inside the ruleset
tag. The ref
attribute of that tag should specify a standard, category, sniff, or error code to enable. It’s also possible to use these tags to disable or modify certain rules. The official annotated file explains how to do this.
Sniff Codes
There is one sniff code that is reported by this sniff.
NoGetCurrentUser.Disallowed.NoGetCurrentUser.Found
In any given file, you can use phpcs comments to disable these sniffs. For example:
For a whole file, you can ignore a sniff like this:
Usage
Most editors have a phpcs plugin available, but you can also run phpcs manually. To run phpcs on a file in your project, just use the command-line as follows (the -s
causes the sniff code to be shown, which is very important for learning about an error).
See Also
- VariableAnalysis: Find undefined and unused variables.
- ImportDetection: A set of phpcs sniffs to look for unused or unimported symbols.