PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

Squiz.NamingConventions.ValidVariableName.NotCamelCaps + property promotion = false positive

Open LastDragon-ru opened this issue 2 years ago • 0 comments

Describe the bug

Property promotions handling like variables, but they are class property

Code sample

<?php declare(strict_types = 1);

namespace Tests;

class Test {
    public string $normal_property = 'abc';

    public function __construct(
        public string $promoted_property = 'abc',
    ) {
        // empty
    }
}

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
  <rule ref="Squiz.NamingConventions.ValidVariableName.NotCamelCaps"/>
</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
----------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------
 9 | ERROR | Variable "promoted_property" is not in valid camel caps format
----------------------------------------------------------------------------

Expected behavior

No error.

Versions (please complete the following information):

  • OS: Windows 10
  • PHP: 8.0
  • PHPCS: 3.6.2

LastDragon-ru avatar Mar 22 '22 13:03 LastDragon-ru