From c1f63c29d7eb74ebd417c3936717e1767a529742 Mon Sep 17 00:00:00 2001 From: Roy Date: Fri, 25 Nov 2022 13:29:57 +0100 Subject: [PATCH 1/4] Prevent possible warnings unset variables --- src/ServerRequest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ServerRequest.php b/src/ServerRequest.php index 43cbb502..b2aa382d 100644 --- a/src/ServerRequest.php +++ b/src/ServerRequest.php @@ -144,10 +144,10 @@ private static function normalizeNestedFileSpec(array $files = []): array foreach (array_keys($files['tmp_name']) as $key) { $spec = [ 'tmp_name' => $files['tmp_name'][$key], - 'size' => $files['size'][$key], - 'error' => $files['error'][$key], - 'name' => $files['name'][$key], - 'type' => $files['type'][$key], + 'size' => $files['size'][$key] ?? null, + 'error' => $files['error'][$key] ?? null, + 'name' => $files['name'][$key] ?? null, + 'type' => $files['type'][$key] ?? null, ]; $normalizedFiles[$key] = self::createUploadedFileFromSpec($spec); } From 64aed30e0be375850cd5d91e59ec48097679f9c5 Mon Sep 17 00:00:00 2001 From: Roy Date: Tue, 4 Apr 2023 14:02:56 +0200 Subject: [PATCH 2/4] Extra test cases --- tests/ServerRequestTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/ServerRequestTest.php b/tests/ServerRequestTest.php index f7605120..15340f2a 100644 --- a/tests/ServerRequestTest.php +++ b/tests/ServerRequestTest.php @@ -163,6 +163,7 @@ public function dataNormalizeFiles(): iterable 'tmp_name' => [ 0 => '/tmp/php/hp9hskjhf', 1 => '/tmp/php/php1h4j1o', + 2 => '/tmp/php/w0ensl4ar', ], 'error' => [ 0 => '0', @@ -173,6 +174,11 @@ public function dataNormalizeFiles(): iterable 1 => '7349', ], ], + 'minimum_data' => [ + 'tmp_name' => [ + 0 => '/tmp/php/hp9hskjhf', + ], + ], 'nested' => [ 'name' => [ 'other' => 'Flag.txt', @@ -227,6 +233,18 @@ public function dataNormalizeFiles(): iterable 'Image.png', 'image/png' ), + 2 => new UploadedFile( + '/tmp/php/w0ensl4ar', + null, + UPLOAD_ERR_OK + ), + ], + 'minimum_data' => [ + 0 => new UploadedFile( + '/tmp/php/hp9hskjhf', + 0, + UPLOAD_ERR_OK + ), ], 'nested' => [ 'other' => new UploadedFile( From 8b323ef3843abb26825ad7933a5cf3541c4cf8e3 Mon Sep 17 00:00:00 2001 From: Roy Date: Wed, 5 Apr 2023 10:07:59 +0200 Subject: [PATCH 3/4] update baselines --- phpstan-baseline.neon | 10 ---------- psalm-baseline.xml | 41 ++++++++++++----------------------------- 2 files changed, 12 insertions(+), 39 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 25961072..795788f2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -220,16 +220,6 @@ parameters: count: 1 path: src/PumpStream.php - - - message: "#^Parameter \\#2 \\$subject of function preg_match expects string, mixed given\\.$#" - count: 1 - path: src/Request.php - - - - message: "#^Property GuzzleHttp\\\\Psr7\\\\Request\\:\\:\\$requestTarget \\(string\\|null\\) does not accept mixed\\.$#" - count: 1 - path: src/Request.php - - message: "#^Method GuzzleHttp\\\\Psr7\\\\ServerRequest\\:\\:normalizeNestedFileSpec\\(\\) should return array\\ but returns array\\\\|Psr\\\\Http\\\\Message\\\\UploadedFileInterface\\>\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 2673b872..ea4ce4a2 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,16 +1,9 @@ - - - $this->stream - - - - - $this->stream - - + + \AllowDynamicProperties + call_user_func($this->_fn___toString) call_user_func($this->_fn_close) @@ -34,16 +27,6 @@ $file - - - $this->stream - - - - - $this->stream - - MessageInterface @@ -68,15 +51,18 @@ $filename $filename - - $this->stream - isset($this->headerNames['host']) + + + (int) $code + (string) $reasonPhrase + + $normalizedFiles @@ -94,6 +80,9 @@ $this->stream + + (int) $whence + isset($this->stream) isset($this->stream) @@ -107,12 +96,6 @@ isset($this->stream) - - - $this->stream - $this->stream - - $result From a50a4527e72e8ac30fd5be9946d9c8e8e440550c Mon Sep 17 00:00:00 2001 From: Roy Date: Wed, 5 Apr 2023 10:38:10 +0200 Subject: [PATCH 4/4] Revert "update baselines" This reverts commit 8b323ef3843abb26825ad7933a5cf3541c4cf8e3. --- phpstan-baseline.neon | 10 ++++++++++ psalm-baseline.xml | 41 +++++++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 795788f2..25961072 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -220,6 +220,16 @@ parameters: count: 1 path: src/PumpStream.php + - + message: "#^Parameter \\#2 \\$subject of function preg_match expects string, mixed given\\.$#" + count: 1 + path: src/Request.php + + - + message: "#^Property GuzzleHttp\\\\Psr7\\\\Request\\:\\:\\$requestTarget \\(string\\|null\\) does not accept mixed\\.$#" + count: 1 + path: src/Request.php + - message: "#^Method GuzzleHttp\\\\Psr7\\\\ServerRequest\\:\\:normalizeNestedFileSpec\\(\\) should return array\\ but returns array\\\\|Psr\\\\Http\\\\Message\\\\UploadedFileInterface\\>\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index ea4ce4a2..2673b872 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,9 +1,16 @@ + + + $this->stream + + + + + $this->stream + + - - \AllowDynamicProperties - call_user_func($this->_fn___toString) call_user_func($this->_fn_close) @@ -27,6 +34,16 @@ $file + + + $this->stream + + + + + $this->stream + + MessageInterface @@ -51,18 +68,15 @@ $filename $filename + + $this->stream + isset($this->headerNames['host']) - - - (int) $code - (string) $reasonPhrase - - $normalizedFiles @@ -80,9 +94,6 @@ $this->stream - - (int) $whence - isset($this->stream) isset($this->stream) @@ -96,6 +107,12 @@ isset($this->stream) + + + $this->stream + $this->stream + + $result