Skip to content
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

Require typed class constants #87

Open
dpi opened this issue Feb 26, 2025 · 2 comments · May be fixed by #89
Open

Require typed class constants #87

dpi opened this issue Feb 26, 2025 · 2 comments · May be fixed by #89

Comments

@dpi
Copy link
Member

dpi commented Feb 26, 2025

https://wiki.php.net/rfc/typed_class_constants

Since PHP 8.3, class constants can be typed.

Seems to make sense, considering you can subclass and override constants. Typing a constant enforces it down the line. Particularly useful in tests.

Rule: SlevomatCodingStandard.TypeHints.ClassConstantTypeHint

New rule introduced in the latest version of slevomat/coding-standard

Mostly autofixable. In scenarios where a constant isnt subclasses, phpcbf can add types. However things like bools, the autofixer might add true or false, but not pick up hierarchy and set to bool. It also seems like if a constant is a classname CLASS::class, string isnt added, but thats an easy fix.

@dpi
Copy link
Member Author

dpi commented Feb 26, 2025

Requires a bump to phpstan/phpdoc-parser and slevomat/coding-standard.

dpi added a commit that referenced this issue Feb 26, 2025
dpi added a commit that referenced this issue Feb 26, 2025
@dpi dpi linked a pull request Feb 26, 2025 that will close this issue
dpi added a commit that referenced this issue Feb 26, 2025
@acbramley
Copy link
Contributor

+1 to this

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 a pull request may close this issue.

2 participants