From ffb7f12176c1e3334d5021e166cab47d673a5d7f Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 20 Jun 2024 17:52:34 +0200 Subject: [PATCH 1/7] Prefix all sprintf() calls --- Factory/PsrHttpFactory.php | 2 +- Factory/UploadedFile.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Factory/PsrHttpFactory.php b/Factory/PsrHttpFactory.php index a09ed2c..276471b 100644 --- a/Factory/PsrHttpFactory.php +++ b/Factory/PsrHttpFactory.php @@ -50,7 +50,7 @@ public function __construct( $psr17Factory = match (true) { class_exists(DiscoveryPsr17Factory::class) => new DiscoveryPsr17Factory(), class_exists(NyholmPsr17Factory::class) => new NyholmPsr17Factory(), - default => throw new \LogicException(sprintf('You cannot use the "%s" as no PSR-17 factories have been provided. Try running "composer require php-http/discovery psr/http-factory-implementation:*".', self::class)), + default => throw new \LogicException(\sprintf('You cannot use the "%s" as no PSR-17 factories have been provided. Try running "composer require php-http/discovery psr/http-factory-implementation:*".', self::class)), }; $serverRequestFactory ??= $psr17Factory; diff --git a/Factory/UploadedFile.php b/Factory/UploadedFile.php index f680dd5..34d4058 100644 --- a/Factory/UploadedFile.php +++ b/Factory/UploadedFile.php @@ -59,7 +59,7 @@ public function move(string $directory, ?string $name = null): File try { $this->psrUploadedFile->moveTo((string) $target); } catch (\RuntimeException $e) { - throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, $e->getMessage()), 0, $e); + throw new FileException(\sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, $e->getMessage()), 0, $e); } @chmod($target, 0666 & ~umask()); From 55891cd317542b40164e52e17646fb5869cd3040 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 16 Jun 2024 17:17:26 +0200 Subject: [PATCH 2/7] chore: CS fixes --- Tests/Factory/PsrHttpFactoryTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/Factory/PsrHttpFactoryTest.php b/Tests/Factory/PsrHttpFactoryTest.php index 41629e8..67356c0 100644 --- a/Tests/Factory/PsrHttpFactoryTest.php +++ b/Tests/Factory/PsrHttpFactoryTest.php @@ -219,14 +219,14 @@ public function testUploadErrNoFile() [], [], [ - 'f1' => $file, - 'f2' => ['name' => null, 'type' => null, 'tmp_name' => null, 'error' => \UPLOAD_ERR_NO_FILE, 'size' => 0], - ], + 'f1' => $file, + 'f2' => ['name' => null, 'type' => null, 'tmp_name' => null, 'error' => \UPLOAD_ERR_NO_FILE, 'size' => 0], + ], [ - 'REQUEST_METHOD' => 'POST', - 'HTTP_HOST' => 'dunglas.fr', - 'HTTP_X_SYMFONY' => '2.8', - ], + 'REQUEST_METHOD' => 'POST', + 'HTTP_HOST' => 'dunglas.fr', + 'HTTP_X_SYMFONY' => '2.8', + ], 'Content' ); From e464593af6d9a6320e36f0714360e5f6dc67f005 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Mon, 1 Jul 2024 09:49:45 +0700 Subject: [PATCH 3/7] Remove redundant check --- Factory/HttpFoundationFactory.php | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Factory/HttpFoundationFactory.php b/Factory/HttpFoundationFactory.php index b1ee25a..32805e8 100644 --- a/Factory/HttpFoundationFactory.php +++ b/Factory/HttpFoundationFactory.php @@ -15,7 +15,6 @@ use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; use Psr\Http\Message\UploadedFileInterface; -use Psr\Http\Message\UriInterface; use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\Request; @@ -40,19 +39,17 @@ public function createRequest(ServerRequestInterface $psrRequest, bool $streamed $server = []; $uri = $psrRequest->getUri(); - if ($uri instanceof UriInterface) { - $server['SERVER_NAME'] = $uri->getHost(); - $server['SERVER_PORT'] = $uri->getPort() ?: ('https' === $uri->getScheme() ? 443 : 80); - $server['REQUEST_URI'] = $uri->getPath(); - $server['QUERY_STRING'] = $uri->getQuery(); + $server['SERVER_NAME'] = $uri->getHost(); + $server['SERVER_PORT'] = $uri->getPort() ?: ('https' === $uri->getScheme() ? 443 : 80); + $server['REQUEST_URI'] = $uri->getPath(); + $server['QUERY_STRING'] = $uri->getQuery(); - if ('' !== $server['QUERY_STRING']) { - $server['REQUEST_URI'] .= '?'.$server['QUERY_STRING']; - } + if ('' !== $server['QUERY_STRING']) { + $server['REQUEST_URI'] .= '?'.$server['QUERY_STRING']; + } - if ('https' === $uri->getScheme()) { - $server['HTTPS'] = 'on'; - } + if ('https' === $uri->getScheme()) { + $server['HTTPS'] = 'on'; } $server['REQUEST_METHOD'] = $psrRequest->getMethod(); From 5f48017193638a56e0f08eb6b04c1a7af0198347 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 1 Jul 2024 09:48:25 +0200 Subject: [PATCH 4/7] Remove uniqid() from tempnam() calls --- Factory/HttpFoundationFactory.php | 2 +- Tests/Factory/HttpFoundationFactoryTest.php | 2 +- Tests/Factory/PsrHttpFactoryTest.php | 11 ++++++++--- Tests/Functional/CovertTest.php | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Factory/HttpFoundationFactory.php b/Factory/HttpFoundationFactory.php index 32805e8..052b963 100644 --- a/Factory/HttpFoundationFactory.php +++ b/Factory/HttpFoundationFactory.php @@ -104,7 +104,7 @@ private function createUploadedFile(UploadedFileInterface $psrUploadedFile): Upl */ protected function getTemporaryPath(): string { - return tempnam(sys_get_temp_dir(), uniqid('symfony', true)); + return tempnam(sys_get_temp_dir(), 'symfony'); } public function createResponse(ResponseInterface $psrResponse, bool $streamed = false): Response diff --git a/Tests/Factory/HttpFoundationFactoryTest.php b/Tests/Factory/HttpFoundationFactoryTest.php index ed2b7e9..7456ea3 100644 --- a/Tests/Factory/HttpFoundationFactoryTest.php +++ b/Tests/Factory/HttpFoundationFactoryTest.php @@ -198,7 +198,7 @@ public function testCreateUploadedFileWithError() private function createUploadedFile(string $content, int $error, string $clientFileName, string $clientMediaType): UploadedFile { - $filePath = tempnam($this->tmpDir, uniqid()); + $filePath = tempnam($this->tmpDir, 'sftest'); file_put_contents($filePath, $content); return new UploadedFile($filePath, filesize($filePath), $error, $clientFileName, $clientMediaType); diff --git a/Tests/Factory/PsrHttpFactoryTest.php b/Tests/Factory/PsrHttpFactoryTest.php index 67356c0..f5b09c8 100644 --- a/Tests/Factory/PsrHttpFactoryTest.php +++ b/Tests/Factory/PsrHttpFactoryTest.php @@ -131,7 +131,7 @@ public function testGetContentCanBeCalledAfterRequestCreation() private function createUploadedFile(string $content, string $originalName, string $mimeType, int $error): UploadedFile { - $path = tempnam($this->tmpDir, uniqid()); + $path = $this->createTempFile(); file_put_contents($path, $content); return new UploadedFile($path, $originalName, $mimeType, $error, true); @@ -182,7 +182,7 @@ public function testCreateResponseFromStreamed() public function testCreateResponseFromBinaryFile() { - $path = tempnam($this->tmpDir, uniqid()); + $path = $this->createTempFile(); file_put_contents($path, 'Binary'); $response = new BinaryFileResponse($path); @@ -194,7 +194,7 @@ public function testCreateResponseFromBinaryFile() public function testCreateResponseFromBinaryFileWithRange() { - $path = tempnam($this->tmpDir, uniqid()); + $path = $this->createTempFile(); file_put_contents($path, 'Binary'); $request = new Request(); @@ -287,4 +287,9 @@ private static function buildHttpMessageFactory(): PsrHttpFactory return new PsrHttpFactory($factory, $factory, $factory, $factory); } + + private function createTempFile(): string + { + return tempnam($this->tmpDir, 'sftest'); + } } diff --git a/Tests/Functional/CovertTest.php b/Tests/Functional/CovertTest.php index b0ea766..23bdbb9 100644 --- a/Tests/Functional/CovertTest.php +++ b/Tests/Functional/CovertTest.php @@ -217,7 +217,7 @@ public static function responseProvider(): array private static function createUploadedFile(string $content, string $originalName, string $mimeType, int $error): UploadedFile { - $path = tempnam(sys_get_temp_dir(), uniqid()); + $path = tempnam(sys_get_temp_dir(), 'sftest'); file_put_contents($path, $content); return new UploadedFile($path, $originalName, $mimeType, $error, true); From 321635b903e1a7d8d3b0205bda49b626349b250b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 6 Jul 2024 20:13:11 +0200 Subject: [PATCH 5/7] do not use uniqid() in tests updates the remaining tests that were not covered by #57665 --- Tests/Factory/HttpFoundationFactoryTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Factory/HttpFoundationFactoryTest.php b/Tests/Factory/HttpFoundationFactoryTest.php index 7456ea3..ed71b36 100644 --- a/Tests/Factory/HttpFoundationFactoryTest.php +++ b/Tests/Factory/HttpFoundationFactoryTest.php @@ -172,15 +172,15 @@ public function testCreateUploadedFile() $symfonyUploadedFile = $this->callCreateUploadedFile($uploadedFile); $size = $symfonyUploadedFile->getSize(); - $uniqid = uniqid(); - $symfonyUploadedFile->move($this->tmpDir, $uniqid); + $filename = 'upload'; + $symfonyUploadedFile->move($this->tmpDir, $filename); $this->assertEquals($uploadedFile->getSize(), $size); $this->assertEquals(\UPLOAD_ERR_OK, $symfonyUploadedFile->getError()); $this->assertEquals('myfile.txt', $symfonyUploadedFile->getClientOriginalName()); $this->assertEquals('txt', $symfonyUploadedFile->getClientOriginalExtension()); $this->assertEquals('text/plain', $symfonyUploadedFile->getClientMimeType()); - $this->assertEquals('An uploaded file.', file_get_contents($this->tmpDir.'/'.$uniqid)); + $this->assertEquals('An uploaded file.', file_get_contents($this->tmpDir.'/'.$filename)); } public function testCreateUploadedFileWithError() From ae2fde1771df55e15d46c2f5ccf87e2d88841640 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Wed, 31 Jul 2024 16:13:26 +0200 Subject: [PATCH 6/7] Remove unused code and unnecessary `else` branches --- Factory/PsrHttpFactory.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Factory/PsrHttpFactory.php b/Factory/PsrHttpFactory.php index 276471b..d3b5467 100644 --- a/Factory/PsrHttpFactory.php +++ b/Factory/PsrHttpFactory.php @@ -195,8 +195,7 @@ public function createResponse(Response $symfonyResponse): ResponseInterface } $protocolVersion = $symfonyResponse->getProtocolVersion(); - $response = $response->withProtocolVersion($protocolVersion); - return $response; + return $response->withProtocolVersion($protocolVersion); } } From 03f2f72319e7acaf2a9f6fcbe30ef17eec51594f Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Thu, 26 Sep 2024 10:09:09 +0200 Subject: [PATCH 7/7] Remove unused imports --- Tests/Fixtures/ServerRequest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/Fixtures/ServerRequest.php b/Tests/Fixtures/ServerRequest.php index 99b7abb..f7ea108 100644 --- a/Tests/Fixtures/ServerRequest.php +++ b/Tests/Fixtures/ServerRequest.php @@ -11,7 +11,6 @@ namespace Symfony\Bridge\PsrHttpMessage\Tests\Fixtures; -use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\StreamInterface; use Psr\Http\Message\UriInterface; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy