Skip to content

New Universal.Enums.EnumProtectedMember sniff#454

Open
rodrigoprimo wants to merge 1 commit into
PHPCSStandards:developfrom
rodrigoprimo:enum-protected-member
Open

New Universal.Enums.EnumProtectedMember sniff#454
rodrigoprimo wants to merge 1 commit into
PHPCSStandards:developfrom
rodrigoprimo:enum-protected-member

Conversation

@rodrigoprimo

Copy link
Copy Markdown
Collaborator

This sniff requires non-public enum members (methods and constants) to be declared private instead of protected. As enums cannot be extended, protected visibility is functionally equivalent to private for an enum member.

This follows PER Coding Style 2.0 (section 9):

Non-public methods MUST use private instead of protected, as enums do not support inheritance.

Separate error codes (MethodFound and ConstantFound) are used, so either case can be excluded independently if desired. PER-CS 2.0 enforces this rule on methods only. The upcoming PER-CS 3.1 is expected to enforce it on classs constants as well (see php-fig/per-coding-style#151).

Fixes #442.

Suggested changelog entry

  • New Universal.Enums.EnumProtectedMember sniff to require non-public enum members (methods and constants) to be declared private instead of protected.

…ected enum members

Add the `Universal.Enums.EnumProtectedMember` sniff which requires non-public enum
members (methods and constants) to be declared `private` instead of `protected`. As
enums cannot be extended, `protected` is functionally equivalent to `private` for an
enum member. This complies with PER Coding Style 2.0 (section 9).

Fixes 442.

Ref: https://github.com/php-fig/per-coding-style/blob/2.0.0/spec.md#9-enumerations
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.

[FR] Enums: sniff to enforce that non-public methods use private instead of protected

1 participant