Skip to content

Commit 8645c1a

Browse files
committed
Improve named constructor for Item
1 parent bffec16 commit 8645c1a

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/Item.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,15 +268,8 @@ public static function fromTimestamp(int $timestamp): self
268268
*/
269269
public static function fromDateFormat(string $format, string $datetime): self
270270
{
271-
try {
272-
$value = DateTimeImmutable::createFromFormat($format, $datetime);
273-
} catch (Exception $exception) {
274-
throw new SyntaxError('The date notation `'.$datetime.'` is incompatible with the date format `'.$format.'`.', 0, $exception);
275-
}
276-
277-
if (!$value instanceof DateTimeImmutable) {
278-
throw new SyntaxError('The date notation `'.$datetime.'` is incompatible with the date format `'.$format.'`.');
279-
}
271+
$value = DateTimeImmutable::createFromFormat($format, $datetime);
272+
$value instanceof DateTimeImmutable || throw new SyntaxError('The date notation `'.$datetime.'` is incompatible with the date format `'.$format.'`.');
280273

281274
return new self($value);
282275
}

0 commit comments

Comments
 (0)