diff --git a/src/Exceptions/InvalidDate.php b/src/Exceptions/InvalidDate.php index e76b624..da1f626 100644 --- a/src/Exceptions/InvalidDate.php +++ b/src/Exceptions/InvalidDate.php @@ -6,6 +6,11 @@ class InvalidDate extends InvalidArgumentException { + public static function cannotBeNull(string $parameter): InvalidDate + { + return new static("{$parameter} cannot be null"); + } + public static function forFormat(string $date, ?string $format): InvalidDate { $message = "Could not construct a date from `{$date}`"; diff --git a/src/Period.php b/src/Period.php index 295e856..c4ea954 100644 --- a/src/Period.php +++ b/src/Period.php @@ -36,6 +36,14 @@ public function __construct(DateTimeImmutable $start, DateTimeImmutable $end) */ public static function make($start, $end, string $format = null): Period { + if ($start === null) { + throw InvalidDate::cannotBeNull('Start date'); + } + + if ($end === null) { + throw InvalidDate::cannotBeNull('Endß date'); + } + return new static( self::resolveDate($start, $format), self::resolveDate($end, $format)