False Postive: Misshandled PHP 8.0 Attributes on Class properties leading to "Missing member variable doc comment"

Created on 13 December 2023, 7 months ago
Updated 1 March 2024, 4 months ago

Problem/Motivation

When having a class with PHP Attributes attached to properties we get the following phpcs error

Missing member variable doc comment

...
  /**
   * Bar property.
   *
   * @var bool
   */
  #[NotBlank]
  private bool $bar;
...

Steps to reproduce

run phpcs against

<?php

use Symfony\Component\Validator\Constraints\NotBlank;

/**
 * Foo class description.
 */
class Foo {

  /**
   * Bar property.
   *
   * @var bool
   */
  #[NotBlank]
  private bool $bar;

}

Workaround

A working workaround for now is to add the attribute before the comment, but it's not a very common practice on the Symfony landscape.

<?php

use Symfony\Component\Validator\Constraints\NotBlank;

/**
 * Foo class description.
 */
class Foo {

  #[NotBlank]
  /**
   * Bar property.
   *
   * @var bool
   */
  private bool $bar;

}

Proposed resolution

  • Having a sniffer that handle PHP 8.0 Attribute properly

Remaining tasks

πŸ› Bug report
Status

Fixed

Version

8.3

Component

Coder Sniffer

Created by

πŸ‡¨πŸ‡­Switzerland wengerk Lausanne

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024