diff --git a/lib/Indexer/Model/IndexJob.php b/lib/Indexer/Model/IndexJob.php index d58b39a00..03cfd5df1 100644 --- a/lib/Indexer/Model/IndexJob.php +++ b/lib/Indexer/Model/IndexJob.php @@ -2,13 +2,13 @@ namespace Phpactor\Indexer\Model; -use FilesystemIterator; use Generator; use Phar; use PharFileInfo; use Phpactor\TextDocument\TextDocumentBuilder; use RecursiveIteratorIterator; use SplFileInfo; +use UnexpectedValueException; class IndexJob { @@ -24,10 +24,17 @@ public function generator(): Generator foreach ($this->fileList as $fileInfo) { assert($fileInfo instanceof SplFileInfo); + if ($fileInfo->isLink()) { + continue; + } // TODO: could refactor this to iterate the PHAR in the file list provider. if ($fileInfo->getExtension() === 'phar') { - $phar = new Phar($fileInfo->getPathname(), FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME); + try { + $phar = new Phar($fileInfo->getPathname()); + } catch (UnexpectedValueException $e) { + continue; + } yield from $this->indexPharFile($phar); continue; } diff --git a/lib/Indexer/Tests/Adapter/PharIndexTest.php b/lib/Indexer/Tests/Adapter/PharIndexTest.php index a665c1e9a..2d786b6b6 100644 --- a/lib/Indexer/Tests/Adapter/PharIndexTest.php +++ b/lib/Indexer/Tests/Adapter/PharIndexTest.php @@ -32,4 +32,13 @@ public function testIndexPhar(): void self::assertCount(1, $hellos); } + public function testIndexInvalidPhar(): void + { + $this->workspace()->put('repo/index.phar', 'indexAgentBuilder('repo')->buildTestAgent(); + $agent->indexer()->getJob()->run(); + $hellos = iterator_to_array($agent->search()->search(Criteria::shortNameContains('Hello'))); + self::assertCount(0, $hellos); + } }