Skip to content

Commit bf625f4

Browse files
thefeqygithub-actions[bot]
authored andcommitted
Fix styling
1 parent 805bfe4 commit bf625f4

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

src/Clients/GrokClient.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace GrokPHP\Client\Clients;
44

5-
use GrokPHP\Client\Contracts\ClientInterface;
6-
use GrokPHP\Client\Traits\HandlesRequests;
7-
use GrokPHP\Client\Config\GrokConfig;
85
use GrokPHP\Client\Config\ChatOptions;
6+
use GrokPHP\Client\Config\GrokConfig;
7+
use GrokPHP\Client\Contracts\ClientInterface;
98
use GrokPHP\Client\Enums\DefaultConfig;
9+
use GrokPHP\Client\Traits\HandlesRequests;
1010
use GuzzleHttp\Client;
1111

1212
/**
@@ -19,7 +19,7 @@ class GrokClient implements ClientInterface
1919
/**
2020
* Constructs a new instance of GrokClient.
2121
*
22-
* @param GrokConfig $config The Grok API configuration.
22+
* @param GrokConfig $config The Grok API configuration.
2323
*/
2424
public function __construct(
2525
private readonly GrokConfig $config
@@ -33,8 +33,6 @@ public function __construct(
3333

3434
/**
3535
* Returns the API key from the configuration.
36-
*
37-
* @return string
3836
*/
3937
public function getApiKey(): string
4038
{
@@ -44,7 +42,7 @@ public function getApiKey(): string
4442
/**
4543
* Overrides the HTTP client (useful for testing).
4644
*
47-
* @param Client $client Custom Guzzle client.
45+
* @param Client $client Custom Guzzle client.
4846
*/
4947
public function setHttpClient(Client $client): void
5048
{
@@ -54,8 +52,8 @@ public function setHttpClient(Client $client): void
5452
/**
5553
* Sends a chat request to Grok API.
5654
*
57-
* @param array $messages Chat messages
58-
* @param ChatOptions $options Chat configuration
55+
* @param array $messages Chat messages
56+
* @param ChatOptions $options Chat configuration
5957
* @return array API response
6058
*/
6159
public function chat(array $messages, ChatOptions $options): array

src/Config/ChatOptions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
class ChatOptions
1212
{
1313
public Model $model;
14+
1415
public float $temperature;
16+
1517
public bool $stream;
1618

1719
public function __construct(

src/Contracts/ClientInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public function setHttpClient(Client $client): void;
1818
/**
1919
* Sends a chat request to the Grok API.
2020
*
21-
* @param array $messages Chat messages in API format.
22-
* @param ChatOptions $options Additional request options.
21+
* @param array $messages Chat messages in API format.
22+
* @param ChatOptions $options Additional request options.
2323
* @return array The API response.
2424
*/
2525
public function chat(array $messages, ChatOptions $options): array;

src/Traits/HandlesRequests.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,32 @@
1313
trait HandlesRequests
1414
{
1515
protected Client $httpClient;
16+
1617
protected string $apiKey;
1718

1819
/**
1920
* Sends a request to the Grok API.
2021
*
21-
* @param string $endpoint API endpoint
22-
* @param array $payload Request payload
22+
* @param string $endpoint API endpoint
23+
* @param array $payload Request payload
2324
* @return array API response
25+
*
2426
* @throws GrokException If the request fails
2527
*/
2628
public function sendRequest(string $endpoint, array $payload): array
2729
{
2830
try {
2931
$response = $this->httpClient->post($endpoint, [
3032
'headers' => [
31-
'Authorization' => 'Bearer ' . $this->apiKey,
33+
'Authorization' => 'Bearer '.$this->apiKey,
3234
'Content-Type' => 'application/json',
3335
],
3436
'json' => $payload,
3537
]);
3638

3739
return json_decode($response->getBody()->getContents(), true, flags: JSON_THROW_ON_ERROR);
3840
} catch (RequestException $e) {
39-
throw new GrokException('API request failed: ' . $e->getMessage());
41+
throw new GrokException('API request failed: '.$e->getMessage());
4042
}
4143
}
4244
}

tests/Feature/GrokClientTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

33
use GrokPHP\Client\Clients\GrokClient;
4-
use GrokPHP\Client\Config\GrokConfig;
54
use GrokPHP\Client\Config\ChatOptions;
5+
use GrokPHP\Client\Config\GrokConfig;
66
use GrokPHP\Client\Enums\Model;
77
use GrokPHP\Client\Exceptions\GrokException;
88
use GuzzleHttp\Client;
9-
use GuzzleHttp\Psr7\Response;
109
use GuzzleHttp\Handler\MockHandler;
1110
use GuzzleHttp\HandlerStack;
11+
use GuzzleHttp\Psr7\Response;
1212

1313
beforeEach(function () {
1414
$this->validApiKey = 'valid-api-key';
@@ -23,7 +23,7 @@
2323
// Mock a successful Grok API response
2424
$mock = new MockHandler([
2525
new Response(200, [], json_encode([
26-
'choices' => [['message' => ['content' => 'Hello from Grok!']]]
26+
'choices' => [['message' => ['content' => 'Hello from Grok!']]],
2727
])),
2828
]);
2929

@@ -36,7 +36,7 @@
3636
$client->setHttpClient($httpClient);
3737

3838
// Set default chat options
39-
$options = new ChatOptions();
39+
$options = new ChatOptions;
4040

4141
// Call the chat method
4242
$response = $client->chat(
@@ -55,7 +55,7 @@
5555
// Mock a successful Grok API response
5656
$mock = new MockHandler([
5757
new Response(200, [], json_encode([
58-
'choices' => [['message' => ['content' => 'Hello from Grok Vision Beta!']]]
58+
'choices' => [['message' => ['content' => 'Hello from Grok Vision Beta!']]],
5959
])),
6060
]);
6161

@@ -86,7 +86,7 @@
8686
test('expired API key results in payment required error', function () {
8787
// Mock a failed response due to expired API key
8888
$mock = new MockHandler([
89-
new Response(402, [], json_encode(['error' => 'Payment Required']))
89+
new Response(402, [], json_encode(['error' => 'Payment Required'])),
9090
]);
9191

9292
$handlerStack = HandlerStack::create($mock);
@@ -98,10 +98,10 @@
9898
$client->setHttpClient($httpClient);
9999

100100
// Set chat options
101-
$options = new ChatOptions();
101+
$options = new ChatOptions;
102102

103103
// Call chat and expect an exception
104-
expect(fn() => $client->chat([['role' => 'user', 'content' => 'Hello!']], $options))
104+
expect(fn () => $client->chat([['role' => 'user', 'content' => 'Hello!']], $options))
105105
->toThrow(GrokException::class, 'API request failed');
106106
});
107107

@@ -111,7 +111,7 @@
111111
test('invalid API key results in unauthorized error', function () {
112112
// Mock a failed response due to invalid API key
113113
$mock = new MockHandler([
114-
new Response(401, [], json_encode(['error' => 'Unauthorized']))
114+
new Response(401, [], json_encode(['error' => 'Unauthorized'])),
115115
]);
116116

117117
$handlerStack = HandlerStack::create($mock);
@@ -123,9 +123,9 @@
123123
$client->setHttpClient($httpClient);
124124

125125
// Set chat options
126-
$options = new ChatOptions();
126+
$options = new ChatOptions;
127127

128128
// Call chat and expect an exception
129-
expect(fn() => $client->chat([['role' => 'user', 'content' => 'Hello!']], $options))
129+
expect(fn () => $client->chat([['role' => 'user', 'content' => 'Hello!']], $options))
130130
->toThrow(GrokException::class, 'API request failed');
131131
});

tests/Unit/ChatOptionsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
namespace GrokPHP\Client\Tests\Unit;
44

5-
use PHPUnit\Framework\Attributes\Test;
6-
use PHPUnit\Framework\TestCase;
75
use GrokPHP\Client\Config\ChatOptions;
8-
use GrokPHP\Client\Enums\Model;
96
use GrokPHP\Client\Enums\DefaultConfig;
7+
use GrokPHP\Client\Enums\Model;
8+
use PHPUnit\Framework\Attributes\Test;
9+
use PHPUnit\Framework\TestCase;
1010

1111
class ChatOptionsTest extends TestCase
1212
{
1313
#[Test]
1414
public function it_applies_default_chat_options()
1515
{
16-
$options = new ChatOptions();
16+
$options = new ChatOptions;
1717

1818
expect($options->model)->toBe(Model::tryFrom(DefaultConfig::MODEL->value) ?? Model::GROK_2);
1919
expect($options->temperature)->toBe((float) DefaultConfig::TEMPERATURE->value);

0 commit comments

Comments
 (0)