Skip to content

Commit

Permalink
Refactor coding style and fix import sorting algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Thavarshan committed Oct 19, 2024
1 parent f7cfae9 commit a5ab566
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pint.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}
},
"ordered_imports": {
"sort_algorithm": "length"
"sort_algorithm": "alpha"
},
"nullable_type_declaration_for_default_null_value": false
}
Expand Down
6 changes: 3 additions & 3 deletions src/Fetch/Http/ClientHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ClientHandler implements ClientHandlerInterface
* Default options for the request.
*/
protected static array $defaultOptions = [
'method' => 'GET',
'method' => 'GET',
'headers' => [],
'timeout' => self::DEFAULT_TIMEOUT,
];
Expand Down Expand Up @@ -196,7 +196,7 @@ protected function getFullUri(): string
}

// Concatenate base URI and URI ensuring no double slashes
return rtrim($baseUri, '/').'/'.ltrim($uri, '/');
return rtrim($baseUri, '/') . '/' . ltrim($uri, '/');
}

/**
Expand Down Expand Up @@ -258,7 +258,7 @@ public function baseUri(string $baseUri): self
*/
public function withToken(string $token): self
{
$this->options['headers']['Authorization'] = 'Bearer '.$token;
$this->options['headers']['Authorization'] = 'Bearer ' . $token;

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Fetch/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function json(bool $assoc = true, bool $throwOnError = true)
}

if ($throwOnError) {
throw new RuntimeException('Failed to decode JSON: '.json_last_error_msg());
throw new RuntimeException('Failed to decode JSON: ' . json_last_error_msg());
}

return null; // or return an empty array/object depending on your needs.
Expand Down
2 changes: 1 addition & 1 deletion src/Fetch/Http/fetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function fetch(?string $url = null, ?array $options = []): Response|ClientHandle

// Handle baseUri if provided
if (isset($options['base_uri'])) {
$url = rtrim($options['base_uri'], '/').'/'.ltrim($url, '/');
$url = rtrim($options['base_uri'], '/') . '/' . ltrim($url, '/');
unset($options['base_uri']);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/FetchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

$response = fetch('http://localhost', [
'headers' => ['Authorization' => 'Bearer token'],
'client' => $mockClient,
'client' => $mockClient,
]);

expect($response->text())->toBe('Headers checked');
Expand All @@ -105,7 +105,7 @@
});

$response = fetch('http://localhost', [
'query' => ['foo' => 'bar', 'baz' => 'qux'],
'query' => ['foo' => 'bar', 'baz' => 'qux'],
'client' => $mockClient,
]);

Expand Down Expand Up @@ -167,7 +167,7 @@

$response = fetch('http://localhost/users', [
'method' => 'POST',
'body' => json_encode(['name' => 'John']),
'body' => json_encode(['name' => 'John']),
'client' => $mockClient,
]);

Expand Down

0 comments on commit a5ab566

Please sign in to comment.