Skip to content

Commit 0475398

Browse files
authored
Add ReactionAlreadyExists::ofType method (#184)
1 parent 526d12d commit 0475398

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

contracts/Reaction/Exceptions/ReactionAlreadyExists.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@
1414
namespace Cog\Contracts\Love\Reaction\Exceptions;
1515

1616
use Cog\Contracts\Love\Exceptions\LoveThrowable;
17+
use Cog\Contracts\Love\ReactionType\Models\ReactionType;
1718
use RuntimeException;
1819

1920
final class ReactionAlreadyExists extends RuntimeException implements
2021
LoveThrowable
2122
{
23+
public static function ofType(ReactionType $reactionType): self
24+
{
25+
return new self(sprintf(
26+
'Reaction of type `%s` already exists.',
27+
$reactionType->getName()
28+
));
29+
}
2230
}

src/Reacter/Models/Reacter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,7 @@ public function reactTo(
9595
}
9696

9797
if ($rate === null) {
98-
throw new ReactionAlreadyExists(sprintf(
99-
'Reaction of type `%s` already exists.',
100-
$reactionType->getName()
101-
));
98+
throw ReactionAlreadyExists::ofType($reactionType);
10299
}
103100

104101
$reaction->changeRate($rate);

0 commit comments

Comments
 (0)