Skip to content

Commit c1fad8a

Browse files
authored
ci: add rector/rector (#18)
1 parent bc89175 commit c1fad8a

29 files changed

+147
-72
lines changed

.github/workflows/pipeline.yml

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
- name: Code Style PHP
3232
run: vendor/bin/php-cs-fixer fix --dry-run
3333

34+
- name: Rector
35+
run: vendor/bin/rector
36+
3437
- name: PHPStan
3538
run: vendor/bin/phpstan analyse
3639

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ qa:
22
vendor/bin/php-cs-fixer fix
33
vendor/bin/phpstan
44
vendor/bin/phpunit
5+
vendor/bin/rector
56

67
qa-lowest:
78
composer update --prefer-lowest

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"phpstan/phpstan": "^1.12",
2828
"phpunit/phpunit": "^11.3",
2929
"probots-io/pinecone-php": "^1.0",
30+
"rector/rector": "^1.2",
3031
"symfony/clock": "^6.4 || ^7.1",
3132
"symfony/console": "^6.4 || ^7.1",
3233
"symfony/css-selector": "^6.4 || ^7.1",

rector.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
7+
use Rector\PHPUnit\Set\PHPUnitSetList;
8+
9+
return RectorConfig::configure()
10+
->withPaths([
11+
__DIR__.'/examples',
12+
__DIR__.'/src',
13+
__DIR__.'/tests',
14+
])
15+
->withPhpSets(php82: true)
16+
->withSets([
17+
PHPUnitSetList::PHPUNIT_110,
18+
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
19+
])
20+
->withImportNames(importNames: true, importShortClasses: false)
21+
->withSkip([
22+
ClosureToArrowFunctionRector::class,
23+
])
24+
->withTypeCoverageLevel(0);

src/Anthropic/Model/Claude.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use PhpLlm\LlmChain\Response\Choice;
1212
use PhpLlm\LlmChain\Response\Response;
1313

14-
final class Claude implements LanguageModel
14+
final readonly class Claude implements LanguageModel
1515
{
1616
public function __construct(
1717
private ClaudeRuntime $runtime,

src/Anthropic/Runtime/Anthropic.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PhpLlm\LlmChain\Anthropic\ClaudeRuntime;
88
use Symfony\Contracts\HttpClient\HttpClientInterface;
99

10-
final class Anthropic implements ClaudeRuntime
10+
final readonly class Anthropic implements ClaudeRuntime
1111
{
1212
public function __construct(
1313
private HttpClientInterface $httpClient,

src/DocumentEmbedder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PhpLlm\LlmChain\Document\Document;
88
use PhpLlm\LlmChain\Store\StoreInterface;
99

10-
final class DocumentEmbedder
10+
final readonly class DocumentEmbedder
1111
{
1212
public function __construct(
1313
private EmbeddingModel $embeddings,

src/OpenAI/Model/Embeddings.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PhpLlm\LlmChain\OpenAI\Model\Embeddings\Version;
1010
use PhpLlm\LlmChain\OpenAI\Runtime;
1111

12-
final class Embeddings implements EmbeddingModel
12+
final readonly class Embeddings implements EmbeddingModel
1313
{
1414
public function __construct(
1515
private Runtime $runtime,

src/OpenAI/Model/Gpt.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use PhpLlm\LlmChain\Response\Response;
1313
use PhpLlm\LlmChain\Response\ToolCall;
1414

15-
final class Gpt implements LanguageModel
15+
final readonly class Gpt implements LanguageModel
1616
{
1717
public function __construct(
1818
private Runtime $runtime,

src/OpenAI/Runtime/Azure.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
final class Azure extends AbstractRuntime implements Runtime
1212
{
1313
public function __construct(
14-
private HttpClientInterface $httpClient,
15-
private string $baseUrl,
16-
private string $deployment,
17-
private string $apiVersion,
18-
private string $key,
14+
private readonly HttpClientInterface $httpClient,
15+
private readonly string $baseUrl,
16+
private readonly string $deployment,
17+
private readonly string $apiVersion,
18+
private readonly string $key,
1919
) {
2020
}
2121

src/OpenAI/Runtime/OpenAI.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
final class OpenAI extends AbstractRuntime implements Runtime
1212
{
1313
public function __construct(
14-
private HttpClientInterface $httpClient,
15-
private string $apiKey,
14+
private readonly HttpClientInterface $httpClient,
15+
private readonly string $apiKey,
1616
) {
1717
}
1818

src/Store/Azure/SearchStore.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
use Symfony\Component\Uid\Uuid;
1212
use Symfony\Contracts\HttpClient\HttpClientInterface;
1313

14-
final class SearchStore implements VectorStoreInterface
14+
final readonly class SearchStore implements VectorStoreInterface
1515
{
1616
public function __construct(
17-
private readonly HttpClientInterface $httpClient,
18-
private readonly string $endpointUrl,
19-
private readonly string $apiKey,
20-
private readonly string $indexName,
21-
private readonly string $apiVersion,
17+
private HttpClientInterface $httpClient,
18+
private string $endpointUrl,
19+
private string $apiKey,
20+
private string $indexName,
21+
private string $apiVersion,
2222
) {
2323
}
2424

src/Store/ChromaDb/Store.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Psr\Log\LoggerInterface;
1313
use Symfony\Component\Uid\Uuid;
1414

15-
final class Store implements VectorStoreInterface
15+
final readonly class Store implements VectorStoreInterface
1616
{
1717
public function __construct(
1818
private Client $client,

src/StructuredOutput/SchemaFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
1010
use Symfony\Component\PropertyInfo\Type;
1111

12-
final class SchemaFactory
12+
final readonly class SchemaFactory
1313
{
1414
public function __construct(
15-
private readonly PropertyInfoExtractor $propertyInfo,
15+
private PropertyInfoExtractor $propertyInfo,
1616
) {
1717
}
1818

src/ToolBox/AsTool.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
namespace PhpLlm\LlmChain\ToolBox;
66

77
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
8-
final class AsTool
8+
final readonly class AsTool
99
{
1010
public function __construct(
11-
public readonly string $name,
12-
public readonly string $description,
13-
public readonly string $method = '__invoke',
11+
public string $name,
12+
public string $description,
13+
public string $method = '__invoke',
1414
) {
1515
}
1616
}

src/ToolBox/Metadata.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
/**
88
* @phpstan-import-type ParameterDefinition from ParameterAnalyzer
99
*/
10-
final class Metadata implements \JsonSerializable
10+
final readonly class Metadata implements \JsonSerializable
1111
{
1212
/**
1313
* @param ParameterDefinition|null $parameters
1414
*/
1515
public function __construct(
16-
public readonly string $className,
17-
public readonly string $name,
18-
public readonly string $description,
19-
public readonly string $method,
20-
public readonly ?array $parameters,
16+
public string $className,
17+
public string $name,
18+
public string $description,
19+
public string $method,
20+
public ?array $parameters,
2121
) {
2222
}
2323

src/ToolBox/Tool/Clock.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Component\Clock\ClockInterface;
99

1010
#[AsTool('clock', description: 'Provides the current date and time.')]
11-
final class Clock
11+
final readonly class Clock
1212
{
1313
public function __construct(
1414
private ClockInterface $clock,

src/ToolBox/Tool/SerpApi.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Symfony\Contracts\HttpClient\HttpClientInterface;
99

1010
#[AsTool(name: 'serpapi', description: 'search for information on the internet')]
11-
final class SerpApi
11+
final readonly class SerpApi
1212
{
1313
public function __construct(
1414
private HttpClientInterface $httpClient,

src/ToolBox/Tool/Wikipedia.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#[AsTool('wikipedia_search', description: 'Searches Wikipedia for a given query', method: 'search')]
1111
#[AsTool('wikipedia_article', description: 'Retrieves a Wikipedia article by its title', method: 'getArticle')]
12-
final class Wikipedia
12+
final readonly class Wikipedia
1313
{
1414
public function __construct(
1515
private HttpClientInterface $httpClient,

src/ToolBox/ToolAnalyzer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
use PhpLlm\LlmChain\Exception\InvalidToolImplementation;
88

9-
final class ToolAnalyzer
9+
final readonly class ToolAnalyzer
1010
{
1111
public function __construct(
12-
private readonly ParameterAnalyzer $parameterAnalyzer = new ParameterAnalyzer(),
12+
private ParameterAnalyzer $parameterAnalyzer = new ParameterAnalyzer(),
1313
) {
1414
}
1515

tests/Message/MessageBagTest.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpLlm\LlmChain\Message\MessageBag;
99
use PHPUnit\Framework\Attributes\CoversClass;
1010
use PHPUnit\Framework\Attributes\Small;
11+
use PHPUnit\Framework\Attributes\Test;
1112
use PHPUnit\Framework\Attributes\UsesClass;
1213
use PHPUnit\Framework\TestCase;
1314

@@ -16,7 +17,8 @@
1617
#[Small]
1718
final class MessageBagTest extends TestCase
1819
{
19-
public function testGetSystemMessage(): void
20+
#[Test]
21+
public function getSystemMessage(): void
2022
{
2123
$messageBag = new MessageBag(
2224
Message::forSystem('My amazing system prompt.'),
@@ -29,7 +31,8 @@ public function testGetSystemMessage(): void
2931
self::assertSame('My amazing system prompt.', $systemMessage->content);
3032
}
3133

32-
public function testGetSystemMessageWithoutSystemMessage(): void
34+
#[Test]
35+
public function getSystemMessageWithoutSystemMessage(): void
3336
{
3437
$messageBag = new MessageBag(
3538
Message::ofAssistant('It is time to sleep.'),
@@ -39,7 +42,8 @@ public function testGetSystemMessageWithoutSystemMessage(): void
3942
self::assertNull($messageBag->getSystemMessage());
4043
}
4144

42-
public function testWith(): void
45+
#[Test]
46+
public function with(): void
4347
{
4448
$messageBag = new MessageBag(
4549
Message::forSystem('My amazing system prompt.'),
@@ -55,7 +59,8 @@ public function testWith(): void
5559
self::assertSame('It is time to wake up.', $newMessageBag[3]->content);
5660
}
5761

58-
public function testWithoutSystemMessage(): void
62+
#[Test]
63+
public function withoutSystemMessage(): void
5964
{
6065
$messageBag = new MessageBag(
6166
Message::forSystem('My amazing system prompt.'),
@@ -70,7 +75,8 @@ public function testWithoutSystemMessage(): void
7075
self::assertSame('It is time to sleep.', $newMessageBag[0]->content);
7176
}
7277

73-
public function testPrepend(): void
78+
#[Test]
79+
public function prepend(): void
7480
{
7581
$messageBag = new MessageBag(
7682
Message::ofAssistant('It is time to sleep.'),
@@ -85,7 +91,8 @@ public function testPrepend(): void
8591
self::assertSame('My amazing system prompt.', $newMessageBag[0]->content);
8692
}
8793

88-
public function testJsonSerialize(): void
94+
#[Test]
95+
public function jsonSerialize(): void
8996
{
9097
$messageBag = new MessageBag(
9198
Message::forSystem('My amazing system prompt.'),

tests/Message/MessageTest.php

+13-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use PHPUnit\Framework\Attributes\CoversClass;
1010
use PHPUnit\Framework\Attributes\DataProvider;
1111
use PHPUnit\Framework\Attributes\Small;
12+
use PHPUnit\Framework\Attributes\Test;
1213
use PHPUnit\Framework\Attributes\UsesClass;
1314
use PHPUnit\Framework\TestCase;
1415

@@ -17,7 +18,8 @@
1718
#[Small]
1819
final class MessageTest extends TestCase
1920
{
20-
public function testCreateSystemMessage(): void
21+
#[Test]
22+
public function createSystemMessage(): void
2123
{
2224
$message = Message::forSystem('My amazing system prompt.');
2325

@@ -29,7 +31,8 @@ public function testCreateSystemMessage(): void
2931
self::assertFalse($message->hasToolCalls());
3032
}
3133

32-
public function testCreateAssistantMessage(): void
34+
#[Test]
35+
public function createAssistantMessage(): void
3336
{
3437
$message = Message::ofAssistant('It is time to sleep.');
3538

@@ -41,7 +44,8 @@ public function testCreateAssistantMessage(): void
4144
self::assertFalse($message->hasToolCalls());
4245
}
4346

44-
public function testCreateAssistantMessageWithToolCalls(): void
47+
#[Test]
48+
public function createAssistantMessageWithToolCalls(): void
4549
{
4650
$toolCalls = [
4751
new ToolCall('call_123456', 'my_tool', ['foo' => 'bar']),
@@ -57,7 +61,8 @@ public function testCreateAssistantMessageWithToolCalls(): void
5761
self::assertTrue($message->hasToolCalls());
5862
}
5963

60-
public function testCreateUserMessage(): void
64+
#[Test]
65+
public function createUserMessage(): void
6166
{
6267
$message = Message::ofUser('Hi, my name is John.');
6368

@@ -69,7 +74,8 @@ public function testCreateUserMessage(): void
6974
self::assertFalse($message->hasToolCalls());
7075
}
7176

72-
public function testCreateToolCallMessage(): void
77+
#[Test]
78+
public function createToolCallMessage(): void
7379
{
7480
$toolCall = new ToolCall('call_123456', 'my_tool', ['foo' => 'bar']);
7581
$message = Message::ofToolCall($toolCall, 'Foo bar.');
@@ -84,7 +90,8 @@ public function testCreateToolCallMessage(): void
8490
}
8591

8692
#[DataProvider('provideJsonScenarios')]
87-
public function testJsonSerialize(Message $message, array $expected): void
93+
#[Test]
94+
public function jsonSerialize(Message $message, array $expected): void
8895
{
8996
self::assertSame($expected, $message->jsonSerialize());
9097
}

0 commit comments

Comments
 (0)