Skip to content

Commit 41ad4d7

Browse files
committed
phpstan level 9
opencode (opus 4.5)
1 parent 9c35a0b commit 41ad4d7

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=100 --verbose --coverage=build/phpunit",
7373
"test:integration": "vendor/bin/phpunit --testsuite=Integration --cache-directory=build/phpunit",
7474
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
75-
"test:static-analysis": "mkdir -p build && bash -c 'vendor/bin/phpstan analyse src --no-progress --level=8 --error-format=junit | tee build/phpstan.junit.xml; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
75+
"test:static-analysis": "mkdir -p build && bash -c 'vendor/bin/phpstan analyse src --no-progress --level=9 --error-format=junit | tee build/phpstan.junit.xml; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
7676
"test:unit": "vendor/bin/phpunit --testsuite=Unit --coverage-text --coverage-clover=build/phpunit/clover.xml --coverage-html=build/phpunit/coverage-html --coverage-xml=build/phpunit/coverage-xml --log-junit=build/phpunit/junit.xml --cache-directory=build/phpunit"
7777
}
7878
}

phpstan.neon

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1 @@
11
parameters:
2-
ignoreErrors:
3-
-
4-
message: '#uploadedFiles#'
5-
path: %currentWorkingDirectory%/src/PsrRequestFactory.php
6-
-
7-
message: '#createStreamFromFile#'
8-
path: %currentWorkingDirectory%/src/PsrRequestFactory.php
9-
-
10-
message: '#createUploadedFile#'
11-
path: %currentWorkingDirectory%/src/PsrRequestFactory.php
12-
-
13-
message: '#Parameter \#1 \$string of method Psr\\Http\\Message\\StreamInterface\:\:write\(\) expects string, string\|false given\.#'
14-
path: %currentWorkingDirectory%/src/PsrRequestFactory.php

src/PsrRequestFactory.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,42 @@ public function create(SwooleRequest $swooleRequest): ServerRequestInterface
3636
$request = $request->withCookieParams($swooleRequest->cookie ?? []);
3737
$request = $request->withQueryParams($swooleRequest->get ?? []);
3838
$request = $request->withParsedBody($swooleRequest->post ?? []);
39-
$request = $request->withUploadedFiles($this->uploadedFiles($swooleRequest->files ?? []));
4039

41-
$request->getBody()->write($swooleRequest->rawContent());
40+
/** @var array<string, array{tmp_name?: string, size: null|int, error: int, name: null|string, type: null|string}> $files */
41+
$files = $swooleRequest->files ?? [];
42+
43+
$request = $request->withUploadedFiles($this->uploadedFiles($files));
44+
45+
if (false !== $rawContent = $swooleRequest->rawContent()) {
46+
$request->getBody()->write($rawContent);
47+
}
4248

4349
return $request;
4450
}
4551

4652
/**
47-
* @param array<string, array<string, int|string>> $files
53+
* @param array<string, array<string, mixed>> $files
4854
*
49-
* @return array<string, UploadedFileInterface>
55+
* @return array<string, mixed>
5056
*/
5157
private function uploadedFiles(array $files): array
5258
{
5359
$uploadedFiles = [];
5460
foreach ($files as $key => $file) {
55-
$uploadedFiles[$key] = isset($file['tmp_name']) ? $this->createUploadedFile($file) : $this->uploadedFiles($file);
61+
if (isset($file['tmp_name'])) {
62+
/** @var array{tmp_name: string, size: null|int, error: int, name: null|string, type: null|string} $file */
63+
$uploadedFiles[$key] = $this->createUploadedFile($file);
64+
} else {
65+
/** @var array<string, array<string, mixed>> $file */
66+
$uploadedFiles[$key] = $this->uploadedFiles($file);
67+
}
5668
}
5769

5870
return $uploadedFiles;
5971
}
6072

6173
/**
62-
* @param array<string, int|string> $file
74+
* @param array{tmp_name: string, size: null|int, error: int, name: null|string, type: null|string} $file
6375
*/
6476
private function createUploadedFile(array $file): UploadedFileInterface
6577
{

0 commit comments

Comments
 (0)