diff --git a/composer.json b/composer.json index ef4273d..a1b09e2 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,11 @@ "hansott/psr7-cookies": "^2.0 || ^1.0", "psr/http-message": "^1.0", "react/cache": "^0.5.0 || ^0.6.0 || ^1.0.0", - "react/http": "^1.0.0", + "react/http": "^1.0 || ^0.8", "react/promise": "^2.7" }, "require-dev": { + "thecodingmachine/safe": "^0.1 || ^1.0", "wyrihaximus/async-test-utilities": "^1.1" }, "config": { diff --git a/composer.lock b/composer.lock index 9949808..4c31877 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6521d4ee26bc1e241fc82482c738acaf", + "content-hash": "86727d999320e55e6322f0017dcd12e2", "packages": [ { "name": "evenement/evenement", @@ -286,16 +286,16 @@ }, { "name": "react/http", - "version": "v1.0.0", + "version": "v1.1.0", "source": { "type": "git", "url": "https://github.com/reactphp/http.git", - "reference": "865694453c95122f8972b9ed7961efb3c517fc5e" + "reference": "754b0c18545d258922ffa907f3b18598280fdecd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/http/zipball/865694453c95122f8972b9ed7961efb3c517fc5e", - "reference": "865694453c95122f8972b9ed7961efb3c517fc5e", + "url": "https://api.github.com/repos/reactphp/http/zipball/754b0c18545d258922ffa907f3b18598280fdecd", + "reference": "754b0c18545d258922ffa907f3b18598280fdecd", "shasum": "" }, "require": { @@ -305,8 +305,8 @@ "react/event-loop": "^1.0 || ^0.5", "react/promise": "^2.3 || ^1.2.1", "react/promise-stream": "^1.1", - "react/socket": "^1.1", - "react/stream": "^1.0 || ^0.7.5", + "react/socket": "^1.6", + "react/stream": "^1.1", "ringcentral/psr7": "^1.2" }, "require-dev": { @@ -314,7 +314,7 @@ "clue/http-proxy-react": "^1.3", "clue/reactphp-ssh-proxy": "^1.0", "clue/socks-react": "^1.0", - "phpunit/phpunit": "^9.0 || ^5.7 || ^4.8.35" + "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35" }, "type": "library", "autoload": { @@ -362,7 +362,17 @@ "server", "streaming" ], - "time": "2020-07-11T13:29:43+00:00" + "funding": [ + { + "url": "https://github.com/WyriHaximus", + "type": "github" + }, + { + "url": "https://github.com/clue", + "type": "github" + } + ], + "time": "2020-09-11T11:01:51+00:00" }, { "name": "react/promise", @@ -7151,5 +7161,6 @@ "platform-dev": [], "platform-overrides": { "php": "7.3" - } + }, + "plugin-api-version": "1.1.0" } diff --git a/phpstan.neon b/phpstan.neon index 6dec066..a8f2b92 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,8 +3,10 @@ parameters: - '#Constructor in [a-zA-Z0-9\\_]+ has parameter \$[a-zA-Z0-9_]+ with default value.#' - '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9_]+\(\) has parameter \$[a-zA-Z0-9_]+ with a nullable type declaration.#' - '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9_]+\(\) has parameter \$[a-zA-Z0-9_]+ with null as default value.#' + - '#Array \(array\) does not accept key int|string.#' + - '#In method \"WyriHaximus\\React\\Http\\Middleware\\SessionMiddleware::fetchSessionFromRequest\", caught \"Throwable\" must be rethrown.#' classesAllowedToBeExtended: - ApiClients\Tools\TestUtilities\TestCase includes: - - vendor/wyrihaximus/async-test-utilities/rules.neon \ No newline at end of file + - vendor/wyrihaximus/async-test-utilities/rules.neon diff --git a/src/Session.php b/src/Session.php index a1eb4f4..501b75d 100644 --- a/src/Session.php +++ b/src/Session.php @@ -10,7 +10,7 @@ final class Session private $id; /** - * @var array + * @var array */ private $contents; @@ -30,9 +30,9 @@ final class Session private $status = \PHP_SESSION_NONE; /** - * @param string $id - * @param array $contents - * @param SessionIdInterface $sessionId + * @param string $id + * @param array $contents + * @param SessionIdInterface $sessionId */ public function __construct(string $id, array $contents, SessionIdInterface $sessionId) { @@ -54,7 +54,7 @@ public function getId(): string } /** - * @param array $contents + * @param array $contents */ public function setContents(array $contents): void { @@ -62,7 +62,7 @@ public function setContents(array $contents): void } /** - * @return array + * @return array */ public function getContents(): array { @@ -123,6 +123,9 @@ public function regenerate(): bool return true; } + /** + * @return array + */ public function toArray(): array { return [ @@ -134,14 +137,14 @@ public function toArray(): array } /** - * @param array $session + * @param array $session * @param bool $clone * @throws \InvalidArgumentException * @return Session */ public function fromArray(array $session, bool $clone = true): self { - if (!isset($session['id']) || !isset($session['contents']) || !isset($session['oldIds']) || !isset($session['status'])) { + if (!\array_key_exists('id', $session) || !\array_key_exists('contents', $session) || !\array_key_exists('oldIds', $session) || !\array_key_exists('status', $session)) { throw new \InvalidArgumentException('Session array most contain "id", "contents", "oldIds", and "status".'); } diff --git a/src/SessionMiddleware.php b/src/SessionMiddleware.php index 426bded..1cdca22 100644 --- a/src/SessionMiddleware.php +++ b/src/SessionMiddleware.php @@ -47,7 +47,7 @@ final class SessionMiddleware /** * @param string $cookieName * @param CacheInterface $cache - * @param array $cookieParams + * @param array $cookieParams * @param SessionIdInterface|null $sessionId */ public function __construct( @@ -107,6 +107,7 @@ private function fetchSessionFromRequest(ServerRequestInterface $request): Promi }); } catch (Throwable $et) { // Do nothing, only a not found will be thrown so generating our own id now + // @ignoreException } return resolve(new Session($id, [], $this->sessionId)); diff --git a/tests/InspectableArrayCache.php b/tests/InspectableArrayCache.php index 6d81be0..4b38079 100644 --- a/tests/InspectableArrayCache.php +++ b/tests/InspectableArrayCache.php @@ -9,11 +9,11 @@ final class InspectableArrayCache implements CacheInterface { - /** @var array */ + /** @var array */ private $data = []; /** - * @return array + * @return array */ public function getData(): array { @@ -27,7 +27,7 @@ public function getData(): array */ public function get($key, $default = null): PromiseInterface { - if (!isset($this->data[$key])) { + if (!\array_key_exists($key, $this->data)) { return resolve($default); } @@ -67,7 +67,7 @@ public function getMultiple(array $keys, $default = null) { $items = []; foreach ($keys as $key) { - if (isset($this->data[$key])) { + if (!\array_key_exists($key, $this->data)) { $items[$key] = $this->data[$key]; continue; @@ -123,6 +123,6 @@ public function clear() */ public function has($key) { - return resolve(isset($this->data[$key])); + return resolve(\array_key_exists($key, $this->data)); } } diff --git a/tests/SessionId/RandomBytesTest.php b/tests/SessionId/RandomBytesTest.php index 843ab70..6438704 100644 --- a/tests/SessionId/RandomBytesTest.php +++ b/tests/SessionId/RandomBytesTest.php @@ -28,7 +28,7 @@ public function testGenerate(int $size): void for ($i = 0; $i < 15; $i++) { $id = $randomBytes->generate(); /** @var string $id */ - $id = \hex2bin($id); + $id = \Safe\hex2bin($id); self::assertSame($size, \strlen($id)); } } diff --git a/tests/SessionMiddlewareTest.php b/tests/SessionMiddlewareTest.php index dcf0b5c..315ee64 100644 --- a/tests/SessionMiddlewareTest.php +++ b/tests/SessionMiddlewareTest.php @@ -405,7 +405,7 @@ function () { return [ $t, - \sprintf( + \Safe\sprintf( '; expires=%s', \gmdate('D, d-M-Y H:i:s T', \time() + $t) ), @@ -419,7 +419,7 @@ function () { return [ $t, - \sprintf( + \Safe\sprintf( '; expires=%s', \gmdate('D, d-M-Y H:i:s T', \time() + $t) ), @@ -433,7 +433,7 @@ function () { return [ $t, - \sprintf( + \Safe\sprintf( '; expires=%s', \gmdate('D, d-M-Y H:i:s T', \time() + $t) ), diff --git a/tests/SessionTest.php b/tests/SessionTest.php index e844cb1..405dc39 100644 --- a/tests/SessionTest.php +++ b/tests/SessionTest.php @@ -177,6 +177,8 @@ public function provideSessionArrayWithMissingItems(): iterable /** * @dataProvider provideSessionArrayWithMissingItems + * + * @param array $session */ public function testFromArrayThrowsOnMissingElements(array $session): void {