Skip to content

Commit

Permalink
Merge pull request #1276 from WordPress-Coding-Standards/feature/1275…
Browse files Browse the repository at this point in the history
…-prefix-all-globals-closure-bug

PrefixAllGlobals: bug fix - don't trigger on closure parameter definition
  • Loading branch information
JDGrimes authored Jan 4, 2018
2 parents ec646f5 + ea3808f commit dd3edd6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ protected function process_variable_assignment( $stackPtr ) {
// Function parameters do not need to be prefixed.
if ( isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
foreach ( $this->tokens[ $stackPtr ]['nested_parenthesis'] as $opener => $closer ) {
if ( isset( $this->tokens[ $opener ]['parenthesis_owner'] ) && T_FUNCTION === $this->tokens[ $this->tokens[ $opener ]['parenthesis_owner'] ]['code'] ) {
if ( isset( $this->tokens[ $opener ]['parenthesis_owner'] )
&& ( T_FUNCTION === $this->tokens[ $this->tokens[ $opener ]['parenthesis_owner'] ]['code']
|| T_CLOSURE === $this->tokens[ $this->tokens[ $opener ]['parenthesis_owner'] ]['code'] )
) {
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ trait T_Example {}

// Issue #1056.
define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ );

// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes false
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,9 @@ namespace Testing {
// OK: whitelisted core hooks.
apply_filters( 'widget_title', $title );
do_action( 'add_meta_boxes' );

add_shortcode( 'acronym_hello', function( $attrs, $content = null ) { // OK. Variables are function params.
// Do something.
} );

// @codingStandardsChangeSetting WordPress.NamingConventions.PrefixAllGlobals prefixes false

0 comments on commit dd3edd6

Please sign in to comment.