Skip to content

Commit

Permalink
WP/Capabilities: tiny tweaks
Browse files Browse the repository at this point in the history
* Use `$%s` to indicate a parameter name in an error message.
* Consistently use multi-line array for `$data` parameter with multiple entries (as in: consistent with how this is done elsewhere in this same sniff).
* Mark a remark about a lists which needs regular updates as `@internal`.
  • Loading branch information
jrfnl committed Nov 29, 2022
1 parent f3930af commit 1ff7cf6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions WordPress/Sniffs/WP/CapabilitiesSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ class CapabilitiesSniff extends AbstractFunctionParameterSniff {
/**
* List of known primitive and meta core capabilities.
*
* To be updated after every major release. Sorted alphabetically.
* Last updated for WordPress 6.1.0.
*
* Sources:
* - {@link https://wordpress.org/support/article/roles-and-capabilities/ Roles and Capabilities handbook page}
* - The `map_meta_cap()` function in the `src/wp-includes/capabilities.php` file.
* - The tests in the `tests/phpunit/tests/user/capabilities.php` file.
*
* List is sorted alphabetically.
*
* {@internal To be updated after every major release. Last updated for WordPress 6.1.0.}
*
* @since 3.0.0
*
* @var array<string, bool> All capabilities available in core.
Expand Down Expand Up @@ -382,7 +383,11 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
'Couldn\'t determine the value passed to the $%s parameter in function call to %s(). Please check if it matches a valid capability. Found: %s',
$i,
'Undetermined',
array( $function_details['name'], $matched_content, $parameter['clean'] ),
array(
$function_details['name'],
$matched_content,
$parameter['clean'],
),
3 // Message severity set to below default.
);
return;
Expand All @@ -408,7 +413,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p

if ( empty( $matched_parameter ) ) {
$this->phpcsFile->addError(
'An empty string is not a valid capability. Empty string found as the %s parameter in a function call to %s()"',
'An empty string is not a valid capability. Empty string found as the $%s parameter in a function call to %s()"',
$first_non_empty,
'Invalid',
array(
Expand Down

0 comments on commit 1ff7cf6

Please sign in to comment.