Skip to content

Commit 5848d1e

Browse files
Fix further CI errors (code sniffer)
1 parent 6b5f4ed commit 5848d1e

32 files changed

Lines changed: 341 additions & 331 deletions

phpcs.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
<exclude-pattern>*/vendor/*</exclude-pattern>
1414
<exclude-pattern>*/coverage/*</exclude-pattern>
1515

16+
<!-- Allow descriptive test method names in test files -->
17+
<rule ref="PSR1.Methods.CamelCapsMethodName">
18+
<exclude-pattern>*/tests/*</exclude-pattern>
19+
</rule>
20+
21+
<!-- Allow multiple classes in test files -->
22+
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
23+
<exclude-pattern>*/tests/*</exclude-pattern>
24+
</rule>
25+
1626
<!-- Show progress -->
1727
<arg value="p"/>
1828

src/Integrations/LLMClientInterface.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,38 @@
44

55
/**
66
* LLM Client Interface
7-
*
7+
*
88
* Abstract interface for LLM providers (OpenAI, Anthropic, etc.)
99
* Allows AIAgent to work with any LLM provider without tight coupling.
1010
*/
1111
interface LLMClientInterface
1212
{
1313
/**
1414
* Generate a chat completion response
15-
*
15+
*
1616
* @param array $requestData Request data including messages, model, etc.
1717
* @return array Response data from the LLM provider
1818
*/
1919
public function chat(array $requestData): array;
20-
20+
2121
/**
2222
* Get supported models for this provider
23-
*
23+
*
2424
* @return array List of supported model names
2525
*/
2626
public function getSupportedModels(): array;
27-
27+
2828
/**
2929
* Get provider name
30-
*
30+
*
3131
* @return string Provider name (e.g., 'openai', 'anthropic')
3232
*/
3333
public function getProviderName(): string;
34-
34+
3535
/**
3636
* Check if the provider supports tool calling
37-
*
37+
*
3838
* @return bool True if tool calling is supported
3939
*/
4040
public function supportsToolCalling(): bool;
41-
}
41+
}

src/Integrations/MockOpenAIClient.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,33 @@
44

55
/**
66
* Mock OpenAI Client for Testing
7-
*
7+
*
88
* Mock implementation of OpenAIClient interface for testing purposes.
99
* Returns predefined responses without making actual API calls.
1010
*/
1111
class MockOpenAIClient implements OpenAIClient
1212
{
1313
private array $responses = [];
1414
private bool $echoInput = true;
15-
15+
1616
public function __construct(array $responses = [], bool $echoInput = true)
1717
{
1818
$this->responses = $responses;
1919
$this->echoInput = $echoInput;
2020
}
21-
21+
2222
public function chat(array $context): array
2323
{
2424
$userMessage = $this->extractUserMessage($context);
25-
25+
2626
if (isset($this->responses[$userMessage])) {
2727
$response = $this->responses[$userMessage];
2828
} elseif ($this->echoInput) {
2929
$response = $userMessage;
3030
} else {
3131
$response = 'Mock response for: ' . $userMessage;
3232
}
33-
33+
3434
return [
3535
'choices' => [
3636
[
@@ -48,32 +48,32 @@ public function chat(array $context): array
4848
]
4949
];
5050
}
51-
51+
5252
private function extractUserMessage(array $context): string
5353
{
5454
$messages = $context['messages'] ?? [];
55-
55+
5656
foreach ($messages as $message) {
5757
if ($message['role'] === 'user') {
5858
return $message['content'];
5959
}
6060
}
61-
61+
6262
return '';
6363
}
64-
64+
6565
public function setResponses(array $responses): self
6666
{
6767
$this->responses = $responses;
6868
return $this;
6969
}
70-
70+
7171
public function setEchoInput(bool $echoInput): self
7272
{
7373
$this->echoInput = $echoInput;
7474
return $this;
7575
}
76-
76+
7777
public function getSupportedModels(): array
7878
{
7979
return [
@@ -82,14 +82,14 @@ public function getSupportedModels(): array
8282
'mock-model'
8383
];
8484
}
85-
85+
8686
public function getProviderName(): string
8787
{
8888
return 'mock-openai';
8989
}
90-
90+
9191
public function supportsToolCalling(): bool
9292
{
9393
return true;
9494
}
95-
}
95+
}

src/Integrations/OpenAIClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Provides a contract for making calls to OpenAI's API,
99
* allowing for both real and mock implementations.
10-
*
10+
*
1111
* @deprecated Use LLMClientInterface instead for better abstraction
1212
*/
1313
interface OpenAIClient extends LLMClientInterface

src/Integrations/RealOpenAIClient.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,37 @@
44

55
/**
66
* Real OpenAI Client Implementation
7-
*
7+
*
88
* Concrete implementation of OpenAIClient interface for making
99
* actual calls to OpenAI API.
1010
*/
1111
class RealOpenAIClient implements OpenAIClient
1212
{
1313
private string $apiKey;
1414
private string $baseUrl = 'https://api.openai.com/v1';
15-
15+
1616
public function __construct(string $apiKey = '')
1717
{
1818
$this->apiKey = $apiKey ?: getenv('OPENAI_API_KEY') ?: '';
1919
}
20-
20+
2121
public function chat(array $context): array
2222
{
2323
if (empty($this->apiKey)) {
2424
throw new \InvalidArgumentException('OpenAI API key is required');
2525
}
26-
26+
2727
$url = $this->baseUrl . '/chat/completions';
2828
$headers = [
2929
'Authorization: Bearer ' . $this->apiKey,
3030
'Content-Type: application/json',
3131
];
32-
32+
3333
$response = $this->makeRequest($url, $context, $headers);
34-
34+
3535
return json_decode($response, true) ?: [];
3636
}
37-
37+
3838
public function getSupportedModels(): array
3939
{
4040
return [
@@ -45,17 +45,17 @@ public function getSupportedModels(): array
4545
'gpt-4-turbo-preview'
4646
];
4747
}
48-
48+
4949
public function getProviderName(): string
5050
{
5151
return 'openai';
5252
}
53-
53+
5454
public function supportsToolCalling(): bool
5555
{
5656
return true;
5757
}
58-
58+
5959
private function makeRequest(string $url, array $data, array $headers): string
6060
{
6161
$ch = curl_init();
@@ -67,22 +67,22 @@ private function makeRequest(string $url, array $data, array $headers): string
6767
CURLOPT_RETURNTRANSFER => true,
6868
CURLOPT_TIMEOUT => 30,
6969
]);
70-
70+
7171
$response = curl_exec($ch);
7272
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
73-
73+
7474
if ($response === false) {
7575
$error = curl_error($ch);
7676
curl_close($ch);
7777
throw new \RuntimeException("cURL request failed: {$error}");
7878
}
79-
79+
8080
curl_close($ch);
81-
81+
8282
if ($httpCode !== 200) {
8383
throw new \RuntimeException("OpenAI API request failed with HTTP code: {$httpCode}");
8484
}
85-
85+
8686
return (string) $response;
8787
}
88-
}
88+
}

0 commit comments

Comments
 (0)