Skip to content

Commit

Permalink
Fix for bracket arrays in function parameter list.
Browse files Browse the repository at this point in the history
*When code sniffing for doc blocks, PHPCS broke when the PHP 5.4 short array syntax was introduced.

*To fix this, I added a check for a bracket_opener and then skipped to the bracket_closer similar to the check for a parenthesis_opener/closer.
  • Loading branch information
joshdavis11 committed Jul 16, 2015
1 parent 67afe75 commit c95da5f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions CodeSniffer/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2717,9 +2717,9 @@ public function getMethodParameters($stackPtr)
$typeHint = '';

for ($i = ($opener + 1); $i <= $closer; $i++) {
// Check to see if this token has a parenthesis opener. If it does
// its likely to be an array, which might have arguments in it, which
// we cause problems in our parsing below, so lets just skip to the
// Check to see if this token has a parenthesis or bracket opener. If it does
// it's likely to be an array which might have arguments in it. This
// could cause problems in our parsing below, so lets just skip to the
// end of it.
if (isset($this->_tokens[$i]['parenthesis_opener']) === true) {
// Don't do this if it's the close parenthesis for the method.
Expand All @@ -2728,6 +2728,13 @@ public function getMethodParameters($stackPtr)
}
}

if (isset($this->_tokens[$i]['bracket_opener']) === true) {
// Don't do this if it's the close parenthesis for the method.
if ($i !== $this->_tokens[$i]['bracket_closer']) {
$i = ($this->_tokens[$i]['bracket_closer'] + 1);
}
}

switch ($this->_tokens[$i]['code']) {
case T_BITWISE_AND:
$passByReference = true;
Expand Down

0 comments on commit c95da5f

Please sign in to comment.