diff --git a/composer.json b/composer.json index b42461a1..56f52d3d 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "psalm/plugin-phpunit": "^0.17.0", "roave/infection-static-analysis-plugin": "^1.22.0", "squizlabs/php_codesniffer": "^3.7.1", - "vimeo/psalm": "^4.26.0" + "vimeo/psalm": "^4.27.0" }, "config": { "allow-plugins": { diff --git a/composer.lock b/composer.lock index f05b6657..27fa41b9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c2495095fe742b7ea6ccd9d560f6895d", + "content-hash": "57f23d47b480bc21c8b59163990ebaa1", "packages": [ { "name": "dflydev/fig-cookies", @@ -5502,16 +5502,16 @@ }, { "name": "vimeo/psalm", - "version": "4.26.0", + "version": "4.27.0", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "6998fabb2bf528b65777bf9941920888d23c03ac" + "reference": "faf106e717c37b8c81721845dba9de3d8deed8ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/6998fabb2bf528b65777bf9941920888d23c03ac", - "reference": "6998fabb2bf528b65777bf9941920888d23c03ac", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/faf106e717c37b8c81721845dba9de3d8deed8ff", + "reference": "faf106e717c37b8c81721845dba9de3d8deed8ff", "shasum": "" }, "require": { @@ -5603,9 +5603,9 @@ ], "support": { "issues": "https://github.com/vimeo/psalm/issues", - "source": "https://github.com/vimeo/psalm/tree/4.26.0" + "source": "https://github.com/vimeo/psalm/tree/4.27.0" }, - "time": "2022-07-31T13:10:26+00:00" + "time": "2022-08-31T13:47:09+00:00" }, { "name": "webmozart/assert", diff --git a/src/Storageless/Http/SessionMiddleware.php b/src/Storageless/Http/SessionMiddleware.php index 556f3261..2f239f96 100644 --- a/src/Storageless/Http/SessionMiddleware.php +++ b/src/Storageless/Http/SessionMiddleware.php @@ -46,6 +46,7 @@ use PSR7Sessions\Storageless\Session\SessionInterface; use stdClass; +use function assert; use function date_default_timezone_get; use function sprintf; @@ -55,9 +56,7 @@ final class SessionMiddleware implements MiddlewareInterface public const SESSION_ATTRIBUTE = 'session'; public const DEFAULT_COOKIE = '__Secure-slsession'; public const DEFAULT_REFRESH_TIME = 60; - private Configuration $config; - private SetCookie $defaultCookie; public function __construct( @@ -209,8 +208,12 @@ private function appendToken(SessionInterface $sessionContainer, Response $respo private function shouldTokenBeRefreshed(Token|null $token): bool { + $refreshTime = $this->clock->now()->sub(new DateInterval(sprintf('PT%sS', $this->refreshTime))); + + assert($refreshTime !== false); + return $token !== null - && $token->hasBeenIssuedBefore($this->clock->now()->sub(new DateInterval(sprintf('PT%sS', $this->refreshTime)))); + && $token->hasBeenIssuedBefore($refreshTime); } /** @throws BadMethodCallException */ @@ -237,6 +240,8 @@ private function getExpirationCookie(): SetCookie { $expirationDate = $this->clock->now()->modify('-30 days'); + assert($expirationDate !== false); + return $this ->defaultCookie ->withValue(null)