Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed bug #19414 : php_cs seems to not track variables correctly in h…

…eredocs. It was important to include the start and end tags of a heredoc so that variables inside it would be tokenized correctly.
  • Loading branch information...
commit d8f22be5a02aff870471b024f685e23eaaf84297 1 parent ecc6693
Greg Sherwood gsherwood authored
17 CodeSniffer/Standards/Generic/Sniffs/CodeAnalysis/UnusedFunctionParameterSniff.php
@@ -116,16 +116,23 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
116 116 if ($code === T_VARIABLE && isset($params[$token['content']]) === true) {
117 117 unset($params[$token['content']]);
118 118 } else if ($code === T_DOUBLE_QUOTED_STRING
119   - || $code === T_HEREDOC
120   - || $code === T_NOWDOC
  119 + || $code === T_START_HEREDOC
  120 + || $code === T_START_NOWDOC
121 121 ) {
122 122 // Tokenize strings that can contain variables.
123 123 // Make sure the string is re-joined if it occurs over multiple lines.
  124 + $validTokens = array(
  125 + T_HEREDOC,
  126 + T_NOWDOC,
  127 + T_END_HEREDOC,
  128 + T_END_NOWDOC,
  129 + T_DOUBLE_QUOTED_STRING,
  130 + );
  131 + $validTokens = array_merge($validTokens, PHP_CodeSniffer_Tokens::$emptyTokens);
  132 +
124 133 $content = $token['content'];
125 134 for ($i = ($next + 1); $i <= $end; $i++) {
126   - if ($tokens[$i]['code'] === $code
127   - || in_array($tokens[$i]['code'], PHP_CodeSniffer_Tokens::$emptyTokens) === true
128   - ) {
  135 + if (in_array($tokens[$i]['code'], $validTokens) === true) {
129 136 $content .= $tokens[$i]['content'];
130 137 $next++;
131 138 } else {
12 CodeSniffer/Standards/Generic/Tests/CodeAnalysis/UnusedFunctionParameterUnitTest.inc
@@ -53,4 +53,14 @@ HERE;
53 53 8
54 54 9 at least 9 lines long
55 55 HERE;
56   -}
  56 +}
  57 +
  58 +function foo( $parameter ) {
  59 + return <<<HTML
  60 +<?xml version="1.0"?>
  61 +<value>$parameter</value>
  62 +HTML;
  63 +}
  64 +
  65 +print foo( 'PARAMETER' );
  66 +print "\n";
1  package.xml
@@ -57,6 +57,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
57 57 - Fixed bug #19394 : Notice in NonExecutableCodeSniff
58 58 - Fixed bug #19412 : Incorrect error about assigning objects to variables when inside inline IF
59 59 - Fixed bug #19413 : php_cs thinks I haven't used a parameter when I have
  60 + - Fixed bug #19414 : php_cs seems to not track variables correctly in heredocs
60 61 </notes>
61 62 <contents>
62 63 <dir name="/">

0 comments on commit d8f22be

Please sign in to comment.
Something went wrong with that request. Please try again.