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

Generic.WhiteSpace.ScopeIndent false positive when using PHP 8.0 constructor property promotion #3167

Closed
vertexvaar opened this issue Nov 18, 2020 · 6 comments

Comments

@vertexvaar
Copy link

vertexvaar commented Nov 18, 2020

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:

  1. Scan the example code with phpcs
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):

  • OS: Docker image in2code/php-dev:8.0-fpm (based on official php:8.0-fpm image)
  • PHP: 8.0
  • PHPCS: 3.5.8
  • Standard: PSR12, see above
@gsherwood
Copy link
Member

gsherwood commented Nov 18, 2020

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.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Nov 18, 2020
@gsherwood gsherwood added this to the 3.6.0 milestone Nov 18, 2020
@gsherwood gsherwood changed the title Support PHP 8.0 constructor property promotion + trailing comma in parameter lists Generic.WhiteSpace.ScopeIndent false positive when using PHP 8.0 constructor property promotion Nov 18, 2020
gsherwood added a commit that referenced this issue Nov 18, 2020
…using PHP 8.0 constructor property promotion
gsherwood added a commit that referenced this issue Nov 18, 2020
…using PHP 8.0 constructor property promotion
@gsherwood
Copy link
Member

Thanks for the bug report. I've added a fix, which will be released in 3.6.0.

@fsalehpour
Copy link

Is it possible to release a patch for 3.5.x?

@MaFx
Copy link

MaFx commented Mar 12, 2021

What is the timeline for 3.6.0 release?

@progmancod
Copy link

Same problem in 3.6.0

@jrfnl
Copy link
Contributor

jrfnl commented Aug 6, 2021

@progmancod No, this issue was fixed. If you have found another (related) issue in PHPCS, please open a new issue with the full details to reproduce it.

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
Development

No branches or pull requests

6 participants