Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Dflydev/FigCookies/SetCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class SetCookie
private $value;
/** @var int */
private $expires = 0;
/** @var int */
private $maxAge = 0;
/** @var int|null */
private $maxAge = null;
/** @var string|null */
private $path;
/** @var string|null */
Expand Down Expand Up @@ -62,7 +62,7 @@ public function getExpires() : int
return $this->expires;
}

public function getMaxAge() : int
public function getMaxAge() : ?int
{
return $this->maxAge;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ public function withMaxAge(?int $maxAge = null) : self
{
$clone = clone($this);

$clone->maxAge = (int) $maxAge;
$clone->maxAge = $maxAge;

return $clone;
}
Expand Down Expand Up @@ -349,7 +349,7 @@ private function appendFormattedExpiresPartIfSet(array $cookieStringParts) : arr
*/
private function appendFormattedMaxAgePartIfSet(array $cookieStringParts) : array
{
if ($this->maxAge) {
if (is_int($this->maxAge)) {
$cookieStringParts[] = sprintf('Max-Age=%s', $this->maxAge);
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Dflydev/FigCookies/SetCookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ public function provideParsesFromSetCookieStringData() : array
->withHttpOnly(true)
->withSameSite(SameSite::lax()),
],
[
'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Path=/; Max-Age=0',
SetCookie::create('lu')
->withValue('Rg3vHJZnehYLjVg7qi3bZjzg')
->withMaxAge(0)
->withPath('/'),
],
[
'lu=Rg3vHJZnehYLjVg7qi3bZjzg; Path=/',
SetCookie::create('lu')
->withValue('Rg3vHJZnehYLjVg7qi3bZjzg')
->withMaxAge(null)
->withPath('/'),
],
];
}

Expand Down