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

FunctionCallSignature works incorrectly #452

Open
1 task
semirke opened this issue Apr 16, 2024 · 2 comments
Open
1 task

FunctionCallSignature works incorrectly #452

semirke opened this issue Apr 16, 2024 · 2 comments

Comments

@semirke
Copy link

semirke commented Apr 16, 2024

Describe the bug

Seems PEAR.Functions.FunctionCallSignature.Indent sniff and fix works incorrectly with some nested structures.
The problem appears when there is indentation issue together with another issue, like PEAR.WhiteSpace.ScopeIndent.Incorrect.

After running phpcbf wrong number of indentation character (space) is not reported anymore.

The problem does not appear when correctly formatted and correct code is processed by phpcbf, nor does it mess up the good code.

Sample code

public function store()
{
  $fails  = $this->req(array(
    'device_id'=> array (
      'default' =>$this->app->param('device_id'),
      'min' => 0,
      'optional' => true
    ),
    )
    );
}

Phpcbf formatting

public function store()
{
    $fails  = $this->req(
        array(
        'device_id'=> array (
        'default' =>$this->app->param('device_id'),
        'min' => 0,
        'optional' => true
        ),
        )
    );
}

Another Phpcs wrong indent not caught:

public function store()
{
    $fails  = $this->req(
        array(
        'device_id'=> array ( // missing indent
                'default' =>$this->app->param('device_id'), 
                'min' => 0,
                'optional' => true
            ), // this line only has 2 spaces
        )
    );
}

Sample from PEAR standard

From: https://pear.php.net/manual/en/standards.funcalls.php

$this->someObject->subObject->callThisFunctionWithALongName(
    $this->someOtherFunc(
        $this->someEvenOtherFunc(
            'Help me!',
            array(
                'foo'  => 'bar',
                'spam' => 'eggs',
            ),
            23
        ),
        $this->someEvenOtherFunc()
    ),
    $this->wowowowowow(12)
);

Custom ruleset

No custom 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
  4. Run phpcbf test.php
  5. Check indentation
  6. phpcs test.php no longer reports indentation error.

PHPCS output here
-------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 9 ERRORS AFFECTING 6 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------------
  2 | ERROR | [ ] Missing file doc comment (PEAR.Commenting.FileComment.Missing)
  2 | ERROR | [ ] Missing doc comment for function store() (PEAR.Commenting.FunctionComment.Missing)
  4 | ERROR | [x] Line indented incorrectly; expected at least 4 spaces, found 2 (PEAR.WhiteSpace.ScopeIndent.Incorrect)
  4 | ERROR | [x] Opening statement of multi-line function call not indented correctly; expected 0 spaces but found 2
    |       |     (PEAR.Functions.FunctionCallSignature.OpeningIndent)
  4 | ERROR | [x] Opening parenthesis of a multi-line function call must be the last content on the line
    |       |     (PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket)
  5 | ERROR | [x] Multi-line function call not indented correctly; expected 6 spaces but found 4 (PEAR.Functions.FunctionCallSignature.Indent)
  9 | ERROR | [x] Multi-line function call not indented correctly; expected 6 spaces but found 4 (PEAR.Functions.FunctionCallSignature.Indent)
 10 | ERROR | [x] Multi-line function call not indented correctly; expected 6 spaces but found 4 (PEAR.Functions.FunctionCallSignature.Indent)
 11 | ERROR | [x] Multi-line function call not indented correctly; expected 2 spaces but found 4 (PEAR.Functions.FunctionCallSignature.Indent)
-------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 91ms; Memory: 6MB

Expected behavior

Phpcbf: follow standard while fixing.
Phpcs: catch wrong indentation.

Versions (please complete the following information)

Operating System Debian 10
PHP version 7.4
PHP_CodeSniffer version PHP_CodeSniffer version 3.8.0 (stable) by Squiz (https://www.squiz.net)
Standard PEAR
Install type git clone

Please confirm

  • [ x] 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.
  • [ x] I have verified the issue still exists in the master branch of PHP_CodeSniffer.

Thank you!

@semirke
Copy link
Author

semirke commented Apr 16, 2024

Hi,
I edited the issue and added more details with better sample code.

@semirke
Copy link
Author

semirke commented Apr 16, 2024

My guess is sniffer would need recursive processing of multi line function calls. Or from inside to outside.
I tried to look into it, but it was too much...

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