Skip to content

Commit

Permalink
Improve InvalidDate
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Nov 28, 2018
1 parent 57e2ac4 commit e5823b0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Exceptions/InvalidDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@

class InvalidDate extends InvalidArgumentException
{
public static function forFormat(string $date, string $format): InvalidDate
public static function forFormat(string $date, ?string $format): InvalidDate
{
return new static("Could not construct a date from `{$date}` with format `{$format}`.");
$message = "Could not construct a date from `{$date}`";

if ($format) {
$message .= " with format `{$format}`";
}

return new static($message);
}
}

0 comments on commit e5823b0

Please sign in to comment.