Skip to content

Commit 0aab424

Browse files
author
Alexander Cherednikov
committed
Rector is installed
1 parent dbd0880 commit 0aab424

30 files changed

Lines changed: 219 additions & 89 deletions

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ jobs:
4141

4242
- name: Check code style
4343
run: composer cs-check
44+
45+
- name: Run Rector
46+
run: composer rector-check

composer.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,18 @@
6161
],
6262
"check": [
6363
"@phpstan",
64-
"@cs-check"
64+
"@cs-check",
65+
"@rector-check"
6566
],
6667
"fix": [
67-
"@cs-fix"
68+
"@cs-fix",
69+
"@rector-fix"
6870
],
6971
"phpstan": "phpstan analyse src --level=8 --no-progress",
7072
"cs-check": "php-cs-fixer fix --dry-run --diff",
71-
"cs-fix": "php-cs-fixer fix"
73+
"cs-fix": "php-cs-fixer fix",
74+
"rector-check": "rector process --dry-run",
75+
"rector-fix": "rector process"
7276
},
7377
"conflict": {
7478
"symfony/symfony": "*"
@@ -80,8 +84,9 @@
8084
}
8185
},
8286
"require-dev": {
83-
"phpstan/phpstan": "^1.12.28",
8487
"friendsofphp/php-cs-fixer": "^3.87.2",
88+
"phpstan/phpstan": "^1.12.28",
89+
"rector/rector": "^1.2",
8590
"symfony/maker-bundle": "^1.64"
8691
}
8792
}

composer.lock

Lines changed: 60 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/bundles.php

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

3+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
4+
use Symfony\Bundle\MakerBundle\MakerBundle;
5+
36
return [
4-
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
5-
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
7+
FrameworkBundle::class => ['all' => true],
8+
MakerBundle::class => ['dev' => true],
69
];

public/index.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
66

7-
return function (array $context) {
8-
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
9-
};
7+
return fn(array $context) => new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

rector.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Doctrine\Set\DoctrineSetList;
7+
use Rector\Php80\Rector\Class_\StringableForToStringRector;
8+
use Rector\Php83\Rector\ClassConst\AddTypeToConstRector;
9+
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
10+
use Rector\Set\ValueObject\LevelSetList;
11+
use Rector\Set\ValueObject\SetList;
12+
13+
return static function (RectorConfig $rectorConfig): void {
14+
$rectorConfig->parallel();
15+
$rectorConfig->cacheDirectory(__DIR__ . '/var/tmp/rector');
16+
17+
$rectorConfig->paths([
18+
__DIR__ . '/config',
19+
__DIR__ . '/public',
20+
__DIR__ . '/src',
21+
__DIR__ . '/tests',
22+
]);
23+
24+
// Doctrine
25+
$rectorConfig->sets([
26+
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
27+
]);
28+
29+
// Symfony
30+
$rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');
31+
32+
$rectorConfig->importNames();
33+
$rectorConfig->importShortClasses(false);
34+
35+
$rectorConfig->sets([
36+
DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
37+
LevelSetList::UP_TO_PHP_83,
38+
SetList::DEAD_CODE,
39+
SetList::PRIVATIZATION,
40+
SetList::EARLY_RETURN,
41+
SetList::STRICT_BOOLEANS,
42+
]);
43+
44+
$rectorConfig->skip([
45+
StringableForToStringRector::class,
46+
AddOverrideAttributeToOverriddenMethodsRector::class,
47+
AddTypeToConstRector::class,
48+
]);
49+
};

