Skip to content

Commit 18c9e82

Browse files
committed
minor #118 Add native types where possible (derrabus)
This PR was merged into the 2.2-dev branch. Discussion ---------- Add native types where possible This PR improves the typing throughout the codebase: * Native types are added where possible without a BC break * PHPDoc``@return`` annotations have been added to prevent deprecations triggered by ErrorHandler * More PHPDoc has been added where a native type cannot be set as long as we support PHP 7.2. * PHPUnit data providers have been declared `static`. Commits ------- 4fd4323 Add native types where possible
2 parents 28a732c + 4fd4323 commit 18c9e82

12 files changed

+35
-19
lines changed

Factory/HttpFoundationFactory.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public function __construct(int $responseBufferMaxLength = 16372)
4141

4242
/**
4343
* {@inheritdoc}
44+
*
45+
* @return Request
4446
*/
4547
public function createRequest(ServerRequestInterface $psrRequest, bool $streamed = false)
4648
{
@@ -121,6 +123,8 @@ protected function getTemporaryPath()
121123

122124
/**
123125
* {@inheritdoc}
126+
*
127+
* @return Response
124128
*/
125129
public function createResponse(ResponseInterface $psrResponse, bool $streamed = false)
126130
{

Factory/PsrHttpFactory.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
namespace Symfony\Bridge\PsrHttpMessage\Factory;
1313

1414
use Psr\Http\Message\ResponseFactoryInterface;
15+
use Psr\Http\Message\ResponseInterface;
1516
use Psr\Http\Message\ServerRequestFactoryInterface;
17+
use Psr\Http\Message\ServerRequestInterface;
1618
use Psr\Http\Message\StreamFactoryInterface;
1719
use Psr\Http\Message\UploadedFileFactoryInterface;
1820
use Psr\Http\Message\UploadedFileInterface;
@@ -45,6 +47,8 @@ public function __construct(ServerRequestFactoryInterface $serverRequestFactory,
4547

4648
/**
4749
* {@inheritdoc}
50+
*
51+
* @return ServerRequestInterface
4852
*/
4953
public function createRequest(Request $symfonyRequest)
5054
{
@@ -84,10 +88,8 @@ public function createRequest(Request $symfonyRequest)
8488

8589
/**
8690
* Converts Symfony uploaded files array to the PSR one.
87-
*
88-
* @return array
8991
*/
90-
private function getFiles(array $uploadedFiles)
92+
private function getFiles(array $uploadedFiles): array
9193
{
9294
$files = [];
9395

@@ -108,10 +110,8 @@ private function getFiles(array $uploadedFiles)
108110

109111
/**
110112
* Creates a PSR-7 UploadedFile instance from a Symfony one.
111-
*
112-
* @return UploadedFileInterface
113113
*/
114-
private function createUploadedFile(UploadedFile $symfonyUploadedFile)
114+
private function createUploadedFile(UploadedFile $symfonyUploadedFile): UploadedFileInterface
115115
{
116116
return $this->uploadedFileFactory->createUploadedFile(
117117
$this->streamFactory->createStreamFromFile(
@@ -126,6 +126,8 @@ private function createUploadedFile(UploadedFile $symfonyUploadedFile)
126126

127127
/**
128128
* {@inheritdoc}
129+
*
130+
* @return ResponseInterface
129131
*/
130132
public function createResponse(Response $symfonyResponse)
131133
{

Factory/UploadedFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(UploadedFileInterface $psrUploadedFile, callable $ge
5252
/**
5353
* {@inheritdoc}
5454
*/
55-
public function move($directory, $name = null): File
55+
public function move(string $directory, string $name = null): File
5656
{
5757
if (!$this->isValid() || $this->test) {
5858
return parent::move($directory, $name);

Tests/EventListener/PsrResponseListenerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ public function testDoesNotConvertControllerResult()
4646
self::assertFalse($event->hasResponse());
4747
}
4848

49+
/**
50+
* @param mixed $controllerResult
51+
*/
4952
private function createEventMock($controllerResult): ViewEvent
5053
{
5154
return new ViewEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MAIN_REQUEST, $controllerResult);

Tests/Factory/HttpFoundationFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function testCreateUploadedFileWithError()
196196
$symfonyUploadedFile->move($this->tmpDir, 'shouldFail.txt');
197197
}
198198

199-
private function createUploadedFile($content, $error, $clientFileName, $clientMediaType): UploadedFile
199+
private function createUploadedFile(string $content, int $error, string $clientFileName, string $clientMediaType): UploadedFile
200200
{
201201
$filePath = tempnam($this->tmpDir, uniqid());
202202
file_put_contents($filePath, $content);

Tests/Factory/PsrHttpFactoryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
*/
2929
class PsrHttpFactoryTest extends TestCase
3030
{
31+
/** @var HttpMessageFactoryInterface */
3132
private $factory;
33+
34+
/** @var string */
3235
private $tmpDir;
3336

3437
protected function buildHttpMessageFactory(): HttpMessageFactoryInterface
@@ -135,7 +138,7 @@ public function testGetContentCanBeCalledAfterRequestCreation()
135138
$this->assertSame('Content', $request->getContent());
136139
}
137140

138-
private function createUploadedFile($content, $originalName, $mimeType, $error)
141+
private function createUploadedFile(string $content, string $originalName, string $mimeType, int $error): UploadedFile
139142
{
140143
$path = tempnam($this->tmpDir, uniqid());
141144
file_put_contents($path, $content);

Tests/Fixtures/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Message implements MessageInterface
2525
private $headers = [];
2626
private $body;
2727

28-
public function __construct($version = '1.1', array $headers = [], StreamInterface $body = null)
28+
public function __construct(string $version = '1.1', array $headers = [], StreamInterface $body = null)
2929
{
3030
$this->version = $version;
3131
$this->headers = $headers;

Tests/Fixtures/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Response extends Message implements ResponseInterface
2121
{
2222
private $statusCode;
2323

24-
public function __construct($version = '1.1', array $headers = [], StreamInterface $body = null, $statusCode = 200)
24+
public function __construct(string $version = '1.1', array $headers = [], StreamInterface $body = null, int $statusCode = 200)
2525
{
2626
parent::__construct($version, $headers, $body);
2727

Tests/Fixtures/ServerRequest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class ServerRequest extends Message implements ServerRequestInterface
3131
private $data;
3232
private $attributes;
3333

34-
public function __construct($version = '1.1', array $headers = [], StreamInterface $body = null, $requestTarget = '/', $method = 'GET', $uri = null, array $server = [], array $cookies = [], array $query = [], array $uploadedFiles = [], $data = null, array $attributes = [])
34+
/**
35+
* @param UriInterface|string|null $uri
36+
* @param array|object|null $data
37+
*/
38+
public function __construct(string $version = '1.1', array $headers = [], StreamInterface $body = null, string $requestTarget = '/', string $method = 'GET', $uri = null, array $server = [], array $cookies = [], array $query = [], array $uploadedFiles = [], $data = null, array $attributes = [])
3539
{
3640
parent::__construct($version, $headers, $body);
3741

Tests/Fixtures/Stream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Stream implements StreamInterface
2121
private $stringContent;
2222
private $eof = true;
2323

24-
public function __construct($stringContent = '')
24+
public function __construct(string $stringContent = '')
2525
{
2626
$this->stringContent = $stringContent;
2727
}

0 commit comments

Comments
 (0)
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