Skip to content

Conversation

remipelhate
Copy link
Member

Prior to this PR, when wanting to exclude some options from the EnumCase provider, we has to do something like:

public static function enumCases(): iterable
{
    $exclude = [SomeEnum::First, SomeEnum::Last];

    yield from EnumCase::options(...array_filter(
        SomeEnum::cases(), 
        fn (SomeEnum $case): bool => ! in_array($case, $exclude),
    ));
}

Not only is it cumbersome to write, it's pretty hard to read as well.

This PR simplifies it with a new provider constructor:

public static function enumCases(): iterable
{
    yield from EnumCase::except(SomeEnum::class, SomeEnum::First, SomeEnum::Last);
}

Copy link
Member

@ppelgrims ppelgrims left a comment

Choose a reason for hiding this comment

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

Much better!

@remipelhate remipelhate merged commit c9672f4 into main Sep 5, 2025
4 checks passed
@remipelhate remipelhate deleted the addition/enum-case-except-provider branch September 5, 2025 10:42
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.

3 participants