Skip to content

Commit a251c05

Browse files
committed
feature #476 [Store] Rename __invoke methods in interfaces to descriptive names (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [Store] Rename `__invoke` methods in interfaces to descriptive names | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | -- | License | MIT Discussed with `@chr`-hertel upfront. Replace generic `__invoke` methods with descriptive names: - `TransformerInterface::__invoke` → `transform` - `VectorizerInterface::__invoke` → `vectorize` - `LoaderInterface::__invoke` → `load` This improves code readability and makes the intent of each interface clearer. Updated all implementations and usages throughout the codebase. Commits ------- 0f2b756 [Store] Rename `__invoke` methods in interfaces to descriptive names
2 parents 9e5fa5d + 0f2b756 commit a251c05

14 files changed

+47
-47
lines changed

src/store/src/Document/Loader/TextFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323
final readonly class TextFileLoader implements LoaderInterface
2424
{
25-
public function __invoke(string $source, array $options = []): iterable
25+
public function load(string $source, array $options = []): iterable
2626
{
2727
if (!is_file($source)) {
2828
throw new RuntimeException(\sprintf('File "%s" does not exist.', $source));

src/store/src/Document/LoaderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ interface LoaderInterface
2222
*
2323
* @return iterable<TextDocument> iterable of TextDocuments loaded from the source
2424
*/
25-
public function __invoke(string $source, array $options = []): iterable;
25+
public function load(string $source, array $options = []): iterable;
2626
}

src/store/src/Document/Transformer/ChainTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public function __construct(iterable $transformers)
2828
$this->transformers = $transformers instanceof \Traversable ? iterator_to_array($transformers) : $transformers;
2929
}
3030

31-
public function __invoke(iterable $documents, array $options = []): iterable
31+
public function transform(iterable $documents, array $options = []): iterable
3232
{
3333
foreach ($this->transformers as $transformer) {
34-
$documents = $transformer($documents, $options);
34+
$documents = $transformer->transform($documents, $options);
3535
}
3636

3737
return $documents;

src/store/src/Document/Transformer/ChunkDelayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function __construct(
3333
/**
3434
* @param array{chunk_size?: int, delay?: int} $options
3535
*/
36-
public function __invoke(iterable $documents, array $options = []): iterable
36+
public function transform(iterable $documents, array $options = []): iterable
3737
{
3838
$chunkSize = $options[self::OPTION_CHUNK_SIZE] ?? 50;
3939
$delay = $options[self::OPTION_DELAY] ?? 10;

src/store/src/Document/Transformer/TextSplitTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/**
3333
* @param array{chunk_size?: int, overlap?: int} $options
3434
*/
35-
public function __invoke(iterable $documents, array $options = []): iterable
35+
public function transform(iterable $documents, array $options = []): iterable
3636
{
3737
$chunkSize = $options[self::OPTION_CHUNK_SIZE] ?? 1000;
3838
$overlap = $options[self::OPTION_OVERLAP] ?? 200;

src/store/src/Document/TransformerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ interface TransformerInterface
2626
*
2727
* @return iterable<TextDocument>
2828
*/
29-
public function __invoke(iterable $documents, array $options = []): iterable;
29+
public function transform(iterable $documents, array $options = []): iterable;
3030
}

src/store/src/Document/Vectorizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function __construct(
2626
) {
2727
}
2828

29-
public function __invoke(array $documents): array
29+
public function vectorize(array $documents): array
3030
{
3131
$documentCount = \count($documents);
3232
$this->logger->info('Starting vectorization process', ['document_count' => $documentCount]);

src/store/src/Document/VectorizerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ interface VectorizerInterface
2323
*
2424
* @return VectorDocument[]
2525
*/
26-
public function __invoke(array $documents): array;
26+
public function vectorize(array $documents): array;
2727
}

src/store/src/Indexer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public function index(TextDocument|iterable $documents, int $chunkSize = 50): vo
4545
++$counter;
4646

4747
if ($chunkSize === \count($chunk)) {
48-
$this->store->add(...($this->vectorizer)($chunk));
48+
$this->store->add(...$this->vectorizer->vectorize($chunk));
4949
$chunk = [];
5050
}
5151
}
5252

5353
if (\count($chunk) > 0) {
54-
$this->store->add(...($this->vectorizer)($chunk));
54+
$this->store->add(...$this->vectorizer->vectorize($chunk));
5555
}
5656

5757
$this->logger->debug(0 === $counter ? 'No documents to index' : \sprintf('Indexed %d documents', $counter));

src/store/tests/Document/Loader/TextFileLoaderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ public function testLoadWithInvalidSource()
2727
$this->expectException(RuntimeException::class);
2828
$this->expectExceptionMessage('File "/invalid/source.txt" does not exist.');
2929

30-
iterator_to_array($loader('/invalid/source.txt'));
30+
iterator_to_array($loader->load('/invalid/source.txt'));
3131
}
3232

3333
public function testLoadWithValidSource()
3434
{
3535
$loader = new TextFileLoader();
3636

37-
$documents = iterator_to_array($loader(\dirname(__DIR__, 5).'/fixtures/lorem.txt'));
37+
$documents = iterator_to_array($loader->load(\dirname(__DIR__, 5).'/fixtures/lorem.txt'));
3838

3939
$this->assertCount(1, $documents);
4040
$this->assertInstanceOf(TextDocument::class, $document = $documents[0]);
@@ -48,7 +48,7 @@ public function testSourceIsPresentInMetadata()
4848
$loader = new TextFileLoader();
4949

5050
$source = \dirname(__DIR__, 5).'/fixtures/lorem.txt';
51-
$documents = iterator_to_array($loader($source));
51+
$documents = iterator_to_array($loader->load($source));
5252

5353
$this->assertCount(1, $documents);
5454
$this->assertInstanceOf(TextDocument::class, $document = $documents[0]);

0 commit comments

Comments
 (0)