src/Command/ProductsChatCommand.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4141
while (true) {
4242
$query = $io->ask('Что вы ищете? ("выход" для завершения)');
4343

44-
if (!$query || in_array(strtolower(trim($query)), ['выход', 'exit', 'quit', 'q'])) {
44+
if (!$query || in_array(strtolower(trim((string) $query)), ['выход', 'exit', 'quit', 'q'])) {
4545
break;
4646
}
4747

@@ -89,7 +89,11 @@ private function displayChatResults(array $results, string $aiResponse, SymfonyS
8989
$io->section('Найденные товары');
9090

9191
foreach ($results as $i => $result) {
92-
if (!isset($result['payload']) || !isset($result['score'])) {
92+
if (!isset($result['payload'])) {
93+
continue;
94+
}
95+
96+
if (!isset($result['score'])) {
9397
continue;
9498
}
9599

src/Command/ProductsSearchCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use function Codewithkyrian\Transformers\Pipelines\pipeline;
1010

1111
use Codewithkyrian\Transformers\Pipelines\Task;
12+
use Codewithkyrian\Transformers\Tensor\Tensor;
1213
use Qdrant\Config;
1314
use Qdrant\Http\Transport;
1415
use Qdrant\Models\Request\SearchRequest;
@@ -50,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5051
try {
5152
$this->initializeServices();
5253
$results = $this->searchProducts($query);
53-
$this->displayResults($results, $query, $io);
54+
$this->displayResults($results, $io);
5455

5556
return Command::SUCCESS;
5657
} catch (\Exception $e) {
@@ -78,7 +79,7 @@ private function searchProducts(string $query): array
7879
if (is_array($embedding)) {
7980
$vector = $embedding[0];
8081
} else {
81-
$vector = $embedding instanceof \Codewithkyrian\Transformers\Tensor\Tensor ? $embedding[0] : [];
82+
$vector = $embedding instanceof Tensor ? $embedding[0] : [];
8283
}
8384

8485
$searchVector = new VectorStruct($vector, 'default');
@@ -93,9 +94,9 @@ private function searchProducts(string $query): array
9394
/**
9495
* @param array<int, array<string, mixed>> $results
9596
*/
96-
private function displayResults(array $results, string $query, SymfonyStyle $io): void
97+
private function displayResults(array $results, SymfonyStyle $io): void
9798
{
98-
if (empty($results)) {
99+
if ([] === $results) {
99100
$io->warning('No products found');
100101

101102
return;

src/Command/ProductsVectorizeCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use function Codewithkyrian\Transformers\Pipelines\pipeline;
1010

1111
use Codewithkyrian\Transformers\Pipelines\Task;
12+
use Codewithkyrian\Transformers\Tensor\Tensor;
1213
use Qdrant\Config;
1314
use Qdrant\Http\Transport;
1415
use Qdrant\Models\PointsStruct;
@@ -94,7 +95,7 @@ private function prepareCollection(): void
9495
{
9596
try {
9697
$this->qdrantClient->collections(self::COLLECTION_NAME)->delete();
97-
} catch (\Exception $e) {
98+
} catch (\Exception) {
9899
}
99100

100101
$createCollection = new CreateCollection();
@@ -116,7 +117,7 @@ private function vectorizeAndStore(\Generator $products): void
116117
}
117118
}
118119

119-
if (!empty($batch)) {
120+
if ([] !== $batch) {
120121
$this->processBatch($batch);
121122
}
122123
}
@@ -153,7 +154,7 @@ private function processBatch(array $batch): void
153154
if (is_array($embedding)) {
154155
$vector = $embedding[0];
155156
} else {
156-
$vector = $embedding instanceof \Codewithkyrian\Transformers\Tensor\Tensor ? $embedding[0] : [];
157+
$vector = $embedding instanceof Tensor ? $embedding[0] : [];
157158
}
158159

159160
$pointsStruct->addPoint(

src/Command/RAGDemoCommand.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4141
}
4242
$interactive = $input->getOption('interactive');
4343
$query = $input->getOption('query');
44-
4544
if ($interactive) {
4645
return $this->runInteractiveMode($io);
47-
} elseif ($query) {
48-
return $this->runSingleQuery($query, $io);
49-
} else {
50-
$this->showUsageExamples($io);
46+
}
5147

52-
return Command::SUCCESS;
48+
if ($query) {
49+
return $this->runSingleQuery($query, $io);
5350
}
51+
$this->showUsageExamples($io);
52+
53+
return Command::SUCCESS;
5454
}
5555

5656
private function checkServices(SymfonyStyle $io): bool
@@ -85,7 +85,7 @@ private function runInteractiveMode(SymfonyStyle $io): int
8585
while (true) {
8686
$query = $io->ask('Ваш запрос ("выход" для завершения)');
8787

88-
if (!$query || in_array(strtolower(trim($query)), ['выход', 'exit', 'quit', 'q'])) {
88+
if (!$query || in_array(strtolower(trim((string) $query)), ['выход', 'exit', 'quit', 'q'])) {
8989
break;
9090
}
9191

0 commit comments

Comments
 (0)