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

PHP 8.1 - Constructor Multi-line function declaration not indented correctly #3786

Closed
ricklambrechts opened this issue Mar 29, 2023 · 8 comments · Fixed by #3787
Closed

PHP 8.1 - Constructor Multi-line function declaration not indented correctly #3786

ricklambrechts opened this issue Mar 29, 2023 · 8 comments · Fixed by #3787

Comments

@ricklambrechts
Copy link

Describe the bug
Line indenting should be correct but is not correct for PHPCS. PHPCS says that PHPCBF can fix it:

23 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 12
24 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 12
25 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 12

But after fixing the indentating is 8 spaces and PHPCS says:

23 | ERROR | [x] Multi-line function call not indented correctly; expected 12 spaces but found 8
24 | ERROR | [x] Multi-line function call not indented correctly; expected 12 spaces but found 8
25 | ERROR | [x] Multi-line function call not indented correctly; expected 12 spaces but found 8

Code sample

class A implements B
{
    public function __construct(
        protected JWK $decryptionKey,
        protected JWESerializerManager $serializerManager = new JWESerializerManager([new CompactSerializer()]),
        protected JWEDecrypter $jweDecrypter = new JWEDecrypter(
            new AlgorithmManager([new RSAOAEP()]),
            new AlgorithmManager([new A128CBCHS256()]),
            new CompressionMethodManager([new Deflate()])
        ),
    ) {
    }
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
  <description>If you are using a custom ruleset, please enter it here.</description>
  <rule ref="PSR12" />
</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed
 7 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 12
 8 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 12
 9 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 12

Expected behavior
The expected behaviour would be that the indentation of 12 spaces is correct.

Versions (please complete the following information):

  • OS: Windows 11 (WSL2 Ubuntu)
  • PHP: 8.1
  • PHPCS: 8.9.1
  • Standard: PSR12
@fredden
Copy link
Contributor

fredden commented Mar 29, 2023

This sounds similar to #3631. Please can you run phpcs with the -s flag (for both states)? This will help identify what sniffs require investigation.

@ricklambrechts
Copy link
Author

State 1:

 29 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 12
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 30 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 12
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 31 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 12
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)

State 2:

 29 | ERROR | [x] Multi-line function call not indented correctly; expected 12 spaces but found 8
    |       |     (PSR2.Methods.FunctionCallSignature.Indent)
 30 | ERROR | [x] Multi-line function call not indented correctly; expected 12 spaces but found 8
    |       |     (PSR2.Methods.FunctionCallSignature.Indent)
 31 | ERROR | [x] Multi-line function call not indented correctly; expected 12 spaces but found 8
    |       |     (PSR2.Methods.FunctionCallSignature.Indent)

@jrfnl
Copy link
Contributor

jrfnl commented Mar 29, 2023

Based on the above, this is due to the PHP 8.1 "new in initializers" syntax not yet being taken into account by the Squiz.Functions.MultiLineFunctionDeclaration sniff.

@fredden Are you already working on a fix or shall I have a look ?

@fredden
Copy link
Contributor

fredden commented Mar 30, 2023

@fredden Are you already working on a fix or shall I have a look ?

You're welcome to pick this up. I probably won't have capacity to look into this for at least a few days.

@jrfnl
Copy link
Contributor

jrfnl commented Mar 30, 2023

PR #3787 should fix this. Testing appreciated.

@ricklambrechts
Copy link
Author

@jrfnl Thanks for creating the PR. Tested it locally and it works!

@jrfnl
Copy link
Contributor

jrfnl commented Mar 30, 2023

@ricklambrechts Thanks for testing and confirming!

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation May 4, 2023
@gsherwood gsherwood added this to the 3.8.0 milestone May 4, 2023
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release May 4, 2023
@jrfnl
Copy link
Contributor

jrfnl commented Dec 8, 2023

FYI: the fix for this issue is included in today's PHP_CodeSniffer 3.8.0 release.

As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
4 participants