Skip to content

Commit 1a48159

Browse files
WebMambafabpot
authored andcommitted
Ban DateTime from the codebase
1 parent 94be3fc commit 1a48159

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Cookie.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct(string $name, ?string $value, string $expires = null
7272
$this->samesite = $samesite;
7373

7474
if (null !== $expires) {
75-
$timestampAsDateTime = \DateTime::createFromFormat('U', $expires);
75+
$timestampAsDateTime = \DateTimeImmutable::createFromFormat('U', $expires);
7676
if (false === $timestampAsDateTime) {
7777
throw new \UnexpectedValueException(sprintf('The cookie expiration time "%s" is not valid.', $expires));
7878
}
@@ -89,7 +89,7 @@ public function __toString(): string
8989
$cookie = sprintf('%s=%s', $this->name, $this->rawValue);
9090

9191
if (null !== $this->expires) {
92-
$dateTime = \DateTime::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
92+
$dateTime = \DateTimeImmutable::createFromFormat('U', $this->expires, new \DateTimeZone('GMT'));
9393
$cookie .= '; expires='.str_replace('+0000', '', $dateTime->format(self::DATE_FORMATS[0]));
9494
}
9595

@@ -202,13 +202,13 @@ private static function parseDate(string $dateValue): ?string
202202
}
203203

204204
foreach (self::DATE_FORMATS as $dateFormat) {
205-
if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
205+
if (false !== $date = \DateTimeImmutable::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
206206
return $date->format('U');
207207
}
208208
}
209209

210210
// attempt a fallback for unusual formatting
211-
if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
211+
if (false !== $date = date_create_immutable($dateValue, new \DateTimeZone('GMT'))) {
212212
return $date->format('U');
213213
}
214214

0 commit comments

Comments
 (0)