Problem/Motivation

readonly class member variables generate `Missing member variable doc comment` errors, regardless of whether they actually have a doc comment.

Steps to reproduce

Here's code that causes the sniff error:

<?php

namespace MyNamespace;

/**
 * Test class with a test member variable.
 */
class Test {

  /**
   * Test.
   *
   * @var float
   */
  public readonly float $test;

}

Proposed resolution

readonly member variables with doc comments shouldn't show errors like that.

This can be fixed by adding T_READONLY to the ignore list in processMemberVar() in VariableCommentSniff.php

Comments

solideogloria created an issue. See original summary.

solideogloria’s picture

Version: 8.x-3.x-dev » 8.3.15
Status: Active » Needs review
StatusFileSize
new566 bytes

Works for me.

klausi’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks, can you file a pull request against https://github.com/pfrenssen/coder so that we see the test cases run?

Please also add a test case so that we cover this.

solideogloria’s picture

Status: Needs work » Needs review
StatusFileSize
new1.41 KB

Added a test and created a pull request. For completion, here is the patch.

https://github.com/pfrenssen/coder/pull/168

solideogloria’s picture

Issue tags: -Needs tests

  • b04c03d committed on 8.3.x
    fix(VariableComment): Support for PHP 8.1 readonly member variables (#...

  • klausi authored 6a6ec05 on 8.3.x
    chore(composer): Bump PHPCS dependency for PHP 8.1 language support (#...
klausi’s picture

Version: 8.3.15 » 8.x-3.x-dev
Status: Needs review » Fixed

Thanks, merged! I also bumped our PHPCs dependency to 3.7.1 to make sure PHP 8.1 language support is there.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.