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

✨ New PHPCSUtils\Utils\Constants class + associated token collection #562

Merged
merged 2 commits into from
May 26, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Feb 26, 2024

✨ New Collections::constantTypeTokens() method

PHP 8.3 adds support for typed OO constants.

This collection contains all the tokens which can be encountered in a constant type.

Note: along the same lines as for property/parameter/return type declarations, the collection does not include the T_NULLABLE token.

Ref: https://wiki.php.net/rfc/typed_class_constants#supported_types

✨ New PHPCSUtils\Utils\Constants class

... to contain utilities methods for analysing constants declared using the const keyword.

In the future, the scope of the methods might be expanded to also covered constants declared using define(), but that's for later.

Initially, the class comes with the following method:

  • getProperties(File $phpcsFile, $stackPtr): array to retrieve an array of information about a constant declaration, like the visibility, whether visibility was explicitly declared, whether the constant was declared as final, what the type is for the constant etc.

Includes extensive unit tests.

@jrfnl jrfnl added this to the 1.1.0 milestone Feb 26, 2024
@jrfnl jrfnl force-pushed the 1.1.0/new-constants-class branch 2 times, most recently from 6943e72 to 3a9516d Compare March 18, 2024 01:27
@jrfnl jrfnl mentioned this pull request Apr 28, 2024
28 tasks
@jrfnl jrfnl force-pushed the 1.1.0/new-constants-class branch 2 times, most recently from 114217e to eaaa537 Compare May 13, 2024 11:12
@jrfnl jrfnl changed the base branch from develop to feature/introduce-better-exceptions May 13, 2024 11:12
@jrfnl
Copy link
Member Author

jrfnl commented May 13, 2024

Rebased on top of #598 and added a commit to take advantage of the new exceptions. Moving to draft until #598 has been merged.

@jrfnl jrfnl marked this pull request as draft May 13, 2024 11:13
@jrfnl jrfnl force-pushed the 1.1.0/new-constants-class branch from eaaa537 to 8829511 Compare May 13, 2024 11:15
@jrfnl jrfnl force-pushed the feature/introduce-better-exceptions branch from d06975f to 8b08c1e Compare May 20, 2024 18:18
Base automatically changed from feature/introduce-better-exceptions to develop May 20, 2024 18:24
@jrfnl
Copy link
Member Author

jrfnl commented May 23, 2024

Rebased and updated for DNF support + added some extra parse error protections (with tests).

Marking as ready for review. I will squash the commits back into the original two commits before merging, but will leave this open for a couple of days before I do so, to allow review.

@jrfnl jrfnl force-pushed the 1.1.0/new-constants-class branch from 8829511 to 2657594 Compare May 23, 2024 08:44
@jrfnl jrfnl marked this pull request as ready for review May 23, 2024 08:44
jrfnl added 2 commits May 23, 2024 22:36
PHP 8.3 adds support for typed OO constants.

This collection contains all the tokens which can be encountered in a constant type.

Note: along the same lines as for property/parameter/return type declarations, the collection does not include the `T_NULLABLE` token.

Ref: https://wiki.php.net/rfc/typed_class_constants#supported_types
... to contain utilities methods for analysing constants declared using the `const` keyword.

In the future, the scope of the methods might be expanded to also covered constants declared using `define()`, but that's for later.

Initially, the class comes with the following method:
* `getProperties(File $phpcsFile, $stackPtr): array` to retrieve an array of information about a constant declaration, like the visibility, whether visibility was explicitly declared, whether the constant was declared as final, what the type is for the constant etc.

Includes extensive unit tests.
@jrfnl jrfnl force-pushed the 1.1.0/new-constants-class branch from 2657594 to 7e953e4 Compare May 26, 2024 22:20
@jrfnl jrfnl merged commit 85846f2 into develop May 26, 2024
54 checks passed
@jrfnl jrfnl deleted the 1.1.0/new-constants-class branch May 26, 2024 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant