From df3edc6829deb37a79a468b26f54ccbed5b01ff5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 15 Sep 2022 20:04:39 +0700 Subject: [PATCH] Apply PHP 7.4 syntax and typed property Signed-off-by: Abdul Malik Ikhsan --- src/LazySession.php | 12 +++++------- src/Session.php | 13 ++++--------- src/SessionMiddleware.php | 4 ++-- test/ConfigProviderTest.php | 3 +-- test/LazySessionTest.php | 3 +-- test/SessionMiddlewareTest.php | 8 +++----- 6 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/LazySession.php b/src/LazySession.php index ccbd71b..da327ba 100644 --- a/src/LazySession.php +++ b/src/LazySession.php @@ -5,6 +5,8 @@ namespace Mezzio\Session; use Mezzio\Session\Exception\NotInitializableException; +use Mezzio\Session\SessionInterface; +use Mezzio\Session\SessionPersistenceInterface; use Psr\Http\Message\ServerRequestInterface; /** @@ -21,18 +23,14 @@ final class LazySession implements SessionInterface, InitializeSessionIdInterface { - /** @var SessionPersistenceInterface */ - private $persistence; + private SessionPersistenceInterface $persistence; - /** @var null|SessionInterface */ - private $proxiedSession; + private ?SessionInterface $proxiedSession = null; /** * Request instance to use when calling $persistence->initializeSessionFromRequest() - * - * @var ServerRequestInterface */ - private $request; + private ServerRequestInterface $request; public function __construct(SessionPersistenceInterface $persistence, ServerRequestInterface $request) { diff --git a/src/Session.php b/src/Session.php index e76cd95..2244784 100644 --- a/src/Session.php +++ b/src/Session.php @@ -21,7 +21,7 @@ class Session implements * * @var array */ - private $data; + private array $data; /** * The session identifier, if any. @@ -31,13 +31,10 @@ class Session implements * when it is time to persist the session, instead of relying on state in * the persistence instance (which may be shared between multiple * requests). - * - * @var string */ - private $id; + private string $id; - /** @var bool */ - private $isRegenerated = false; + private bool $isRegenerated = false; /** * Original data provided to the constructor. @@ -48,10 +45,8 @@ class Session implements /** * Lifetime of the session cookie. - * - * @var int */ - private $sessionLifetime = 0; + private int $sessionLifetime = 0; /** @param array $data */ public function __construct(array $data, string $id = '') diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index 63cd9f6..611d035 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -4,6 +4,7 @@ namespace Mezzio\Session; +use Mezzio\Session\SessionPersistenceInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; @@ -13,8 +14,7 @@ class SessionMiddleware implements MiddlewareInterface { public const SESSION_ATTRIBUTE = 'session'; - /** @var SessionPersistenceInterface */ - private $persistence; + private SessionPersistenceInterface $persistence; public function __construct(SessionPersistenceInterface $persistence) { diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 40127f6..49d97d1 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -9,8 +9,7 @@ class ConfigProviderTest extends TestCase { - /** @var ConfigProvider */ - private $provider; + private ConfigProvider $provider; public function setUp(): void { diff --git a/test/LazySessionTest.php b/test/LazySessionTest.php index a1ca8c2..c8c7c23 100644 --- a/test/LazySessionTest.php +++ b/test/LazySessionTest.php @@ -35,8 +35,7 @@ class LazySessionTest extends TestCase */ private $request; - /** @var LazySession */ - private $session; + private LazySession $session; public function setUp(): void { diff --git a/test/SessionMiddlewareTest.php b/test/SessionMiddlewareTest.php index 4e89ea6..7c1a179 100644 --- a/test/SessionMiddlewareTest.php +++ b/test/SessionMiddlewareTest.php @@ -73,11 +73,9 @@ public function testMiddlewareCreatesLazySessionAndPassesItToDelegateAndPersists ->expects($this->once()) ->method('persistSession') ->with( - $this->callback(function (SessionInterface $session) use ($persistence, $request) { - return $session instanceof LazySession - && $persistence === $this->getAttribute($session, 'persistence') - && $request === $this->getAttribute($session, 'request'); - }), + $this->callback(fn(SessionInterface $session) => $session instanceof LazySession + && $persistence === $this->getAttribute($session, 'persistence') + && $request === $this->getAttribute($session, 'request')), $response ) ->willReturn($response);