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

Allow enum value to be backed by an empty string #189

Merged

Conversation

martin-helmich
Copy link
Contributor

Q A
Documentation no
Bugfix yes
BC Break no
New Feature no
RFC no
QA no

Description

Currently, the EnumGenerator class enforces (in its Psalm typings) that a case of a backed enumeration is backed by int|non-empty-string. However, the non-empty-string constraint is unnecessarily strict, since (AFAIK)
an empty string is an entirely valid value (not name!) for a backed enum case.

This change relaxes the Psalm type hints a bit in order to allow this:

$enum = EnumGenerator::withConfig([
  "name"        => "Foo",
  "backedCases" => [
    "type"  => "string",
    "cases" => [
      "empty" => "",
      "foo"   => "foo",
      "bar"   => "bar",
    ],
  ]
]);

@Ocramius Ocramius self-assigned this Sep 6, 2023
@Ocramius Ocramius added this to the 4.12.0 milestone Sep 6, 2023
@Ocramius
Copy link
Member

Ocramius commented Sep 6, 2023

@martin-helmich CI shows that more adjustments are needed

@martin-helmich
Copy link
Contributor Author

Yep, already noticed. Converting back to draft, for now. Although I suspect that (some) of the failing CI jobs may be unrelated to this change (this one, for example).

@martin-helmich martin-helmich marked this pull request as draft September 6, 2023 14:50
Signed-off-by: Martin Helmich <m.helmich@mittwald.de>
@martin-helmich martin-helmich force-pushed the bugfix/enum-case-may-be-empty branch from 6fa1bd9 to 16d1a08 Compare September 6, 2023 14:52
@martin-helmich martin-helmich marked this pull request as ready for review September 6, 2023 14:54
@martin-helmich
Copy link
Contributor Author

Ready for review, again. The Psalm CI job now runs successfully; some PHPUnit jobs are failing for reasons I believe to be unrelated to this change.

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.

Thanks @martin-helmich!

@Ocramius Ocramius merged commit 36cbee2 into laminas:4.12.x Sep 6, 2023
@martin-helmich martin-helmich deleted the bugfix/enum-case-may-be-empty branch September 6, 2023 14:56
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.

2 participants