Skip to content

Commit 2ddfa0e

Browse files
committed
refactor: removes reason phrase until we have a "reason"...
1 parent 7c65178 commit 2ddfa0e

File tree

3 files changed

+5
-59
lines changed

3 files changed

+5
-59
lines changed

src/Providers/Http/DTO/Response.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
* @phpstan-type ResponseArrayShape array{
1919
* statusCode: int,
2020
* headers: array<string, list<string>>,
21-
* body?: string|null,
22-
* reasonPhrase: string
21+
* body?: string|null
2322
* }
2423
*
2524
* @extends AbstractDataTransferObject<ResponseArrayShape>
@@ -29,7 +28,6 @@ class Response extends AbstractDataTransferObject
2928
public const KEY_STATUS_CODE = 'statusCode';
3029
public const KEY_HEADERS = 'headers';
3130
public const KEY_BODY = 'body';
32-
public const KEY_REASON_PHRASE = 'reasonPhrase';
3331

3432
/**
3533
* @var int The HTTP status code.
@@ -51,11 +49,6 @@ class Response extends AbstractDataTransferObject
5149
*/
5250
protected ?string $body;
5351

54-
/**
55-
* @var string The reason phrase.
56-
*/
57-
protected string $reasonPhrase;
58-
5952
/**
6053
* Constructor.
6154
*
@@ -64,11 +57,10 @@ class Response extends AbstractDataTransferObject
6457
* @param int $statusCode The HTTP status code.
6558
* @param array<string, string|list<string>> $headers The response headers.
6659
* @param string|null $body The response body.
67-
* @param string $reasonPhrase The reason phrase.
6860
*
6961
* @throws InvalidArgumentException If the status code is invalid.
7062
*/
71-
public function __construct(int $statusCode, array $headers, ?string $body = null, string $reasonPhrase = '')
63+
public function __construct(int $statusCode, array $headers, ?string $body = null)
7264
{
7365
if ($statusCode < 100 || $statusCode >= 600) {
7466
throw new InvalidArgumentException('Invalid HTTP status code: ' . $statusCode);
@@ -78,7 +70,6 @@ public function __construct(int $statusCode, array $headers, ?string $body = nul
7870
$this->headers = $this->normalizeHeaderValues($headers);
7971
$this->headersMap = $this->buildHeadersMap($this->headers);
8072
$this->body = $body;
81-
$this->reasonPhrase = $reasonPhrase;
8273
}
8374

8475
/**
@@ -148,18 +139,6 @@ public function getBody(): ?string
148139
return $this->body;
149140
}
150141

151-
/**
152-
* Gets the reason phrase.
153-
*
154-
* @since n.e.x.t
155-
*
156-
* @return string The reason phrase.
157-
*/
158-
public function getReasonPhrase(): string
159-
{
160-
return $this->reasonPhrase;
161-
}
162-
163142
/**
164143
* Checks if the response indicates success.
165144
*
@@ -260,12 +239,8 @@ public static function getJsonSchema(): array
260239
'type' => ['string', 'null'],
261240
'description' => 'The response body.',
262241
],
263-
self::KEY_REASON_PHRASE => [
264-
'type' => 'string',
265-
'description' => 'The reason phrase.',
266-
],
267242
],
268-
'required' => [self::KEY_STATUS_CODE, self::KEY_HEADERS, self::KEY_REASON_PHRASE],
243+
'required' => [self::KEY_STATUS_CODE, self::KEY_HEADERS],
269244
];
270245
}
271246

@@ -281,7 +256,6 @@ public function toArray(): array
281256
$data = [
282257
self::KEY_STATUS_CODE => $this->statusCode,
283258
self::KEY_HEADERS => $this->headers,
284-
self::KEY_REASON_PHRASE => $this->reasonPhrase,
285259
];
286260

287261
if ($this->body !== null) {
@@ -301,14 +275,12 @@ public static function fromArray(array $array): self
301275
static::validateFromArrayData($array, [
302276
self::KEY_STATUS_CODE,
303277
self::KEY_HEADERS,
304-
self::KEY_REASON_PHRASE,
305278
]);
306279

307280
return new self(
308281
$array[self::KEY_STATUS_CODE],
309282
$array[self::KEY_HEADERS],
310-
$array[self::KEY_BODY] ?? null,
311-
$array[self::KEY_REASON_PHRASE]
283+
$array[self::KEY_BODY] ?? null
312284
);
313285
}
314286
}

src/Providers/Http/HttpTransporter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ private function convertFromPsr7Response(ResponseInterface $psr7Response): Respo
126126
return new Response(
127127
$psr7Response->getStatusCode(),
128128
$headers,
129-
$body === '' ? null : $body,
130-
$psr7Response->getReasonPhrase()
129+
$body === '' ? null : $body
131130
);
132131
}
133132
}

tests/unit/Providers/Http/HttpTransporterTest.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -167,31 +167,6 @@ public function testMultipleHeaderValues(): void
167167
$this->assertEquals(['single-value'], $sentRequest->getHeader('X-Custom'));
168168
}
169169

170-
/**
171-
* Tests response with reason phrase.
172-
*
173-
* @since n.e.x.t
174-
*
175-
* @covers ::send
176-
* @covers ::convertFromPsr7Response
177-
*
178-
* @return void
179-
*/
180-
public function testResponseReasonPhrase(): void
181-
{
182-
// Arrange
183-
$request = new Request('GET', 'https://api.example.com');
184-
$mockResponse = new Psr7Response(404, [], null, '1.1', 'Not Found');
185-
$this->mockClient->addResponse($mockResponse);
186-
187-
// Act
188-
$response = $this->transporter->send($request);
189-
190-
// Assert
191-
$this->assertEquals(404, $response->getStatusCode());
192-
$this->assertEquals('Not Found', $response->getReasonPhrase());
193-
}
194-
195170
/**
196171
* Tests using discovery when no dependencies provided.
197172
*

0 commit comments

Comments
 (0)