Skip to content

Conversation

@jaymcp
Copy link
Contributor

@jaymcp jaymcp commented Mar 10, 2025

Description

Updates our file name sniff to account for enums correctly.
Enums should follow the same rules as interfaces, classes, and traits:

  • one object per file
  • file name should be lower-kebab case, and be prefixed with enum-

This PR also remove some template checks that came from the original Sniff, but are not required for our purposes.

Testing steps

composer require --dev bigbite/phpcs-config:dev-feat/enum-filenames

Create a file called enum-my-enum.php:

enum My_Enum {
    case Foo;
}

Run

./vendor/bin/phpcs .

There should be no errors.

Then try:

  • renaming the file or renaming the enum
  • adding a second enum to the same file

Run ./vendor/bin/phpcs . after every change.
If the filename isn't exactly the lower-kebab case name of the enum, prefixed with enum-, PHPCS should error.

Types of changes (if applicable):

  • Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist (if applicable):

  • All checks pass when running `composer run all-checks.

@jaymcp jaymcp requested a review from a team March 10, 2025 12:16
Copy link
Member

@ampersarnie ampersarnie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the following enum setups:

  • Enums
  • Back Enums.
  • Enum Methods.
  • Enum Methods with an Interface.
  • Enum constants.

@jaymcp jaymcp merged commit 2095dc8 into main Mar 17, 2025
5 checks passed
@jaymcp jaymcp deleted the feat/enum-filenames branch March 17, 2025 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants