Skip to content

Commit

Permalink
Merge pull request #88 from psr7-sessions/chore/upgrade-coding-standard
Browse files Browse the repository at this point in the history
Upgraded to `doctrine/coding-standard` 6.0
  • Loading branch information
Ocramius authored Aug 11, 2019
2 parents bf0fe98 + 7745665 commit 1b2f995
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 76 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"phpstan/phpstan-phpunit": "^0.11.2",
"phpstan/phpstan-strict-rules": "^0.11.1",
"squizlabs/php_codesniffer": "^3.4.2",
"doctrine/coding-standard": "^4.0.0"
"doctrine/coding-standard": "^6.0.0"
},
"replace": {
"ocramius/psr7-session": "self.version"
Expand Down
22 changes: 13 additions & 9 deletions src/Storageless/Http/SessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,27 @@

namespace PSR7Sessions\Storageless\Http;

use BadMethodCallException;
use Dflydev\FigCookies\FigResponseCookies;
use Dflydev\FigCookies\Modifier\SameSite;
use Dflydev\FigCookies\SetCookie;
use InvalidArgumentException;
use Lcobucci\Clock\Clock;
use Lcobucci\Clock\SystemClock;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Parser;
use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Token;
use Lcobucci\JWT\ValidationData;
use OutOfBoundsException;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use PSR7Sessions\Storageless\Session\DefaultSessionData;
use PSR7Sessions\Storageless\Session\LazySession;
use PSR7Sessions\Storageless\Session\SessionInterface;
use stdClass;

final class SessionMiddleware implements MiddlewareInterface
{
Expand Down Expand Up @@ -137,8 +141,8 @@ public static function fromAsymmetricKeyDefaults(
/**
* {@inheritdoc}
*
* @throws \BadMethodCallException
* @throws \InvalidArgumentException
* @throws BadMethodCallException
* @throws InvalidArgumentException
*/
public function process(Request $request, RequestHandlerInterface $delegate) : Response
{
Expand Down Expand Up @@ -168,7 +172,7 @@ private function parseToken(Request $request) : ?Token

try {
$token = $this->tokenParser->parse($cookies[$cookieName]);
} catch (\InvalidArgumentException $invalidToken) {
} catch (InvalidArgumentException $invalidToken) {
return null;
}

Expand All @@ -180,7 +184,7 @@ private function parseToken(Request $request) : ?Token
}

/**
* @throws \OutOfBoundsException
* @throws OutOfBoundsException
*/
private function extractSessionContainer(?Token $token) : SessionInterface
{
Expand All @@ -194,16 +198,16 @@ private function extractSessionContainer(?Token $token) : SessionInterface
}

return DefaultSessionData::fromDecodedTokenData(
(object) $token->getClaim(self::SESSION_CLAIM, new \stdClass())
(object) $token->getClaim(self::SESSION_CLAIM, new stdClass())
);
} catch (\BadMethodCallException $invalidToken) {
} catch (BadMethodCallException $invalidToken) {
return DefaultSessionData::newEmptySession();
}
}

/**
* @throws \BadMethodCallException
* @throws \InvalidArgumentException
* @throws BadMethodCallException
* @throws InvalidArgumentException
*/
private function appendToken(SessionInterface $sessionContainer, Response $response, ?Token $token) : Response
{
Expand All @@ -230,7 +234,7 @@ private function shouldTokenBeRefreshed(?Token $token) : bool
}

/**
* @throws \BadMethodCallException
* @throws BadMethodCallException
*/
private function getTokenCookie(SessionInterface $sessionContainer) : SetCookie
{
Expand Down
6 changes: 4 additions & 2 deletions src/Storageless/Session/DefaultSessionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
namespace PSR7Sessions\Storageless\Session;

use InvalidArgumentException;
use JsonSerializable;
use stdClass;
use const JSON_PRESERVE_ZERO_FRACTION;
use function array_key_exists;
use function count;
Expand Down Expand Up @@ -51,7 +53,7 @@ private function __construct()
{
}

public static function fromDecodedTokenData(\stdClass $data) : self
public static function fromDecodedTokenData(stdClass $data) : self
{
$instance = new self();

Expand Down Expand Up @@ -157,7 +159,7 @@ public function jsonSerialize() : object
}

/**
* @param int|bool|string|float|mixed[]|object|\JsonSerializable|null $value
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value
*
* @return int|bool|string|float|mixed[]
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Storageless/Session/LazySession.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public function jsonSerialize() : object

/**
* Get or initialize the session
*
*/
private function getRealSession() : SessionInterface
{
Expand All @@ -123,7 +122,6 @@ private function getRealSession() : SessionInterface

/**
* Type-safe wrapper that ensures that the given callback returns the expected type of object, when called
*
*/
private function loadSession() : SessionInterface
{
Expand Down
11 changes: 6 additions & 5 deletions src/Storageless/Session/SessionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@

namespace PSR7Sessions\Storageless\Session;

interface SessionInterface extends \JsonSerializable
use JsonSerializable;

interface SessionInterface extends JsonSerializable
{
/**
* Stores a given value in the session
*
* @param int|bool|string|float|mixed[]|object|\JsonSerializable|null $value allows any nested combination of the previous
* types as well
*
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $value allows any nested combination of the previous
* types as well
*/
public function set(string $key, $value) : void;

/**
* Retrieves a value from the session - if the value doesn't exist, then it uses the given $default, but transformed
* into a immutable and safely manipulated scalar or array
*
* @param int|bool|string|float|mixed[]|object|\JsonSerializable|null $default
* @param int|bool|string|float|mixed[]|object|JsonSerializable|null $default
*
* @return int|bool|string|float|mixed[]|null
*/
Expand Down
Loading

0 comments on commit 1b2f995

Please sign in to comment.