Skip to content

Commit 8a9458b

Browse files
committed
Refactor date header parsing logic
Improves the getParsedDateHeader method by restructuring the checks for DateHeader and its date value, ensuring null is returned for invalid cases and only converting valid dates.
1 parent 9d78587 commit 8a9458b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/HasParsedMessage.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ public function date(): ?CarbonInterface
3232
return null;
3333
}
3434

35-
if ($header instanceof DateHeader) {
36-
return Carbon::instance($header->getDateTime());
35+
if (! $header instanceof DateHeader) {
36+
return null;
37+
}
38+
39+
if (! $date = $header->getDateTime()) {
40+
return null;
3741
}
3842

39-
return null;
43+
return Carbon::instance($date);
4044
}
4145

4246
/**

0 commit comments

Comments
 (0)