Skip to content

Commit cfb0f16

Browse files
authored
style: add rector (#70)
* style: add rector * style: fix for rectors
1 parent e7889ee commit cfb0f16

File tree

8 files changed

+44
-8
lines changed

8 files changed

+44
-8
lines changed

.github/workflows/pipeline.yml

+3
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,8 @@ jobs:
5454
- name: Code Style PHP
5555
run: vendor/bin/php-cs-fixer fix --dry-run
5656

57+
- name: Rector
58+
run: vendor/bin/rector --dry-run
59+
5760
- name: PHPStan
5861
run: vendor/bin/phpstan analyse

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"require-dev": {
2525
"php-cs-fixer/shim": "^3.69",
2626
"phpstan/phpstan": "^2.1",
27-
"phpunit/phpunit": "^11.5"
27+
"phpunit/phpunit": "^11.5",
28+
"rector/rector": "^2.0"
2829
},
2930
"config": {
3031
"sort-packages": true

rector.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\CodeQuality\Rector\Class_\PreferPHPUnitSelfCallRector;
8+
use Rector\PHPUnit\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector;
9+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertCountWithZeroToAssertEmptyRector;
10+
use Rector\PHPUnit\Set\PHPUnitSetList;
11+
12+
return RectorConfig::configure()
13+
->withPaths([
14+
__DIR__.'/src',
15+
__DIR__.'/tests',
16+
])
17+
->withPhpSets(php82: true)
18+
->withSets([
19+
PHPUnitSetList::PHPUNIT_110,
20+
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
21+
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
22+
])
23+
->withRules([
24+
PreferPHPUnitSelfCallRector::class,
25+
])
26+
->withImportNames(importShortClasses: false)
27+
->withSkip([
28+
AssertCountWithZeroToAssertEmptyRector::class,
29+
ClosureToArrowFunctionRector::class,
30+
PreferPHPUnitThisCallRector::class,
31+
])
32+
->withTypeCoverageLevel(0);

src/DependencyInjection/LlmChainExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
219219
// MODEL
220220
['name' => $modelName, 'version' => $version, 'options' => $options] = $config['model'];
221221

222-
$llmClass = match (strtolower($modelName)) {
222+
$llmClass = match (strtolower((string) $modelName)) {
223223
'gpt' => GPT::class,
224224
'claude' => Claude::class,
225225
'llama' => Llama::class,
@@ -404,7 +404,7 @@ private function processEmbedderConfig(int|string $name, array $config, Containe
404404
{
405405
['name' => $modelName, 'version' => $version, 'options' => $options] = $config['model'];
406406

407-
$modelClass = match (strtolower($modelName)) {
407+
$modelClass = match (strtolower((string) $modelName)) {
408408
'embeddings' => Embeddings::class,
409409
'voyage' => Voyage::class,
410410
default => throw new \InvalidArgumentException(sprintf('Model "%s" is not supported.', $modelName)),

src/Profiler/DataCollector.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ final class DataCollector extends AbstractDataCollector
2020
/**
2121
* @var TraceablePlatform[]
2222
*/
23-
private array $platforms;
23+
private readonly array $platforms;
2424

2525
/**
2626
* @var TraceableToolBox[]
2727
*/
28-
private array $toolBoxes;
28+
private readonly array $toolBoxes;
2929

3030
/**
3131
* @param TraceablePlatform[] $platforms

src/Profiler/TraceableToolBox.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class TraceableToolBox implements ToolBoxInterface
2121
public array $calls = [];
2222

2323
public function __construct(
24-
private ToolBoxInterface $toolBox,
24+
private readonly ToolBoxInterface $toolBox,
2525
) {
2626
}
2727

src/Resources/config/services.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use PhpLlm\LlmChainBundle\Profiler\DataCollector;
1616
use PhpLlm\LlmChainBundle\Profiler\TraceableToolBox;
1717

18-
return static function (ContainerConfigurator $container) {
18+
return static function (ContainerConfigurator $container): void {
1919
$container->services()
2020
->defaults()
2121
->autowire()

tests/Profiler/TraceableToolBoxTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private function createToolBox(array $metadata): ToolBoxInterface
5252
{
5353
return new class($metadata) implements ToolBoxInterface {
5454
public function __construct(
55-
private array $metadata,
55+
private readonly array $metadata,
5656
) {
5757
}
5858

0 commit comments

Comments
 (0)