Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b3966b1

Browse filesBrowse files
committed
[PsrHttpMessageBridge] Add native types where possible
1 parent e7e39b5 commit b3966b1
Copy full SHA for b3966b1

13 files changed

+100
-261
lines changed

‎EventListener/PsrResponseListener.php

Copy file name to clipboardExpand all lines: EventListener/PsrResponseListener.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
final class PsrResponseListener implements EventSubscriberInterface
2828
{
29-
private $httpFoundationFactory;
29+
private readonly HttpFoundationFactoryInterface $httpFoundationFactory;
3030

3131
public function __construct(HttpFoundationFactoryInterface $httpFoundationFactory = null)
3232
{

‎Factory/HttpFoundationFactory.php

Copy file name to clipboardExpand all lines: Factory/HttpFoundationFactory.php
+4-6Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@
2828
class HttpFoundationFactory implements HttpFoundationFactoryInterface
2929
{
3030
/**
31-
* @var int The maximum output buffering size for each iteration when sending the response
31+
* @param int $responseBufferMaxLength The maximum output buffering size for each iteration when sending the response
3232
*/
33-
private $responseBufferMaxLength;
34-
35-
public function __construct(int $responseBufferMaxLength = 16372)
36-
{
37-
$this->responseBufferMaxLength = $responseBufferMaxLength;
33+
public function __construct(
34+
private readonly int $responseBufferMaxLength = 16372,
35+
) {
3836
}
3937

4038
public function createRequest(ServerRequestInterface $psrRequest, bool $streamed = false): Request

‎Factory/PsrHttpFactory.php

Copy file name to clipboardExpand all lines: Factory/PsrHttpFactory.php
+6-11Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,12 @@
3333
*/
3434
class PsrHttpFactory implements HttpMessageFactoryInterface
3535
{
36-
private $serverRequestFactory;
37-
private $streamFactory;
38-
private $uploadedFileFactory;
39-
private $responseFactory;
40-
41-
public function __construct(ServerRequestFactoryInterface $serverRequestFactory, StreamFactoryInterface $streamFactory, UploadedFileFactoryInterface $uploadedFileFactory, ResponseFactoryInterface $responseFactory)
42-
{
43-
$this->serverRequestFactory = $serverRequestFactory;
44-
$this->streamFactory = $streamFactory;
45-
$this->uploadedFileFactory = $uploadedFileFactory;
46-
$this->responseFactory = $responseFactory;
36+
public function __construct(
37+
private readonly ServerRequestFactoryInterface $serverRequestFactory,
38+
private readonly StreamFactoryInterface $streamFactory,
39+
private readonly UploadedFileFactoryInterface $uploadedFileFactory,
40+
private readonly ResponseFactoryInterface $responseFactory,
41+
) {
4742
}
4843

4944
public function createRequest(Request $symfonyRequest): ServerRequestInterface

‎Factory/UploadedFile.php

Copy file name to clipboardExpand all lines: Factory/UploadedFile.php
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
*/
2222
class UploadedFile extends BaseUploadedFile
2323
{
24-
private $psrUploadedFile;
25-
private $test = false;
24+
private bool $test = false;
2625

27-
public function __construct(UploadedFileInterface $psrUploadedFile, callable $getTemporaryPath)
28-
{
26+
public function __construct(
27+
private readonly UploadedFileInterface $psrUploadedFile,
28+
callable $getTemporaryPath,
29+
) {
2930
$error = $psrUploadedFile->getError();
3031
$path = '';
3132

@@ -45,8 +46,6 @@ public function __construct(UploadedFileInterface $psrUploadedFile, callable $ge
4546
$psrUploadedFile->getError(),
4647
$this->test
4748
);
48-
49-
$this->psrUploadedFile = $psrUploadedFile;
5049
}
5150

5251
public function move(string $directory, string $name = null): File

‎Tests/Factory/PsrHttpFactoryTest.php

Copy file name to clipboardExpand all lines: Tests/Factory/PsrHttpFactoryTest.php
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@
2929
*/
3030
class PsrHttpFactoryTest extends TestCase
3131
{
32-
/** @var HttpMessageFactoryInterface */
33-
private $factory;
34-
35-
/** @var string */
36-
private $tmpDir;
32+
private HttpMessageFactoryInterface $factory;
33+
private string $tmpDir;
3734

3835
protected function buildHttpMessageFactory(): HttpMessageFactoryInterface
3936
{

‎Tests/Fixtures/App/Controller/PsrRequestController.php

Copy file name to clipboardExpand all lines: Tests/Fixtures/App/Controller/PsrRequestController.php
+4-7Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111

1212
final class PsrRequestController
1313
{
14-
private $responseFactory;
15-
private $streamFactory;
16-
17-
public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
18-
{
19-
$this->responseFactory = $responseFactory;
20-
$this->streamFactory = $streamFactory;
14+
public function __construct(
15+
private readonly ResponseFactoryInterface $responseFactory,
16+
private readonly StreamFactoryInterface $streamFactory,
17+
) {
2118
}
2219

2320
public function serverRequestAction(ServerRequestInterface $request): ResponseInterface

‎Tests/Fixtures/Message.php

Copy file name to clipboardExpand all lines: Tests/Fixtures/Message.php
+10-36Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,19 @@
2121
*/
2222
class Message implements MessageInterface
2323
{
24-
private $version = '1.1';
25-
private $headers = [];
26-
private $body;
27-
28-
public function __construct(string $version = '1.1', array $headers = [], StreamInterface $body = null)
29-
{
30-
$this->version = $version;
31-
$this->headers = $headers;
32-
$this->body = $body ?? new Stream();
24+
public function __construct(
25+
private readonly string $version = '1.1',
26+
private array $headers = [],
27+
private readonly StreamInterface $body = new Stream(),
28+
) {
3329
}
3430

3531
public function getProtocolVersion(): string
3632
{
3733
return $this->version;
3834
}
3935

40-
/**
41-
* {@inheritdoc}
42-
*
43-
* @return static
44-
*/
45-
public function withProtocolVersion($version): MessageInterface
36+
public function withProtocolVersion($version): never
4637
{
4738
throw new \BadMethodCallException('Not implemented.');
4839
}
@@ -67,34 +58,19 @@ public function getHeaderLine($name): string
6758
return $this->hasHeader($name) ? implode(',', $this->headers[$name]) : '';
6859
}
6960

70-
/**
71-
* {@inheritdoc}
72-
*
73-
* @return static
74-
*/
75-
public function withHeader($name, $value): MessageInterface
61+
public function withHeader($name, $value): static
7662
{
7763
$this->headers[$name] = (array) $value;
7864

7965
return $this;
8066
}
8167

82-
/**
83-
* {@inheritdoc}
84-
*
85-
* @return static
86-
*/
87-
public function withAddedHeader($name, $value): MessageInterface
68+
public function withAddedHeader($name, $value): never
8869
{
8970
throw new \BadMethodCallException('Not implemented.');
9071
}
9172

92-
/**
93-
* {@inheritdoc}
94-
*
95-
* @return static
96-
*/
97-
public function withoutHeader($name): MessageInterface
73+
public function withoutHeader($name): static
9874
{
9975
unset($this->headers[$name]);
10076

@@ -108,10 +84,8 @@ public function getBody(): StreamInterface
10884

10985
/**
11086
* {@inheritdoc}
111-
*
112-
* @return static
11387
*/
114-
public function withBody(StreamInterface $body): MessageInterface
88+
public function withBody(StreamInterface $body): never
11589
{
11690
throw new \BadMethodCallException('Not implemented.');
11791
}

‎Tests/Fixtures/Response.php

Copy file name to clipboardExpand all lines: Tests/Fixtures/Response.php
+8-11Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,26 @@
1919
*/
2020
class Response extends Message implements ResponseInterface
2121
{
22-
private $statusCode;
23-
24-
public function __construct(string $version = '1.1', array $headers = [], StreamInterface $body = null, int $statusCode = 200)
25-
{
22+
public function __construct(
23+
string $version = '1.1',
24+
array $headers = [],
25+
StreamInterface $body = new Stream(),
26+
private readonly int $statusCode = 200,
27+
) {
2628
parent::__construct($version, $headers, $body);
27-
28-
$this->statusCode = $statusCode;
2929
}
3030

3131
public function getStatusCode(): int
3232
{
3333
return $this->statusCode;
3434
}
3535

36-
/**
37-
* @return static
38-
*/
39-
public function withStatus($code, $reasonPhrase = ''): ResponseInterface
36+
public function withStatus($code, $reasonPhrase = ''): never
4037
{
4138
throw new \BadMethodCallException('Not implemented.');
4239
}
4340

44-
public function getReasonPhrase(): string
41+
public function getReasonPhrase(): never
4542
{
4643
throw new \BadMethodCallException('Not implemented.');
4744
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.