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 whitelisting comment for tax query #524

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions WordPress/Sniffs/Arrays/ArrayAssignmentRestrictionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
* @package PHP_CodeSniffer
* @author Shady Sharaf <[email protected]>
*/
class WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff implements PHP_CodeSniffer_Sniff
class WordPress_Sniffs_Arrays_ArrayAssignmentRestrictionsSniff extends WordPress_Sniff
{

/**
* Exclude groups
*
* Example: 'foo,bar'
*
* @var string Comma-delimited group list
*
* @var string Comma-delimited group list
*/
public $exclude = '';

/**
* Groups of variable data to check against.
* Don't use this in extended classes, override getGroups() instead.
* This is only used for Unit tests.
*
*
* @var array
*/
public static $groups = array();
Expand Down Expand Up @@ -132,7 +132,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )


foreach ( $groups as $groupName => $group ) {

if ( in_array( $groupName, $exclude ) ) {
continue;
}
Expand Down Expand Up @@ -165,9 +165,9 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )

call_user_func(
$addWhat,
$message,
$stackPtr,
$groupName,
$message,
$stackPtr,
$groupName,
array( $key, $val )
);
}
Expand All @@ -183,7 +183,7 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
/**
* Callback to process each confirmed key, to check value
* This must be extended to add the logic to check assignment value
*
*
* @param string $key Array index / key
* @param mixed $val Assigned value
* @param int $line Token line
Expand Down
20 changes: 20 additions & 0 deletions WordPress/Sniffs/VIP/SlowDBQuerySniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,24 @@ public function getGroups() {
)
);
}

/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {

$this->init( $phpcsFile );

if ( $this->has_whitelist_comment( 'tax_query', $stackPtr ) ) {
return;
}

parent::process( $phpcsFile, $stackPtr );
}
}//end class
17 changes: 17 additions & 0 deletions WordPress/Tests/VIP/SlowDBQueryUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ $query = 'foo=bar&meta_key=foo&meta_value=bar';
if ( ! isset( $widget['params'][0] ) ) {
$widget['params'][0] = array();
}


// Testing whitelisting comments.
$test = array(

// Single-line statements.
'tax_query' => array(), // Bad.
'tax_query' => array(), // WPCS: tax_query ok.

// Multi-line statement.
'tax_query' => array( // WPCS: tax_query ok.
array(
'taxonomy' => 'foo',
),
),
),
);
1 change: 1 addition & 0 deletions WordPress/Tests/VIP/SlowDBQueryUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getWarningList()
15 => 1,
16 => 1,
19 => 2,
30 => 1,
);

}//end getWarningList()
Expand Down