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

Feature: add abort method to result object #12

Merged
merged 3 commits into from
Apr 19, 2024
Merged

Conversation

lindyhopchris
Copy link
Member

@lindyhopchris lindyhopchris commented Apr 19, 2024

This new method throws a FailedResultException if the result is a failure; otherwise it does nothing. This means the following:

$result = $bus->dispatch($command);

if ($result->didFail()) {
    throw new FailedResultException($result);
}

can be rewritten as:

$result = $bus->dispatch($command);
$result->abort();
// here result is definitely a success.

This PR also changes the ResultInterface::value() method to throw FailedResultException if attempting to get a value from a failed result. Previously it threw a ContractException - but the failed result exception makes more sense as it contains the originating result.

@lindyhopchris lindyhopchris self-assigned this Apr 19, 2024
@lindyhopchris lindyhopchris merged commit a98756c into next Apr 19, 2024
4 checks passed
@lindyhopchris lindyhopchris deleted the result-abort branch April 19, 2024 20:30
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.

1 participant