Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for enum methods #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
sirbrillig merged 2 commits into 2.x from add-enum
Mar 12, 2023
Merged

Add support for enum methods #289

sirbrillig merged 2 commits into 2.x from add-enum
Mar 12, 2023

Conversation

@sirbrillig
Copy link
Owner

@sirbrillig sirbrillig commented Jan 27, 2023

This adds support for enum methods to behave like class methods.

Fixes #288

Copy link
Owner Author

🤔 This will need a way to identify enum scopes without T_ENUM in order to work prior to PHP 7.3 (enums were introduced in PHP 8 but it appears that T_ENUM works in 7.3 🤷 ).

Copy link
Owner Author

sirbrillig commented Mar 11, 2023
edited
Loading

These test failures are really hard to debug. I consistently get failures for PHP 7 and 5.6, but when I run those same tests locally using those versions, everything passes.

Screenshot 2023年03月11日 at 6 37 41 PM

Screenshot 2023年03月11日 at 6 38 31 PM

Even running the sniff itself works as expected (the only error should be on line 33):

Screenshot 2023年03月11日 at 6 41 09 PM

Screenshot 2023年03月11日 at 6 41 30 PM

So why does it fail in Github Actions?

Copy link
Owner Author

sirbrillig commented Mar 11, 2023
edited
Loading

🤔 Ah, it may be something to do with how php or phpcs is installed... T_ENUM is somehow defined on my local machine even for php 5.6 which doesn't seem possible. I have to refactor how we detect classes so it can work for enums without T_ENUM entirely. Still difficult since I can't examine the failing code locally 👎

Copy link
Owner Author

I figured out how to reproduce the bug! I have to explicitly downgrade phpcs to 3.5.6. I think the issue is that in that version of phpcs, the enum does not get added to the conditions array at all (in fact, it looks like it gets confused by the syntax and adds things like the unrelated case statements to the conditions array). Now maybe I'll get somewhere.

Copy link
Collaborator

jrfnl commented Mar 12, 2023

PHPCS 3.5.6 was released in August 2020, way before the idea of Enums ever made it into a PHP RFC,

Support for enums was added in PHPCS 3.7.0.

Copy link
Owner Author

Ah hah! I think I've got it now. The only failing tests now are the coverage reports which I don't think are related to this PR:

Screenshot 2023年03月11日 at 7 58 32 PM

Copy link
Owner Author

💥 Fixed. I've disabled code coverage for now until it can be fixed but that's outside the scope of this PR.

Copy link
Collaborator

jrfnl commented Mar 12, 2023

Hang on, I actually have a commit ready to fix that code coverage for you. Give me a moment to send you a PR.

sirbrillig reacted with heart emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Variable $this is undefined in enum

AltStyle によって変換されたページ (->オリジナル) /