1
|
<?php
|
2
|
/**
|
3
|
* Drupal_Sniffs_WhiteSpace_CloseBracketSpacingSniff.
|
4
|
*
|
5
|
* PHP version 5
|
6
|
*
|
7
|
* @category PHP
|
8
|
* @package PHP_CodeSniffer
|
9
|
* @link http://pear.php.net/package/PHP_CodeSniffer
|
10
|
*/
|
11
|
|
12
|
/**
|
13
|
* Checks that there is no white space before a closing bracket, for ")" and "}".
|
14
|
* Square Brackets are handled by Squiz_Sniffs_Arrays_ArrayBracketSpacingSniff.
|
15
|
*
|
16
|
* @category PHP
|
17
|
* @package PHP_CodeSniffer
|
18
|
* @link http://pear.php.net/package/PHP_CodeSniffer
|
19
|
*/
|
20
|
class Drupal_Sniffs_WhiteSpace_CloseBracketSpacingSniff implements PHP_CodeSniffer_Sniff
|
21
|
{
|
22
|
|
23
|
/**
|
24
|
* A list of tokenizers this sniff supports.
|
25
|
*
|
26
|
* @var array
|
27
|
*/
|
28
|
public $supportedTokenizers = array(
|
29
|
'PHP',
|
30
|
'JS',
|
31
|
);
|
32
|
|
33
|
|
34
|
/**
|
35
|
* Returns an array of tokens this test wants to listen for.
|
36
|
*
|
37
|
* @return array
|
38
|
*/
|
39
|
public function register()
|
40
|
{
|
41
|
return array(
|
42
|
T_CLOSE_CURLY_BRACKET,
|
43
|
T_CLOSE_PARENTHESIS,
|
44
|
);
|
45
|
|
46
|
}//end register()
|
47
|
|
48
|
|
49
|
/**
|
50
|
* Processes this test, when one of its tokens is encountered.
|
51
|
*
|
52
|
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
|
53
|
* @param int $stackPtr The position of the current token
|
54
|
* in the stack passed in $tokens.
|
55
|
*
|
56
|
* @return void
|
57
|
*/
|
58
|
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
59
|
{
|
60
|
$tokens = $phpcsFile->getTokens();
|
61
|
|
62
|
// Ignore curly brackets in javascript files.
|
63
|
if ($tokens[$stackPtr]['code'] === T_CLOSE_CURLY_BRACKET
|
64
|
&& $phpcsFile->tokenizerType === 'JS'
|
65
|
) {
|
66
|
return;
|
67
|
}
|
68
|
|
69
|
if (isset($tokens[($stackPtr - 1)]) === true
|
70
|
&& $tokens[($stackPtr - 1)]['code'] === T_WHITESPACE
|
71
|
) {
|
72
|
$before = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
|
73
|
if ($before !== false && $tokens[$stackPtr]['line'] === $tokens[$before]['line']) {
|
74
|
$error = 'There should be no white space before a closing "%s"';
|
75
|
$phpcsFile->addError(
|
76
|
$error,
|
77
|
($stackPtr - 1),
|
78
|
'ClosingWhitespace',
|
79
|
array($tokens[$stackPtr]['content'])
|
80
|
);
|
81
|
}
|
82
|
}
|
83
|
|
84
|
}//end process()
|
85
|
|
86
|
|
87
|
}//end class
|
88
|
|
89
|
?>
|