Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method params incorrectly detected when default value uses short array syntax #642

Merged

Conversation

joshdavis11
Copy link
Contributor

*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.

*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.
@aik099
Copy link
Contributor

aik099 commented Jul 16, 2015

Can you please add code example where it fails and used code standard?

@joshdavis11
Copy link
Contributor Author

This is what was failing:

/**
 * Complete a step
 *
 * @param string $status status of step to complete
 * @param array  $array  array
 * @param string $note   optional note
 *
 * @return void
 */
public function completeStep($status, array $array = [Class1::class, 'test'], $note = '') {
...
}
FILE: /Users/jdavis/repos/main/test.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 8 | ERROR | Doc comment for parameter $note does not match actual
   |       | variable name $array
----------------------------------------------------------------------

The coding standards used are:
PEAR, PHPCS, PSR1, PSR2, Squiz and Zend

@aik099
Copy link
Contributor

aik099 commented Jul 16, 2015

Now I clearly can see the problem. Thanks.

@joshdavis11
Copy link
Contributor Author

One other note: it only seemed to break when $array was not the last parameter. If it was the last parameter, it was fine (because it wasn't trying to parse the next parameter).

@gsherwood gsherwood changed the title Fix for bracket arrays in function parameter list. Method params incorrectly detected when default value uses short array syntax Jul 16, 2015
@gsherwood gsherwood merged commit c95da5f into squizlabs:master Jul 16, 2015
@gsherwood
Copy link
Member

Thanks a lot for fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants