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

phpcbf fails to fix function call when there is a trailing comma immediately before a closing parenthesis #3836

Closed
3 tasks done
scorgn opened this issue May 25, 2023 · 3 comments

Comments

@scorgn
Copy link

scorgn commented May 25, 2023

Describe the bug

phpcbf fails to fix a file when it has a call to a function where all the following are true:

  • All arguments are on the same line as the opening parenthesis
  • At least part of the reference to the callable is also on the same line as the opening parenthesis and arguments
  • There is a trailing comma after the last argument and before the closing parenthesis

The two conflicting rules are:

  • Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma
  • PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket

Code samples

phpcbf will fail to fix the following code samples:

<?php
var_dump('foobar',);
<?php
var_dump('foobar'
   ,

);
<?php
Foo
::bar('foobar',);
<?php
Foo::{
'bar'
}('foobar',);

However phpcbf will successfully fix the following code sample without failing:

<?php
var_dump
('foobar',);

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with any of the failing code samples above...
  2. Run phpcbf --standard=PSR2 --sniffs=Generic.Functions.FunctionCallArgumentSpacing,PSR2.Methods.FunctionCallSignature test.php
  3. See error message displayed
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------------------------
FILE                                                                    FIXED  REMAINING
----------------------------------------------------------------------------------------
.../test.php     FAILED TO FIX
----------------------------------------------------------------------------------------
A TOTAL OF 0 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
----------------------------------------------------------------------------------------

Expected behavior

It may not be appropriate for phpcs to remove the trailing comma, so my expected behavior would be that phpcs does not mark the line as automatically fixable and that phpcbf does not attempt to fix the issue - and that phpcbf does not fail to fix the file.

Versions (please complete the following information)

Operating System MacOS 12.6.5
PHP version PHP 8.0.28
PHP_CodeSniffer version PHP_CodeSniffer version 3.7.2 (stable) by Squiz (http://www.squiz.net)
Standard PSR2
Install type Composer (local)

Please confirm:

  • I have searched the issue list and am not opening a duplicate issue.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.
@jrfnl
Copy link
Contributor

jrfnl commented May 25, 2023

Closing as duplicate of #3477 and #3707, which were both already fixed via #3805.

@scorgn I don't know why you checked the "I have verified the issue still exists in the master branch of PHP_CodeSniffer." (or the "I have searched the issue list and am not opening a duplicate issue.") checkboxes ? Any particular reason ? I honestly cannot reproduce the issue anymore with the current master branch, so I don't understand how you could... ?

@jrfnl jrfnl closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2023
@scorgn
Copy link
Author

scorgn commented May 25, 2023

Apologies, I'm now realizing that my .zshrc kicked in and was still using the global installation of phpcs rather than the one in the local folder.

I did search through existing issues but I wasn't able to find those, I will try to be more diligent looking in the future.

@jrfnl
Copy link
Contributor

jrfnl commented May 25, 2023

@scorgn Thanks for getting back to me. The fix will be included in the next (3.8.0) release.

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