PrefixAllGlobalsSniff
extends AbstractFunctionParameterSniff
in package
uses
IsUnitTestTrait
Verify that everything defined in the global namespace is prefixed with a theme/plugin specific prefix.
Tags
Table of Contents
Constants
- ERROR_MSG = '%s by a theme/plugin should start with the theme/plugin prefix. Found: "%s".'
- Error message template.
- MIN_PREFIX_LENGTH = 3
- Minimal number of characters the prefix needs in order to be valid.
Properties
- $custom_test_classes : array<string|int, string>
- Custom list of classes which test classes can extend.
- $exclude : array<string|int, mixed>
- Exclude groups.
- $prefixes : array<string|int, string>
- Target prefixes.
- $unittest_groups : array<string|int, mixed>
- Groups of function data to check against.
- $allowed_core_constants : array<string, true>
- A list of core constants that are allowed to be defined by plugins and themes.
- $allowed_core_hooks : array<string, true>
- A list of core hooks that are allowed to be called by plugins and themes.
- $excluded_groups : array<string|int, mixed>
- Cache for the excluded groups information.
- $group_name : string
- The group name for this group of functions.
- $groups : array<string|int, mixed>
- Cache for the group information.
- $phpcsFile : File
- The current file being sniffed.
- $pluggable_classes : array<string, true>
- A list of classes declared in WP core as "Pluggable", i.e. overloadable from a plugin.
- $pluggable_functions : array<string, true>
- A list of functions declared in WP core as "Pluggable", i.e. overloadable from a plugin.
- $prefix_blocklist : array<string, true>
- Prefix blocklist.
- $regex_pattern : string
- Regex pattern with placeholder for the function names.
- $target_functions : array<string|int, mixed>
- Functions this sniff is looking for. Should be defined in the child class.
- $tokens : array<string|int, mixed>
- The list of tokens in the current file being sniffed.
- $added_custom_test_classes : array<string|int, string>
- Cache of previously added custom test classes.
- $all_test_classes : array<string, bool>
- Combined list of WP/PHPUnit native and custom test classes.
- $built_in_functions : array<string, int>
- List of all PHP native functions.
- $known_test_classes : array<string, true>
- List of PHPUnit and WP native classes which test classes can extend.
- $previous_prefixes : array<string|int, string>
- Cache of previously set prefixes.
- $validated_namespace_prefixes : array<string, array<string, mixed>>
- Target namespace prefixes after validation with regex indicator.
- $validated_prefixes : array<string, string>
- Target prefixes after validation.
Methods
- check_for_matches() : int|void
- Verify if the current token is one of the targetted functions.
- getGroups() : array<string|int, mixed>
- Groups of functions to restrict.
- is_targetted_token() : bool
- Verify is the current token is a function call.
- process() : int|void
- Set sniff properties and hand off to child class for processing of the token.
- process_matched_token() : int|void
- Process a matched token.
- process_no_parameters() : int|void
- Process the function if no parameters were found.
- process_parameters() : void
- Process the parameters of a matched function.
- process_token() : int|void
- Processes this test, when one of its tokens is encountered.
- register() : array<string|int, mixed>
- Returns an array of tokens this test wants to listen for.
- get_all_test_classes() : array<string, bool>
- Retrieve a list of all registered test classes, both WP/PHPUnit native as well as custom.
- is_test_class() : bool
- Check if a class token is part of a unit test suite.
- prepare_name_for_regex() : string
- Prepare the function name for use in a regular expression.
- process_list_assignment() : int|void
- Check that global variables declared via a list construct are prefixed.
- process_variable_assignment() : int|void
- Check that defined global variables are prefixed.
- process_variable_variable() : int|void
- Handle variable variables defined in the global namespace.
- setup_groups() : bool
- Set up the regular expressions for each group.
- is_prefixed() : bool
- Check if a function/class/constant/variable name is prefixed with one of the expected prefixes.
- record_potential_prefix_metric() : void
- Record the "potential prefix" metric.
- validate_prefixes() : void
- Validate an array of prefixes as passed through a custom property or via the command line.
- variable_prefixed_or_allowed() : bool
- Check if a variable name might need a prefix.
Constants
ERROR_MSG
Error message template.
public
string
ERROR_MSG
= '%s by a theme/plugin should start with the theme/plugin prefix. Found: "%s".'
MIN_PREFIX_LENGTH
Minimal number of characters the prefix needs in order to be valid.
public
int
MIN_PREFIX_LENGTH
= 3
Tags
Properties
$custom_test_classes
Custom list of classes which test classes can extend.
public
array<string|int, string>
$custom_test_classes
= array()
This property allows end-users to add to the build-in $known_test_classes
via their custom PHPCS ruleset.
This property will need to be set for each sniff which uses this trait.
Currently this property is used by the WordPress.WP.GlobalVariablesOverride,
WordPress.NamingConventions.PrefixAllGlobals and the WordPress.Files.Filename sniffs.
Example usage:
<rule ref="WordPress.[Subset].[Sniffname]">
<properties>
<property name="custom_test_classes" type="array">
<element value="My_Plugin_First_Test_Class"/>
<element value="My_Plugin_Second_Test_Class"/>
</property>
</properties>
</rule>
Note: it is strongly recommended to exclude your test directories for select error codes of those particular sniffs instead of relying on this property/trait.
Tags
$exclude
Exclude groups.
public
array<string|int, mixed>
$exclude
= array()
Example: 'switch_to_blog,user_meta'
Tags
$prefixes
Target prefixes.
public
array<string|int, string>
$prefixes
= array()
Tags
$unittest_groups
Groups of function data to check against.
public
static array<string|int, mixed>
$unittest_groups
= array()
Don't use this in extended classes, override getGroups() instead. This is only used for Unit tests.
Tags
$allowed_core_constants
A list of core constants that are allowed to be defined by plugins and themes.
protected
array<string, true>
$allowed_core_constants
= array(
'ADMIN_COOKIE_PATH' => true,
'AUTH_COOKIE' => true,
'AUTOSAVE_INTERVAL' => true,
'COOKIEHASH' => true,
'COOKIEPATH' => true,
'COOKIE_DOMAIN' => true,
'EMPTY_TRASH_DAYS' => true,
'FORCE_SSL_ADMIN' => true,
'FORCE_SSL_LOGIN' => true,
// Deprecated.
'LOGGED_IN_COOKIE' => true,
'MEDIA_TRASH' => true,
'MUPLUGINDIR' => true,
// Deprecated.
'PASS_COOKIE' => true,
'PLUGINDIR' => true,
// Deprecated.
'PLUGINS_COOKIE_PATH' => true,
'RECOVERY_MODE_COOKIE' => true,
'SCRIPT_DEBUG' => true,
'SECURE_AUTH_COOKIE' => true,
'SHORTINIT' => true,
'SITECOOKIEPATH' => true,
'TEST_COOKIE' => true,
'USER_COOKIE' => true,
'WPMU_PLUGIN_DIR' => true,
'WPMU_PLUGIN_URL' => true,
'WP_CACHE' => true,
'WP_CONTENT_DIR' => true,
'WP_CONTENT_URL' => true,
'WP_CRON_LOCK_TIMEOUT' => true,
'WP_DEBUG' => true,
'WP_DEBUG_DISPLAY' => true,
'WP_DEBUG_LOG' => true,
'WP_DEFAULT_THEME' => true,
'WP_DEVELOPMENT_MODE' => true,
'WP_MAX_MEMORY_LIMIT' => true,
'WP_MEMORY_LIMIT' => true,
'WP_PLUGIN_DIR' => true,
'WP_PLUGIN_URL' => true,
'WP_POST_REVISIONS' => true,
'WP_START_TIMESTAMP' => true,
)
Source:
The constants are listed in alphabetic order.
Only overrulable constants are listed, i.e. those defined within core within
a if ( ! defined() ) } wrapper.
Key is constant name, value irrelevant.
Tags
$allowed_core_hooks
A list of core hooks that are allowed to be called by plugins and themes.
protected
array<string, true>
$allowed_core_hooks
= array('widget_title' => true, 'add_meta_boxes' => true)
Key is hook name, value irrelevant.
Tags
$excluded_groups
Cache for the excluded groups information.
protected
array<string|int, mixed>
$excluded_groups
= array()
Tags
$group_name
The group name for this group of functions.
protected
string
$group_name
= 'restricted_parameters'
Intended to be overruled in the child class.
$groups
Cache for the group information.
protected
array<string|int, mixed>
$groups
= array()
Tags
$phpcsFile
The current file being sniffed.
protected
File
$phpcsFile
Tags
$pluggable_classes
A list of classes declared in WP core as "Pluggable", i.e. overloadable from a plugin.
protected
array<string, true>
$pluggable_classes
= array('TwentyTwenty_Customize' => true, 'TwentyTwenty_Non_Latin_Languages' => true, 'TwentyTwenty_SVG_Icons' => true, 'TwentyTwenty_Script_Loader' => true, 'TwentyTwenty_Separator_Control' => true, 'TwentyTwenty_Walker_Comment' => true, 'TwentyTwenty_Walker_Page' => true, 'Twenty_Twenty_One_Customize' => true, 'WP_User_Search' => true, 'wp_atom_server' => true)
Note: deprecated classes should still be included in this list as plugins may support older WP versions.
Key is class name, value irrelevant.
Tags
$pluggable_functions
A list of functions declared in WP core as "Pluggable", i.e. overloadable from a plugin.
protected
array<string, true>
$pluggable_functions
= array(
'auth_redirect' => true,
'cache_users' => true,
'check_admin_referer' => true,
'check_ajax_referer' => true,
'get_avatar' => true,
'get_currentuserinfo' => true,
// Deprecated.
'get_user_by' => true,
'get_user_by_email' => true,
// Deprecated.
'get_userdata' => true,
'get_userdatabylogin' => true,
// Deprecated.
'graceful_fail' => true,
'install_global_terms' => true,
'install_network' => true,
'is_user_logged_in' => true,
// 'lowercase_octets' => true, => unclear if this function is meant to be publicly pluggable.
'maybe_add_column' => true,
'maybe_create_table' => true,
'set_current_user' => true,
// Deprecated.
'twenty_twenty_one_entry_meta_footer' => true,
'twenty_twenty_one_post_thumbnail' => true,
'twenty_twenty_one_post_title' => true,
'twenty_twenty_one_posted_by' => true,
'twenty_twenty_one_posted_on' => true,
'twenty_twenty_one_setup' => true,
'twenty_twenty_one_the_posts_navigation' => true,
'twentyeleven_admin_header_image' => true,
'twentyeleven_admin_header_style' => true,
'twentyeleven_comment' => true,
'twentyeleven_content_nav' => true,
'twentyeleven_continue_reading_link' => true,
'twentyeleven_header_image' => true,
'twentyeleven_header_style' => true,
'twentyeleven_posted_on' => true,
'twentyeleven_setup' => true,
'twentyfifteen_comment_nav' => true,
'twentyfifteen_entry_meta' => true,
'twentyfifteen_excerpt_more' => true,
'twentyfifteen_fonts_url' => true,
'twentyfifteen_get_color_scheme' => true,
'twentyfifteen_get_color_scheme_choices' => true,
'twentyfifteen_get_link_url' => true,
'twentyfifteen_header_style' => true,
'twentyfifteen_post_thumbnail' => true,
'twentyfifteen_sanitize_color_scheme' => true,
'twentyfifteen_setup' => true,
'twentyfifteen_the_custom_logo' => true,
'twentyfourteen_admin_header_image' => true,
'twentyfourteen_admin_header_style' => true,
'twentyfourteen_excerpt_more' => true,
'twentyfourteen_font_url' => true,
'twentyfourteen_header_image' => true,
'twentyfourteen_header_style' => true,
'twentyfourteen_list_authors' => true,
'twentyfourteen_paging_nav' => true,
'twentyfourteen_post_nav' => true,
'twentyfourteen_post_thumbnail' => true,
'twentyfourteen_posted_on' => true,
'twentyfourteen_setup' => true,
'twentyfourteen_the_attached_image' => true,
'twentynineteen_comment_count' => true,
'twentynineteen_comment_form' => true,
'twentynineteen_discussion_avatars_list' => true,
'twentynineteen_entry_footer' => true,
'twentynineteen_get_user_avatar_markup' => true,
'twentynineteen_post_thumbnail' => true,
'twentynineteen_posted_by' => true,
'twentynineteen_posted_on' => true,
'twentynineteen_setup' => true,
'twentynineteen_the_posts_navigation' => true,
'twentyseventeen_edit_link' => true,
'twentyseventeen_entry_footer' => true,
'twentyseventeen_fonts_url' => true,
'twentyseventeen_header_style' => true,
'twentyseventeen_posted_on' => true,
'twentyseventeen_time_link' => true,
'twentysixteen_categorized_blog' => true,
'twentysixteen_entry_date' => true,
'twentysixteen_entry_meta' => true,
'twentysixteen_entry_taxonomies' => true,
'twentysixteen_excerpt' => true,
'twentysixteen_excerpt_more' => true,
'twentysixteen_fonts_url' => true,
'twentysixteen_get_color_scheme' => true,
'twentysixteen_get_color_scheme_choices' => true,
'twentysixteen_header_style' => true,
'twentysixteen_post_thumbnail' => true,
'twentysixteen_sanitize_color_scheme' => true,
'twentysixteen_setup' => true,
'twentysixteen_the_custom_logo' => true,
'twentyten_admin_header_style' => true,
'twentyten_comment' => true,
'twentyten_continue_reading_link' => true,
'twentyten_header_image' => true,
'twentyten_posted_in' => true,
'twentyten_posted_on' => true,
'twentyten_setup' => true,
'twentythirteen_entry_date' => true,
'twentythirteen_entry_meta' => true,
'twentythirteen_excerpt_more' => true,
'twentythirteen_fonts_url' => true,
'twentythirteen_paging_nav' => true,
'twentythirteen_post_nav' => true,
'twentythirteen_the_attached_image' => true,
'twentytwelve_comment' => true,
'twentytwelve_content_nav' => true,
'twentytwelve_entry_meta' => true,
'twentytwelve_get_font_url' => true,
'twentytwenty_customize_partial_blogdescription' => true,
'twentytwenty_customize_partial_blogname' => true,
'twentytwenty_customize_partial_site_logo' => true,
'twentytwenty_generate_css' => true,
'twentytwenty_get_customizer_css' => true,
'twentytwenty_get_theme_svg' => true,
'twentytwenty_the_theme_svg' => true,
'twentytwentyfour_block_styles' => true,
'twentytwentyfour_block_stylesheets' => true,
'twentytwentyfour_pattern_categories' => true,
'twentytwentytwo_styles' => true,
'twentytwentytwo_support' => true,
'wp_authenticate' => true,
'wp_cache_add_multiple' => true,
'wp_cache_delete_multiple' => true,
'wp_cache_flush_group' => true,
'wp_cache_flush_runtime' => true,
'wp_cache_get_multiple' => true,
'wp_cache_set_multiple' => true,
'wp_cache_supports' => true,
'wp_check_password' => true,
'wp_clear_auth_cookie' => true,
'wp_clearcookie' => true,
// Deprecated.
'wp_create_nonce' => true,
'wp_generate_auth_cookie' => true,
'wp_generate_password' => true,
'wp_get_cookie_login' => true,
// Deprecated.
'wp_get_current_user' => true,
// 'wp_handle_upload_error' => true, => unclear if this function is meant to be publicly pluggable.
'wp_hash' => true,
'wp_hash_password' => true,
'wp_install' => true,
'wp_install_defaults' => true,
'wp_login' => true,
// Deprecated.
'wp_logout' => true,
'wp_mail' => true,
'wp_new_blog_notification' => true,
'wp_new_user_notification' => true,
'wp_nonce_tick' => true,
'wp_notify_moderator' => true,
'wp_notify_postauthor' => true,
'wp_parse_auth_cookie' => true,
'wp_password_change_notification' => true,
'wp_rand' => true,
'wp_redirect' => true,
'wp_safe_redirect' => true,
'wp_salt' => true,
'wp_sanitize_redirect' => true,
'wp_set_auth_cookie' => true,
'wp_set_current_user' => true,
'wp_set_password' => true,
'wp_setcookie' => true,
// Deprecated.
'wp_text_diff' => true,
'wp_upgrade' => true,
'wp_validate_auth_cookie' => true,
'wp_validate_redirect' => true,
'wp_verify_nonce' => true,
)
Note: deprecated functions should still be included in this list as plugins may support older WP versions.
Key is function name, value irrelevant.
Tags
$prefix_blocklist
Prefix blocklist.
protected
array<string, true>
$prefix_blocklist
= array('wordpress' => true, 'wp' => true, '_' => true, 'php' => true)
Key is prefix, value irrelevant.
Tags
$regex_pattern
Regex pattern with placeholder for the function names.
protected
string
$regex_pattern
= '`^(?:%s)$`i'
Tags
$target_functions
Functions this sniff is looking for. Should be defined in the child class.
protected
array<string|int, mixed>
$target_functions
= array()
The only requirement for this array is that the top level array keys are the names of the functions you're looking for. Other than that, the array can have arbitrary content depending on your needs.
$tokens
The list of tokens in the current file being sniffed.
protected
array<string|int, mixed>
$tokens
Tags
$added_custom_test_classes
Cache of previously added custom test classes.
private
array<string|int, string>
$added_custom_test_classes
= array()
Prevents having to do the same merges over and over again.
Tags
$all_test_classes
Combined list of WP/PHPUnit native and custom test classes.
private
array<string, bool>
$all_test_classes
= array()
Tags
$built_in_functions
List of all PHP native functions.
private
array<string, int>
$built_in_functions
Using this list rather than a call to function_exists() prevents
false negatives from user-defined functions when those would be
autoloaded via a Composer autoload files directives.
$known_test_classes
List of PHPUnit and WP native classes which test classes can extend.
private
array<string, true>
$known_test_classes
= array(
// Base test cases.
'WP_UnitTestCase' => true,
'WP_UnitTestCase_Base' => true,
'PHPUnit_Adapter_TestCase' => true,
// Domain specific base test cases.
'WP_Ajax_UnitTestCase' => true,
'WP_Canonical_UnitTestCase' => true,
'WP_Font_Face_UnitTestCase' => true,
'WP_Test_REST_Controller_Testcase' => true,
'WP_Test_REST_Post_Type_Controller_Testcase' => true,
'WP_Test_REST_TestCase' => true,
'WP_Test_XML_TestCase' => true,
'WP_XMLRPC_UnitTestCase' => true,
// PHPUnit native test cases.
'PHPUnit_Framework_TestCase' => true,
'PHPUnit\Framework\TestCase' => true,
// PHPUnit native TestCase class when imported via use statement.
'TestCase' => true,
)
{internal These are the test cases provided in the /tests/phpunit/includes/
directory of WP Core.}
Key is class name, value irrelevant.
Tags
$previous_prefixes
Cache of previously set prefixes.
private
array<string|int, string>
$previous_prefixes
= array()
Prevents having to do the same prefix validation over and over again.
Tags
$validated_namespace_prefixes
Target namespace prefixes after validation with regex indicator.
private
array<string, array<string, mixed>>
$validated_namespace_prefixes
= array()
All prefixes are lowercased for case-insensitive compare.
If the prefix doesn't already contain a namespace separator, but does contain
non-word characters, these will have been replaced with regex syntax to allow
for namespace separators and the is_regex indicator will have been set to true.
Tags
$validated_prefixes
Target prefixes after validation.
private
array<string, string>
$validated_prefixes
= array()
All prefixes are lowercased for case-insensitive compare.
Tags
Methods
check_for_matches()
Verify if the current token is one of the targetted functions.
public
check_for_matches(int $stackPtr) : int|void
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
getGroups()
Groups of functions to restrict.
public
getGroups() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>is_targetted_token()
Verify is the current token is a function call.
public
is_targetted_token(int $stackPtr) : bool
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
Tags
Return values
boolprocess()
Set sniff properties and hand off to child class for processing of the token.
public
process(File $phpcsFile, int $stackPtr) : int|void
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the current token in the stack passed in $tokens.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
process_matched_token()
Process a matched token.
public
process_matched_token(int $stackPtr, string $group_name, string $matched_content) : int|void
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
- $group_name : string
-
The name of the group which was matched.
- $matched_content : string
-
The token content (function name) which was matched in lowercase.
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
process_no_parameters()
Process the function if no parameters were found.
public
process_no_parameters(int $stackPtr, string $group_name, string $matched_content) : int|void
Defaults to doing nothing. Can be overloaded in child classes to handle functions were parameters are expected, but none found.
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
- $group_name : string
-
The name of the group which was matched.
- $matched_content : string
-
The token content (function name) which was matched in lowercase.
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
process_parameters()
Process the parameters of a matched function.
public
process_parameters(int $stackPtr, string $group_name, string $matched_content, array<string|int, mixed> $parameters) : void
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
- $group_name : string
-
The name of the group which was matched.
- $matched_content : string
-
The token content (function name) which was matched in lowercase.
- $parameters : array<string|int, mixed>
-
Array with information about the parameters.
Tags
process_token()
Processes this test, when one of its tokens is encountered.
public
process_token(int $stackPtr) : int|void
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
register()
Returns an array of tokens this test wants to listen for.
public
register() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>get_all_test_classes()
Retrieve a list of all registered test classes, both WP/PHPUnit native as well as custom.
protected
final get_all_test_classes() : array<string, bool>
Tags
Return values
array<string, bool>is_test_class()
Check if a class token is part of a unit test suite.
protected
final is_test_class(File $phpcsFile, int $stackPtr) : bool
Unit test classes are identified as such:
- Class which either extends one of the known test cases, such as
WP_UnitTestCaseorPHPUnit_Framework_TestCaseor extends a custom unit test class as listed in thecustom_test_classesproperty.
Parameters
- $phpcsFile : File
-
The file being scanned.
- $stackPtr : int
-
The position of the token to be examined. This should be a class, anonymous class or trait token.
Tags
Return values
bool —True if the class is a unit test class, false otherwise.
prepare_name_for_regex()
Prepare the function name for use in a regular expression.
protected
prepare_name_for_regex(string $function_name) : string
The getGroups() method allows for providing function names with a wildcard * to target a group of functions. This prepare routine takes that into account while still safely escaping the function name for use in a regular expression.
Parameters
- $function_name : string
-
Function name.
Tags
Return values
string —Regex escaped function name.
process_list_assignment()
Check that global variables declared via a list construct are prefixed.
protected
process_list_assignment(int $stackPtr) : int|void
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
process_variable_assignment()
Check that defined global variables are prefixed.
protected
process_variable_assignment(int $stackPtr[, bool $in_list = false ]) : int|void
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
- $in_list : bool = false
-
Whether or not this is a variable in a list assignment. Defaults to false.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
process_variable_variable()
Handle variable variables defined in the global namespace.
protected
process_variable_variable(int $stackPtr) : int|void
Parameters
- $stackPtr : int
-
The position of the current token in the stack.
Tags
Return values
int|void —Integer stack pointer to skip forward or void to continue normal file processing.
setup_groups()
Set up the regular expressions for each group.
protected
setup_groups(string $key) : bool
Parameters
- $key : string
-
The group array index key where the input for the regular expression can be found.
Tags
Return values
bool —True if the groups were setup. False if not.
is_prefixed()
Check if a function/class/constant/variable name is prefixed with one of the expected prefixes.
private
is_prefixed(int $stackPtr, string $name) : bool
Parameters
- $stackPtr : int
-
The position of the token to record the metric against.
- $name : string
-
Name to check for a prefix.
Tags
Return values
bool —True when the name is one of the prefixes or starts with an allowed prefix. False otherwise.
record_potential_prefix_metric()
Record the "potential prefix" metric.
private
record_potential_prefix_metric(int $stackPtr, string $construct_name) : void
Parameters
- $stackPtr : int
-
The position of the token to record the metric against.
- $construct_name : string
-
Name of the global construct to try and distill a potential prefix from.
Tags
validate_prefixes()
Validate an array of prefixes as passed through a custom property or via the command line.
private
validate_prefixes() : void
Checks that the prefix:
- is not one of the blocked ones.
- complies with the PHP rules for valid function, class, variable, constant names.
Tags
variable_prefixed_or_allowed()
Check if a variable name might need a prefix.
private
variable_prefixed_or_allowed(int $stackPtr, string $name) : bool
Prefix is not needed for:
- superglobals,
- WP native globals,
- variables which are already prefixed.
Parameters
- $stackPtr : int
-
The position of the token to record the metric against.
- $name : string
-
Variable name without the dollar sign.
Tags
Return values
bool —True if the variable name is allowed or already prefixed. False otherwise.