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

[9.x] Cleaning up old if-else statement #43712

Merged
merged 1 commit into from
Aug 15, 2022

Conversation

coleshirley
Copy link
Contributor

This old (and ugly) if else statement was discovered in the Laravel discord so I figured I'd PR it for better readability.

https://discord.com/channels/297040613688475649/486650445297877003/1008788895120506970

@coleshirley
Copy link
Contributor Author

An alternative syntax with less right hand side arms:

return match (true) {
            $this->shouldQuit => static::EXIT_SUCCESS,
            $this->memoryExceeded($options->memory) => static::EXIT_MEMORY_LIMIT,
            $this->queueShouldRestart($lastRestart),
            $options->stopWhenEmpty && is_null($job),
            $options->maxTime && hrtime(true) / 1e9 - $startTime >= $options->maxTime,
            $options->maxJobs && $jobsProcessed >= $options->maxJobs => static::EXIT_SUCCESS,
            default => null
        };

@taylorotwell taylorotwell merged commit caa6f0a into laravel:9.x Aug 15, 2022
@GrahamCampbell GrahamCampbell changed the title Cleaning up old if-else statement [9.x] Cleaning up old if-else statement Aug 15, 2022
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 this pull request may close these issues.

2 participants