Skip to content

Commit

Permalink
Fixed bug #19421 : phpcs doesn't recognize as equivalent to
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed May 18, 2012
1 parent cd54fab commit c79233f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 50 deletions.
Expand Up @@ -115,6 +115,17 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)

if ($code === T_VARIABLE && isset($params[$token['content']]) === true) {
unset($params[$token['content']]);
} else if ($code === T_DOLLAR) {
$nextToken = $phpcsFile->findNext(T_WHITESPACE, ($next + 1), null, true);
if ($tokens[$nextToken]['code'] === T_OPEN_CURLY_BRACKET) {
$nextToken = $phpcsFile->findNext(T_WHITESPACE, ($nextToken + 1), null, true);
if ($tokens[$nextToken]['code'] === T_STRING) {
$varContent = '$'.$tokens[$nextToken]['content'];
if (isset($params[$varContent]) === true) {
unset($params[$varContent]);
}
}
}
} else if ($code === T_DOUBLE_QUOTED_STRING
|| $code === T_START_HEREDOC
|| $code === T_START_NOWDOC
Expand All @@ -141,13 +152,20 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}

$stringTokens = token_get_all(sprintf('<?php %s;?>', $content));
foreach ($stringTokens as $stringToken) {
if (is_array($stringToken) === false || $stringToken[0] !== T_VARIABLE ) {
foreach ($stringTokens as $stringPtr => $stringToken) {
if (is_array($stringToken) === false) {
continue;
}

if (isset($params[$stringToken[1]]) === true) {
unset($params[$stringToken[1]]);
$varContent = '';
if ($stringToken[0] === T_DOLLAR_OPEN_CURLY_BRACES) {
$varContent = '$'.$stringTokens[($stringPtr + 1)][1];
} else if ($stringToken[0] === T_VARIABLE) {
$varContent = $stringToken[1];
}

if ($varContent !== '' && isset($params[$varContent]) === true) {
unset($params[$varContent]);
}
}
}//end if
Expand Down
Expand Up @@ -131,6 +131,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}

// Is this a variable name, in the form ${varname} ?
if ($tokens[$prevPtr]['code'] === T_OPEN_CURLY_BRACKET) {
$nextPtr = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
if ($tokens[$nextPtr]['code'] === T_CLOSE_CURLY_BRACKET) {
return;
}
}

// Is this a namespace name?
if ($tokens[$prevPtr]['code'] === T_NS_SEPARATOR) {
return;
Expand Down
Expand Up @@ -63,4 +63,14 @@ HTML;
}

print foo( 'PARAMETER' );
print "\n";
print "\n";

function foo($bar)
{
print "${bar} things\n";
}

function bar($x)
{
return 2 * ${x};
}
Expand Up @@ -122,5 +122,6 @@ switch($foo)
gototarget3:
}

$a = 2 * ${x} - ${minus};

?>
48 changes: 3 additions & 45 deletions package.xml
Expand Up @@ -17,58 +17,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
<date>2012-05-17</date>
<time>13:47:00</time>
<version>
<release>1.3.4</release>
<api>1.3.4</api>
<release>1.3.5</release>
<api>1.3.5</api>
</version>
<stability>
<release>stable</release>
<api>stable</api>
</stability>
<license uri="http://matrix.squiz.net/developer/tools/php_cs/licence">BSD License</license>
<notes>
- Added missing package.xml entries for new Generic FixmeSniff
-- Thanks to Jaroslav Hanslík for the patch
- Expected indents for PEAR ScopeClosingBraceSniff and FunctionCallSignatureSniff can now be set in ruleset files
-- Both sniffs use a variable called "indent"
-- Thanks to Thomas Despoix for the patch
- Standards designed to be installed in the PHPCS Standards dir will now work outside this dir as well
-- In particular, allows the Drupal CS to work without needing to symlink it into the PHPCS install
-- Thanks to Peter Philipp for the patch
- Rule references for standards, directories and specific sniffs can now be relative in ruleset.xml files
-- For example: ref="../MyStandard/Sniffs/Commenting/DisallowHashCommentsSniff.php"
- Symlinked standards now work correctly, allowing aliasing of installed standards (request #19417)
-- Thanks to Tom Klingenberg for the patch
- Squiz ObjectInstantiationSniff now allows objects to be returned without assinging them to a variable
- Added Squiz.Commenting.FileComment.MissingShort error message for file comments that only contains tags
-- Also stops undefined index errors being generated for these comments
- Debug option -vv now shows tokenizer status for CSS files
- Added support for new gjslint error formats
-- Thanks to Meck for the patch
- Generic ScopeIndentSniff now allows comment indents to not be exact even if the exact flag is set
-- The start of the comment is still checked for exact indentation as normal
- Fixed an issue in AbstractPatternSniff where comments were not being ignored in some cases
- Fixed an issue in Zend ClosingTagSniff where the closing tag was not always being detected correctly
-- Thanks to Jonathan Robson for the patch
- Fixed an issue in Generic FunctionCallArgumentSpacingSniff where closures could cause incorrect errors
- Fixed an issue in Generic UpperCaseConstantNameSniff where errors were incorrectly reported on goto statements
-- Thanks to Tom Klingenberg for the patch
- PEAR FileCommentSniff and ClassCommentSniff now support author emails with a single character in the local part
-- E.g., a@me.com
-- Thanks to Denis Shapkin for the patch
- Fixed bug #19290 : Generic indent sniffer fails for anonymous functions
- Fixed bug #19324 : Setting show_warnings configuration option does not work
- Fixed bug #19354 : Not recognizing references passed to method
- Fixed bug #19361 : CSS tokenzier generates errors when PHP embedded in CSS file
- Fixed bug #19374 : HEREDOC/NOWDOC Indentation problems
- Fixed bug #19381 : traits and indetations in traits are not handled properly
- Fixed bug #19394 : Notice in NonExecutableCodeSniff
- Fixed bug #19402 : Syntax error when executing phpcs on Windows with parens in PHP path
-- Thanks to Tom Klingenberg for the patch
- Fixed bug #19411 : magic method error on __construct()
-- The fix required a rewrite of AbstractScopeSniff, so please test any sniffs that extend this class
- Fixed bug #19412 : Incorrect error about assigning objects to variables when inside inline IF
- Fixed bug #19413 : php_cs thinks I haven't used a parameter when I have
- Fixed bug #19414 : php_cs seems to not track variables correctly in heredocs
- Fixed bug #19421 : phpcs doesn't recognize ${x} as equivalent to $x
</notes>
<contents>
<dir name="/">
Expand Down

0 comments on commit c79233f

Please sign in to comment.