class Drupal_Sniffs_ControlStructures_ElseCatchNewlineSniff in Coder 7.2
Checks that else/elseif/catch statements start on a new line.
Unfortunately we need this sniff because Drupal_Sniffs_ControlStructures_ControlSignatureSniff does not detect this.
@category PHP @package PHP_CodeSniffer @link http://pear.php.net/package/PHP_CodeSniffer
Hierarchy
- class \Drupal_Sniffs_ControlStructures_ElseCatchNewlineSniff implements \PHP_CodeSniffer_Sniff
Expanded class hierarchy of Drupal_Sniffs_ControlStructures_ElseCatchNewlineSniff
File
- coder_sniffer/
Drupal/ Sniffs/ ControlStructures/ ElseCatchNewlineSniff.php, line 22
View source
class Drupal_Sniffs_ControlStructures_ElseCatchNewlineSniff implements PHP_CodeSniffer_Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array
*/
public function register() {
return array(
T_ELSE,
T_ELSEIF,
T_CATCH,
);
}
//end register()
/**
* 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) {
$tokens = $phpcsFile
->getTokens();
$prevNonWhiteSpace = $phpcsFile
->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr - 1, null, true);
if ($tokens[$prevNonWhiteSpace]['line'] === $tokens[$stackPtr]['line']) {
$error = '%s must start on a new line';
$data = array(
$tokens[$stackPtr]['content'],
);
$phpcsFile
->addError($error, $stackPtr, 'ElseNewline', $data);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Drupal_Sniffs_ControlStructures_ElseCatchNewlineSniff:: |
public | function | Processes this test, when one of its tokens is encountered. | |
Drupal_Sniffs_ControlStructures_ElseCatchNewlineSniff:: |
public | function | Returns an array of tokens this test wants to listen for. |