Problem/Motivation

Currently enums introduced in PHP 8.1 are not supported.
This leads to Sniffs like Drupal.Commenting.FileComment requiring a file comment for PHP files containing an enum.

Steps to reproduce

Run said sniff on a PHP file containing an enum.

Proposed resolution

Define T_ENUM constant if it does not exist to avoid errors and add backwards compatibility.

Update Sniffs to also check for T_ENUM constant:

Drupal.Classes.ClassDeclaration
Drupal.Classes.ClassFileName
Drupal.Classes.UseGlobalClass
Drupal.Commenting.ClassComment
Drupal.Commenting.FileComment
Drupal.Commenting.InlineComment
Drupal.Commenting.InlineVariableComment
Drupal.Methods.MethodDeclaration
Drupal.Scope.MethodScope
Drupal.InfoFiles.ClassFiles

Note:
Please note that those changes only work when squizlabs/PHP_CodeSniffer releases the next version to include support for T_ENUM.

Issue fork coder-3283741

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

chfoidl created an issue. See original summary.

chfoidl’s picture

Title: Add compatibility for Enums in PHP 8.1 » Enum support in PHP 8.1
Issue summary: View changes
chfoidl’s picture

Issue summary: View changes

chfoidl’s picture

Status: Active » Needs review

klausi’s picture

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

Marking as "needs work"

kevinquillen’s picture

Running into this same issue. It does not work with the latest version, throwing the same error mentioned in the original post.

FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
1 | ERROR | [x] Missing file doc comment

solideogloria’s picture

Version: 8.3.15 » 8.3.x-dev
claudiu.cristea’s picture

Status: Needs work » Needs review
claudiu.cristea’s picture

@klausi, current tests are green but no new tests

claudiu.cristea’s picture

OK, I give up. No idea on how to test this

pfrenssen’s picture

Assigned: Unassigned » pfrenssen

Thanks a lot for making the MR! I will add some test coverage.

pfrenssen’s picture

Assigned: pfrenssen » Unassigned
Status: Needs review » Fixed
Issue tags: -Needs tests

Thanks!

Status: Fixed » Closed (fixed)

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

alexander allen’s picture

Unrelated to the file comment, but still related to enums, the coding standard does not let you add comments, specifically doc-block comments to enum cases.

Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
(Drupal.Commenting.InlineComment.DocBlock)

Example:

enum OAuthTokenState {
  case VALID;

  /**
   * When the Cache API marks an item as invalid or is not able to find it.
   */
  case INVALID;
}