Skip to content

Commit 9c98312

Browse files
author
Jerome Thayananthajothy
committed
Refactor code for consistency by aligning array and string concatenation formatting across multiple files
1 parent db313d6 commit 9c98312

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

src/Fetch/Http/ClientHandler.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ClientHandler implements ClientHandlerInterface
3636
* Default options for the request.
3737
*/
3838
protected static array $defaultOptions = [
39-
'method' => 'GET',
39+
'method' => 'GET',
4040
'headers' => [],
4141
'timeout' => self::DEFAULT_TIMEOUT,
4242
];
@@ -201,7 +201,7 @@ protected function getFullUri(): string
201201
$parsedUrl = parse_url($uri);
202202
$separator = ! empty($parsedUrl['query']) ? '&' : '?';
203203

204-
return $uri.$separator.http_build_query($this->options['query']);
204+
return $uri . $separator . http_build_query($this->options['query']);
205205
}
206206

207207
return $uri;
@@ -217,13 +217,13 @@ protected function getFullUri(): string
217217
}
218218

219219
// Concatenate base URI and URI ensuring no double slashes
220-
$result = rtrim($baseUri, '/').'/'.ltrim($uri, '/');
220+
$result = rtrim($baseUri, '/') . '/' . ltrim($uri, '/');
221221
}
222222

223223
// If query parameters exist, append them to the URL
224224
if (! empty($this->options['query'])) {
225225
$separator = strpos($result, '?') !== false ? '&' : '?';
226-
$result .= $separator.http_build_query($this->options['query']);
226+
$result .= $separator . http_build_query($this->options['query']);
227227
}
228228

