Open
Description
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:
- Create a file called
test.php
with the code sample above... - Run
phpcs test.php ...
- See error message displayed
- Run
phpcbf test.php
- Check indentation
- 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.