Skip to content

PHP8 custructor property promotion bugged when phpdoc is used #3363

@fabianbadoi

Description

@fabianbadoi

Describe the bug
Using PHP8 promoted constructror properties by themselves works fine, but adding phpdoc to them leads to some false errors.

Code sample

<?php

declare(strict_types=1);

namespace Test;

class Test
{
    public function __construct(
        /**
         * @var int
         */
        public int $test,
    ) {
    }
}

Custom ruleset

I am using --standard=PSR12

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
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 11 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 0 (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 12 | ERROR | [x] Multi-line function declaration not indented correctly; expected 8 spaces but found 0 (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 13 | ERROR | [x] The first parameter of a multi-line function declaration must be on the line after the opening bracket
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.FirstParamSpacing)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 31ms; Memory: 8MB

Expected behavior
The test class looks fine, I expected phpcs to not complain about it. The error message also points towards bugs, there are clearly more than 0 spaces:

expected 8 spaces but found 0

Versions (please complete the following information):

  • OS: Ubuntu 20.04
  • PHP: 8.0.3
  • PHPCS: 3.6.0
  • Standard: PSR12

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions