Describe the bug
I get a false positive when running code sniffer on PHP 8.0 code which uses two features at the same time.
Code sample
<?php
declare(strict_types=1);
namespace CoStack\LibTests\Unit\Double;
class FactoryTestClassThree
{
/**
* @param int $intArg
* @param string $stringArg
* @param mixed[] $arrayArg
* @param bool $boolArg
* @param float $floatArg
*/
public function __construct(
public int $intArg,
public string $stringArg,
public array $arrayArg,
public bool $boolArg,
public float $floatArg,
) {
}
}
Custom ruleset
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
name="PHPCS ruleset"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
>
<description>Test Classes and Tests. Config optimized for local and CI/CD.</description>
<rule ref="PSR12"/>
<file>src/</file>
<file>tests/</file>
<arg name="basepath" value="."/>
<arg name="colors"/>
<arg name="parallel" value="75"/>
<arg value="nps"/>
</ruleset>
To reproduce
Steps to reproduce the behavior:
FILE: tests/Unit/Double/FactoryTestClassThree.php
------------------------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 5 LINES
------------------------------------------------------------------------------------------------------------------------
17 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
| | (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
18 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
| | (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
19 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
| | (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
20 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
| | (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
21 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 8
| | (Generic.WhiteSpace.ScopeIndent.IncorrectExact)
------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------
Expected behavior
I expect no error. The code is indented correctly
Versions (please complete the following information):
in2code/php-dev:8.0-fpm (based on official php:8.0-fpm image)The core issue here is that the sniff thinks the T_PUBLIC token for the param is a method prefix, and sets the indent check to exact.
Thanks for the bug report. I've added a fix, which will be released in 3.6.0.
Most helpful comment
Thanks for the bug report. I've added a fix, which will be released in 3.6.0.