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

Squiz.Functions.FunctionDeclarationArgumentSpacing bug when no space between type hint and argument #900

Closed
dereuromark opened this issue Feb 20, 2016 · 3 comments

Comments

@dereuromark
Copy link
Contributor

This does only recognize the 2nd and 3rd:

 31 | ERROR   | [x] Expected 1 space between comma and argument "$c"; 0
    |         |     found
    |         |     (Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg)
 31 | ERROR   | [x] Expected 1 space between comma and argument "$o"; 0
    |         |     found
    |         |     (Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg)

in

public function MissingParamTypeInDocBlock(array$a = null, callable$c, \ArrayObject$o, $foo = []) 
{
}

The array$a should be detected and fixed to array $a.
I assume it has to do with the beginning of the argument list.

The text is also a bit misleading, should maybe say "between typehint and argument". Or let the other rule take care of it, that does correctly use this terminology.

@dereuromark
Copy link
Contributor Author

Actually, it reports it, but fixes it incorrectly:

 31 | ERROR   | [x] Expected 1 space between type hint and argument
    |         |     "$a"; 0 found
    |         |     (Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint)

Result: array = null, the variable is now missing.

I made sure to run it with --sniffs=Squiz.Functions.FunctionDeclarationArgumentSpacing to have no side-effects of other sniffers.

This is most likely the reason there is an exclude in PSR2:
https://github.com/squizlabs/PHP_CodeSniffer/blob/master/CodeSniffer/Standards/PSR2/ruleset.xml#L123-L125

@gsherwood gsherwood changed the title Squiz.Functions.FunctionDeclarationArgumentSpacing bug with typehint/argument spacing Squiz.Functions.FunctionDeclarationArgumentSpacing bug when no space between type hint and argument Feb 22, 2016
gsherwood added a commit that referenced this issue Feb 22, 2016
…ug when no space between type hint and argument
@gsherwood
Copy link
Member

There were a couple of bugs in there, and PSR2 shouldn't have been reporting any errors with this sniff.

With the fix, this code now produces the following errors for the Squiz standard:

FILE: temp.php
---------------------------------------------------------------------------------------------------------------------
FOUND 7 ERRORS AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------
 2 | ERROR | [x] Expected 1 space between type hint and argument "$a"; 0 found
 2 | ERROR | [x] Incorrect spacing between argument "$a" and equals sign; expected 0 but found 1
 2 | ERROR | [x] Incorrect spacing between default value and equals sign for argument "$a"; expected 0 but found 1
 2 | ERROR | [x] Expected 1 space between type hint and argument "$c"; 0 found
 2 | ERROR | [x] Expected 1 space between type hint and argument "$o"; 0 found
 2 | ERROR | [x] Incorrect spacing between argument "$foo" and equals sign; expected 0 but found 1
 2 | ERROR | [x] Incorrect spacing between default value and equals sign for argument "$foo"; expected 0 but found 1
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------

and the diff for the fixes is this:

--- temp.php
+++ PHP_CodeSniffer
@@ -1,4 +1,4 @@
 <?php
-public function MissingParamTypeInDocBlock(array$a = null, callable$c, \ArrayObject$o, $foo = [])
+public function MissingParamTypeInDocBlock(array $a=null, callable $c, \ArrayObject $o, $foo=[])
 {
 }

Thanks for reporting this.

@dereuromark
Copy link
Contributor Author

👍

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

No branches or pull requests

2 participants