229229
return $result;
@@ -328,7 +328,7 @@ public function withMultipart(array $multipart): self
328328
*/
329329
public function withToken(string $token): self
330330
{
331-
$this->options['headers']['Authorization'] = 'Bearer '.$token;
331+
$this->options['headers']['Authorization'] = 'Bearer ' . $token;
332332

333333
return $this;
334334
}
@@ -645,8 +645,8 @@ public function hasOption(string $option): bool
645645
public function debug(): array
646646
{
647647
return [
648-
'uri' => $this->getFullUri(),
649-
'method' => $this->options['method'] ?? 'GET',
648+
'uri' => $this->getFullUri(),
649+
'method' => $this->options['method'] ?? 'GET',
650650
'headers' => $this->getHeaders(),
651651
'options' => array_diff_key($this->options, ['headers' => true]),
652652
];

src/Fetch/Http/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function json(bool $assoc = true, bool $throwOnError = true, int $depth =
5757
);
5858
} catch (JsonException $e) {
5959
if ($throwOnError) {
60-
throw new RuntimeException('Failed to decode JSON: '.$e->getMessage(), $e->getCode(), $e);
60+
throw new RuntimeException('Failed to decode JSON: ' . $e->getMessage(), $e->getCode(), $e);
6161
}
6262

6363
return $assoc ? [] : (object) [];
@@ -296,7 +296,7 @@ public function xml(int $options = 0, bool $throwOnError = true): ?SimpleXMLElem
296296
libxml_use_internal_errors(false);
297297

298298
if ($throwOnError) {
299-
throw new RuntimeException('Failed to parse XML: '.$e->getMessage(), $e->getCode(), $e);
299+
throw new RuntimeException('Failed to parse XML: ' . $e->getMessage(), $e->getCode(), $e);
300300
}
301301

302302
return null;

src/Fetch/Http/fetch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function fetch(?string $url = null, ?array $options = []): Response|ClientHandle
2929

3030
// Handle baseUri if provided
3131
if (isset($options['base_uri'])) {
32-
$url = rtrim($options['base_uri'], '/').'/'.ltrim($url, '/');
32+
$url = rtrim($options['base_uri'], '/') . '/' . ltrim($url, '/');
3333
unset($options['base_uri']);
3434
}
3535

@@ -44,7 +44,7 @@ function fetch(?string $url = null, ?array $options = []): Response|ClientHandle
4444

4545
// Add context to the exception
4646
throw new RuntimeException(
47-
"Fetch request to '$url' failed: ".$e->getMessage(),
47+
"Fetch request to '$url' failed: " . $e->getMessage(),
4848
$e->getCode(),
4949
$e
5050
);

tests/Integration/HttpTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@
7979

8080
// Make a request with custom headers
8181
fetch('https://example.com', [
82-
'client' => $this->client,
82+
'client' => $this->client,
8383
'headers' => [
8484
'X-API-Key' => 'test-key',
85-
'Accept' => 'application/json',
85+
'Accept' => 'application/json',
8686
],
8787
]);
8888

@@ -101,7 +101,7 @@
101101
// Make a request with query parameters
102102
fetch('https://example.com', [
103103
'client' => $this->client,
104-
'query' => [
104+
'query' => [
105105
'foo' => 'bar',
106106
'baz' => 'qux',
107107
],
@@ -124,7 +124,7 @@
124124

125125
// Make a request with a timeout
126126
fetch('https://example.com', [
127-
'client' => $this->client,
127+
'client' => $this->client,
128128
'timeout' => 5,
129129
]);
130130

@@ -145,7 +145,7 @@
145145
fetch('https://example.com', [
146146
'client' => $this->client,
147147
'method' => 'POST',
148-
'body' => $data,
148+
'body' => $data,
149149
]);
150150

151151
// Check request

tests/Unit/ClientHandlerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function getSyncClient(): \Psr\Http\Client\ClientInterface
190190

191191
$handler->withHeaders([
192192
'X-API-Key' => 'abc123',
193-
'Accept' => 'application/json',
193+
'Accept' => 'application/json',
194194
]);
195195

196196
$headers = $handler->getHeaders();
@@ -330,7 +330,7 @@ public function setUri(string $uri): void
330330
]);
331331

332332
$mockClient = new Client([
333-
'handler' => HandlerStack::create($mockHandler),
333+
'handler' => HandlerStack::create($mockHandler),
334334
'http_errors' => false, // Don't throw exceptions for HTTP errors
335335
]);
336336

@@ -475,8 +475,8 @@ public function setRequestUri(string $uri): void
475475

476476
$handler->withOptions([
477477
'connect_timeout' => 5,
478-
'debug' => true,
479-
'version' => '1.1',
478+
'debug' => true,
479+
'version' => '1.1',
480480
]);
481481

482482
$options = $handler->getOptions();

tests/Unit/FetchTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
fetch('https://example.com', [
7070
'method' => 'POST',
71-
'body' => $body,
71+
'body' => $body,
7272
'client' => $this->mockClient,
7373
]);
7474

@@ -84,7 +84,7 @@
8484

8585
fetch('endpoint', [
8686
'base_uri' => 'https://api.example.com/',
87-
'client' => $this->mockClient,
87+
'client' => $this->mockClient,
8888
]);
8989

9090
expect($this->historyContainer)->toHaveCount(1);
@@ -98,7 +98,7 @@
9898

9999
fetch('/endpoint', [
100100
'base_uri' => 'https://api.example.com',
101-
'client' => $this->mockClient,
101+
'client' => $this->mockClient,
102102
]);
103103

104104
expect($this->historyContainer)->toHaveCount(1);
@@ -180,7 +180,7 @@
180180

181181
fetch('https://example.com', [
182182
'method' => 'POST',
183-
'body' => ['data' => 'value'],
183+
'body' => ['data' => 'value'],
184184
'client' => $this->mockClient,
185185
]);
186186

@@ -191,13 +191,13 @@
191191

192192
fetch('https://example.com', [
193193
'method' => 'PUT',
194-
'body' => ['data' => 'updated'],
194+
'body' => ['data' => 'updated'],
195195
'client' => $this->mockClient,
196196
]);
197197

198198
fetch('https://example.com', [
199199
'method' => 'PATCH',
200-
'body' => ['data' => 'patched'],
200+
'body' => ['data' => 'patched'],
201201
'client' => $this->mockClient,
202202
]);
203203

@@ -218,9 +218,9 @@
218218
$this->mockHandler->append(new GuzzleResponse(200));
219219

220220
fetch('https://example.com', [
221-
'method' => 'POST',
221+
'method' => 'POST',
222222
'form_params' => ['username' => 'test', 'password' => 'secret'],
223-
'client' => $this->mockClient,
223+
'client' => $this->mockClient,
224224
]);
225225

226226
expect($this->historyContainer)->toHaveCount(1);
@@ -237,7 +237,7 @@
237237
$this->mockHandler->append(new GuzzleResponse(200));
238238

239239
fetch('https://example.com', [
240-
'query' => ['page' => 1, 'limit' => 10],
240+
'query' => ['page' => 1, 'limit' => 10],
241241
'client' => $this->mockClient,
242242
]);
243243

@@ -257,7 +257,7 @@
257257
fetch('https://example.com', [
258258
'headers' => [
259259
'X-API-Key' => 'abc123',
260-
'Accept' => 'application/json',
260+
'Accept' => 'application/json',
261261
],
262262
'client' => $this->mockClient,
263263
]);
@@ -274,7 +274,7 @@
274274

275275
fetch('https://example.com', [
276276
'timeout' => 15,
277-
'client' => $this->mockClient,
277+
'client' => $this->mockClient,
278278
]);
279279

280280
expect($this->historyContainer)->toHaveCount(1);
@@ -331,12 +331,12 @@
331331
$this->mockHandler->append(new GuzzleResponse(200));
332332

333333
fetch('https://example.com', [
334-
'method' => 'POST',
335-
'body' => ['name' => 'test'],
334+
'method' => 'POST',
335+
'body' => ['name' => 'test'],
336336
'headers' => ['X-Custom' => 'value'],
337337
'timeout' => 30,
338-
'query' => ['debug' => 1],
339-
'client' => $this->mockClient,
338+
'query' => ['debug' => 1],
339+
'client' => $this->mockClient,
340340
]);
341341

342342
expect($this->historyContainer)->toHaveCount(1);

tests/Unit/ResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function test_header_accessors()
213213
$response = new Response(
214214
200,
215215
[
216-
'Content-Type' => 'application/json',
216+
'Content-Type' => 'application/json',
217217
'X-Test-Header' => 'Test Value',
218218
]
219219
);

0 commit comments

Comments
 (0)