Skip to content

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

Merged
taylorotwell merged 1 commit intolaravel:9.xfrom
coleshirley:clean-up-if-else-statement
Aug 15, 2022
Merged

[9.x] Cleaning up old if-else statement#43712
taylorotwell merged 1 commit intolaravel:9.xfrom
coleshirley:clean-up-if-else-statement

Conversation

@coleshirley
Copy link
Copy Markdown
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
Copy Markdown
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