Skip to content

Commit

Permalink
Apply PHP 7.4 syntax and typed property
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Malik Ikhsan <[email protected]>
  • Loading branch information
samsonasik committed Sep 15, 2022
1 parent 60b3b7d commit df3edc6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 27 deletions.
12 changes: 5 additions & 7 deletions src/LazySession.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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)
{
Expand Down
13 changes: 4 additions & 9 deletions src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Session implements
*
* @var array<string, mixed>
*/
private $data;
private array $data;

/**
* The session identifier, if any.
Expand All @@ -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.
Expand All @@ -48,10 +45,8 @@ class Session implements

/**
* Lifetime of the session cookie.
*
* @var int
*/
private $sessionLifetime = 0;
private int $sessionLifetime = 0;

/** @param array<string, mixed> $data */
public function __construct(array $data, string $id = '')
Expand Down
4 changes: 2 additions & 2 deletions src/SessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down
3 changes: 1 addition & 2 deletions test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

class ConfigProviderTest extends TestCase
{
/** @var ConfigProvider */
private $provider;
private ConfigProvider $provider;

public function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions test/LazySessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class LazySessionTest extends TestCase
*/
private $request;

/** @var LazySession */
private $session;
private LazySession $session;

public function setUp(): void
{
Expand Down
8 changes: 3 additions & 5 deletions test/SessionMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit df3edc6

Please sign in to comment.