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

Add changeRate method to Reaction contract #98

Closed
antonkomarev opened this issue Aug 1, 2019 · 0 comments · Fixed by #100
Closed

Add changeRate method to Reaction contract #98

antonkomarev opened this issue Aug 1, 2019 · 0 comments · Fixed by #100
Milestone

Comments

@antonkomarev
Copy link
Member

antonkomarev commented Aug 1, 2019

Motivation

Reacter::reactTo method changes reaction rate directly using Eloquent update method:

$reaction->update([
    'rate' => $rate,
]);

But method update does not exist on Cog\Contracts\Love\Reaction\Models\Reaction interface.

New Implementation

We can add changeRate method to the Reaction interface.

public function changeRate(float $rate): void;

We could move check for same rate value out from the Reacter::reactTo method to new Reaction::changeRate method.

if ($reaction->getRate() === $rate) {
    throw new ReactionAlreadyExists(
        sprintf('Reaction of type `%s` with `%s` rate already exists.', $reactionType->getName(), $rate)
    );
}

This will require to introduce new exception like RateInvalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant