-
-
Notifications
You must be signed in to change notification settings - Fork 117
/
IndexJob.php
49 lines (40 loc) · 1.08 KB
/
IndexJob.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Phpactor\Indexer\Model;
use Generator;
use Phpactor\TextDocument\TextDocumentBuilder;
use SplFileInfo;
class IndexJob
{
public function __construct(private IndexBuilder $indexBuilder, private FileList $fileList)
{
}
/**
* @return Generator<string>
*/
public function generator(): Generator
{
foreach ($this->fileList as $fileInfo) {
assert($fileInfo instanceof SplFileInfo);
if ($fileInfo->isLink()) {
continue;
}
$contents = @file_get_contents($fileInfo->getPathname());
if (false === $contents) {
continue;
}
$this->indexBuilder->index(
TextDocumentBuilder::create($contents)->uri($fileInfo->getPathname())->build()
);
yield $fileInfo->getPathname();
}
$this->indexBuilder->done();
}
public function run(): void
{
iterator_to_array($this->generator());
}
public function size(): int
{
return $this->fileList->count();
}
}