Skip to content

Commit

Permalink
small refactor of supported html dice logic
Browse files Browse the repository at this point in the history
  • Loading branch information
steve.brazier committed Apr 2, 2018
1 parent 451bc5c commit 4614c02
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Renderer/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class Html implements DiceRenderer
{
const SUPPORTED_DICE = ["d6", "d20"];

private $urlRoot;

public function __construct($urlRoot)
Expand Down Expand Up @@ -35,8 +37,9 @@ public function urlPrefix(): string
public function htmlForSingleDice(Dice $dice)
{
$name = $dice->name();
if ($name != "d6" && $name != "d20") {
throw new UnrenderableDiceException("Currently only d6 and d20 can be rendered as html");
if (!in_array($name, self::SUPPORTED_DICE)) {
$supportedDice = implode(", ", self::SUPPORTED_DICE);
throw new UnrenderableDiceException("Only the following can be rendered as html: $supportedDice");
}
$roll = $dice->roll();
$url = "{$this->urlRoot}/images/poorly-drawn/{$name}/{$roll}.png";
Expand Down

0 comments on commit 4614c02

Please sign in to comment.