Skip to content

Commit

Permalink
Fixed duplicate message codes in Generic OpeningFunctionBraceKernigha…
Browse files Browse the repository at this point in the history
…nRitchieSniff and also doing the checks in a different way so that closures can be supported.
  • Loading branch information
gsherwood committed Jul 11, 2012
1 parent d269206 commit f7711ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
Expand Up @@ -77,26 +77,34 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}

// Checks that the closing parenthesis and the opening brace are
// separated by a whitespace character.
$closerColumn = $tokens[$tokens[$stackPtr]['parenthesis_closer']]['column'];
$braceColumn = $tokens[$openingBrace]['column'];

$columnDifference = ($braceColumn - $closerColumn);
$closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
if ($tokens[($closeBracket + 1)]['code'] !== T_WHITESPACE) {
$length = 0;
} else if ($tokens[($closeBracket + 1)]['content'] === "\t") {
$length = '\t';
} else {
$length = strlen($tokens[($closeBracket + 1)]['content']);
}

if ($columnDifference !== 2) {
$error = 'Expected 1 space between the closing parenthesis and the opening brace; found %s';
$data = array(($columnDifference - 1));
$phpcsFile->addError($error, $openingBrace, 'SpaceBeforeBrace', $data);
if ($length !== 1) {
$error = 'Expected 1 space after closing parenthesis; found %s';
$data = array($length);
$phpcsFile->addError($error, $openingBrace, 'SpaceAfterBracket', $data);
return;
}

// Check that a tab was not used instead of a space.
$spaceTokenPtr = ($tokens[$stackPtr]['parenthesis_closer'] + 1);
$spaceContent = $tokens[$spaceTokenPtr]['content'];
if ($spaceContent !== ' ') {
$error = 'Expected a single space character between closing parenthesis and opening brace; found %s';
$data = array($spaceContent);
$closeBrace = $tokens[$stackPtr]['scope_opener'];
if ($tokens[($closeBrace - 1)]['code'] !== T_WHITESPACE) {
$length = 0;
} else if ($tokens[($closeBrace - 1)]['content'] === "\t") {
$length = '\t';
} else {
$length = strlen($tokens[($closeBrace - 1)]['content']);
}

if ($length !== 1) {
$error = 'Expected 1 space before opening brace; found %s';
$data = array($length);
$phpcsFile->addError($error, $openingBrace, 'SpaceBeforeBrace', $data);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion package.xml
Expand Up @@ -39,6 +39,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Exclude rules written for Unix systems will now work correctly on Windows
-- Thanks to Walter Tamboer for the patch
- The PHP tokenizer now recognises T_RETURN as a valid closer for T_CASE and T_DEFAULT inside switch statements
- Fixed duplicate message codes in Generic OpeningFunctionBraceKernighanRitchieSniff
- Fixed bug #18651 : PHPunit Test cases for custom standards are not working on Windows
- Fixed bug #19416 : Shorthand arrays cause bracket spacing errors
- Fixed bug #19421 : phpcs doesn't recognize ${x} as equivalent to $x
Expand All @@ -50,7 +51,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #19471 : phpcs on Windows, when using Zend standard, doesn't catch problems
-- Thanks to Ivan Habunek for the patch
- Fixed bug #19478 : Incorrect indent detection in PEAR standard
-- Thanks to Shane Auckland
-- Thanks to Shane Auckland for the patch
- Fixed bug #19483 : Blame Reports fail with space in directory name
</notes>
<contents>
Expand Down

0 comments on commit f7711ce

Please sign in to comment.