Skip to content

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
merged 2 commits into from
Mar 12, 2023
Merged

Add support for enum methods #289

merged 2 commits into from
Mar 12, 2023

Conversation

sirbrillig
Copy link
Owner

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

Fixes #288

@sirbrillig
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 🤷 ).

@sirbrillig
Copy link
Owner Author

sirbrillig commented Mar 11, 2023

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?

@sirbrillig
Copy link
Owner Author

sirbrillig commented Mar 11, 2023

🤔 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 👎

@sirbrillig
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.

@jrfnl
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.

@sirbrillig
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

@sirbrillig
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.

@jrfnl
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.

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.

Variable $this is undefined in enum
2 participants