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

Add initial use cases for Enum generation #109

Merged
merged 2 commits into from
Dec 7, 2021
Merged

Add initial use cases for Enum generation #109

merged 2 commits into from
Dec 7, 2021

Conversation

agustingomes
Copy link
Contributor

@agustingomes agustingomes commented Oct 18, 2021

Q A
Documentation yes (at later stage)
Bugfix no
BC Break no
New Feature yes
RFC no
QA no

Description

This PR Enables the creation of Enum objects for the following use cases:

  • Pure Enums
  • Backed Enums either with string or integer values (as per RFC specification)

Fixes #100

@weierophinney weierophinney added this to the 4.5.0 milestone Oct 20, 2021
Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bulk of the static analysis errors are due to the engine needing to infer types, and not being able to do so. The way to correct that is to verify them before doing an operation. For values in arrays, check that the array key exists, and then that the value conforms to what is required, before performing an operation. In other cases, just make sure that the typehints provided are correct, particularly in annotations. If needed, uses webmozart/assert to do the validations.

@agustingomes
Copy link
Contributor Author

Thanks @weierophinney for the initial review. I'll keep your feedback in account as I work further in the PR

Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few minor suggestions, mainly for readability. After making them, I think you can go ahead and remove the draft status, and @Ocramius can do final review.

@agustingomes agustingomes marked this pull request as ready for review November 11, 2021 17:00
@agustingomes
Copy link
Contributor Author

@weierophinney Thank you for the suggestions. I marked the PR as ready for review.

Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting close now! Thanks for all the work you're doing on this!

Verified

This commit was signed with the committer’s verified signature. The key has expired.
mtorromeo Massimiliano Torromeo
Supports generating Enums that are pure or have backed values.

Signed-off-by: Agustin Gomes <me@agustingomes.com>
Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Will wait for @Ocramius to do final review, however.

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall excellent:

  • the fact that implementations are @internal gives us space to improve later
  • everything else is simple and to the point

I'll proceed to merge, and will factor in the last comments by @michaelpetri ( #109 (review) )

@Ocramius Ocramius self-assigned this Dec 7, 2021
Ref: #109 (review)

In this change:

 * we remove the `polyfill/test` directory: we will use `<<<'PHP'` blocks directly
   in the test sources, in order to generate the classes that we need to verify
   enumerable type code generation
 * we replace `PHP_VERSION_ID`-based checks with PHPUnit's built-in `@requires PHP > 8.1`
   and similar
 * fixed some docblocks in tests
 * re-generated psalm baseline to reflect the fact that multiple issues were solved
@Ocramius
Copy link
Member

Ocramius commented Dec 7, 2021

🚢

Thanks @agustingomes @michaelpetri @weierophinney! Gonna cut a release after dependency upgrades

@Ocramius Ocramius merged commit 55c9fc5 into laminas:4.5.x Dec 7, 2021
@agustingomes agustingomes deleted the gh-100/add-enum-generation branch December 7, 2021 09:03
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.

PHP 8.1 enum type support
4 participants