-
-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only check T_USE tokens associated with closures
The `T_USE` token is also used to import traits to classes, and to import classes into namespaces. Fixes #431
- Loading branch information
Showing
4 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,8 +22,7 @@ | |
* @author Greg Sherwood <[email protected]> | ||
* @author Marc McIntyre <[email protected]> | ||
*/ | ||
class WordPress_Sniffs_WhiteSpace_ControlStructureSpacingSniff implements PHP_CodeSniffer_Sniff | ||
{ | ||
class WordPress_Sniffs_WhiteSpace_ControlStructureSpacingSniff extends WordPress_Sniff { | ||
|
||
/** | ||
* A list of tokenizers this sniff supports. | ||
|
@@ -103,6 +102,8 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
|
||
$tokens = $phpcsFile->getTokens(); | ||
|
||
$this->init( $phpcsFile ); | ||
|
||
if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE | ||
&& ! ( $tokens[$stackPtr]['code'] === T_ELSE && $tokens[($stackPtr + 1)]['code'] === T_COLON ) | ||
&& ! ( T_CLOSURE === $tokens[ $stackPtr ]['code'] && 0 === (int) $this->spaces_before_closure_open_paren ) | ||
|
@@ -122,7 +123,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
|
||
if ( isset( $tokens[ $stackPtr ]['scope_closer'] ) === false ) { | ||
|
||
if ( T_USE === $tokens[ $stackPtr ]['code'] ) { | ||
if ( T_USE === $tokens[ $stackPtr ]['code'] && 'closure' === $this->get_use_type( $stackPtr ) ) { | ||
$scopeOpener = $phpcsFile->findNext( T_OPEN_CURLY_BRACKET, $stackPtr + 1 ); | ||
$scopeCloser = $tokens[ $scopeOpener ]['scope_closer']; | ||
} else { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters