File tree Expand file tree Collapse file tree
Application/UseCase/Dice/RollDice Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212
1313final class RollDiceUseCase
1414{
15- /** @return Result<RollDiceOutput> */
15+ /**
16+ * @param RollDiceInput $input
17+ * @return Result<RollDiceOutput>
18+ * @throws \Random\RandomException if the system entropy source fails.
19+ * @throws \LogicException if an invalid symbol somehow bypasses DiceModifier::fromString.
20+ */
1621 public static function handle (RollDiceInput $ input ): Result
1722 {
1823 $ total = 0 ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ final class RollDiceAction
1212 * Returns the result of rolling a dice with the given number of sides.
1313 * @param Dice $dice The dice to roll.
1414 * @return int The result of the roll.
15+ * @throws \Random\RandomException if the system entropy source fails.
1516 */
1617 public static function roll (Dice $ dice ): int
1718 {
Original file line number Diff line number Diff line change @@ -12,15 +12,10 @@ final class Session
1212 * @param string $name The name of the session
1313 * @param Identifier $identifier The unique identifier for the session
1414 * @param \DateTime $createdAt The date and time when the session was created
15- * @throws \InvalidArgumentException if the session name is empty
1615 */
1716 public function __construct (
1817 public readonly string $ name ,
1918 public readonly Identifier $ identifier ,
2019 public readonly \DateTime $ createdAt ,
21- ) {
22- if (empty ($ name )) {
23- throw new \InvalidArgumentException ('Session name cannot be empty ' );
24- }
25- }
20+ ) {}
2621}
Original file line number Diff line number Diff line change @@ -45,14 +45,16 @@ public static function fromString(string $modifier): self
4545 /**
4646 * @param int $rollValue
4747 * @return int
48+ * @throws \LogicException if an invalid symbol somehow bypasses fromString
4849 */
4950 public function apply (int $ rollValue ): int
5051 {
5152 return (int ) ceil (match ($ this ->symbol ) {
5253 '+ ' => $ rollValue + $ this ->value ,
5354 '- ' => $ rollValue - $ this ->value ,
5455 '* ' , 'x ' => $ rollValue * $ this ->value ,
55- '/ ' => $ this ->value !== 0 ? $ rollValue / $ this ->value : $ rollValue ,
56+ '/ ' => $ rollValue / $ this ->value ,
57+ default => throw new \LogicException ("Unexpected symbol: {$ this ->symbol }" ),
5658 });
5759 }
5860}
You can’t perform that action at this time.
0 commit comments