Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Contracts/FileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ interface FileParser
*
* @return array<ClassStructuralElement>
*/
public function parse(string $contents): array;
public function parse(string $contents, string $filePath = null): array;
}
4 changes: 2 additions & 2 deletions src/Facades/ParserFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function parseAutoloadFile(?SplFileInfo $file): array

return $this->fileParser
->create(FileType::autoload())
->parse($file->getContents());
->parse($file->getContents(), $file->getPathname());
}

/**
Expand All @@ -46,7 +46,7 @@ public function parseClassFiles(array $files): array
return array_reduce($files, function (array $carry, SplFileInfo $file): array {
$classStructuralElements = $this->fileParser
->create(FileType::core())
->parse($file->getContents());
->parse($file->getContents(), $file->getPathname());

$filteredClassStructuralElements = array_filter(
$classStructuralElements,
Expand Down
13 changes: 11 additions & 2 deletions src/Parsers/AutoloadFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Haemanthus\CodeIgniter3IdeHelper\Factories\NodeTraverserFactory;
use Haemanthus\CodeIgniter3IdeHelper\Factories\NodeVisitorFactory;
use PhpParser\BuilderFactory;
use PhpParser\Error as PhpParserError;
use PhpParser\Node;
use PhpParser\ParserFactory;

Expand Down Expand Up @@ -67,9 +68,17 @@ public function __construct(
*
* @return array<ClassStructuralElement>
*/
public function parse(string $contents): array
public function parse(string $contents, string $filePath = null): array
{
$this->traverser->traverse($this->parser->parse($contents));
try {
$this->traverser->traverse($this->parser->parse($contents));
} catch (PhpParserError $e) {
throw new \RuntimeException(
sprintf('Failed to parse file "%s": %s', $filePath, $e->getMessage()),
0,
$e
);
}

$loadLibraryStructuralElements = $this->parseAutoloadLibraryNodes(
$this->autoloadLibraryNodeVisitor->getFoundNodes()
Expand Down
13 changes: 11 additions & 2 deletions src/Parsers/ClassFileParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Haemanthus\CodeIgniter3IdeHelper\Factories\NodeCasterFactory;
use Haemanthus\CodeIgniter3IdeHelper\Factories\NodeTraverserFactory;
use Haemanthus\CodeIgniter3IdeHelper\Factories\NodeVisitorFactory;
use PhpParser\Error as PhpParserError;
use PhpParser\Node;
use PhpParser\NodeVisitor\ParentConnectingVisitor;
use PhpParser\ParserFactory;
Expand Down Expand Up @@ -45,9 +46,17 @@ public function __construct(
*
* @return array<ClassStructuralElement>
*/
public function parse(string $contents): array
public function parse(string $contents, string $filePath = null): array
{
$this->traverser->traverse($this->parser->parse($contents));
try {
$this->traverser->traverse($this->parser->parse($contents));
} catch (PhpParserError $e) {
throw new \RuntimeException(
sprintf('Failed to parse file "%s": %s', $filePath, $e->getMessage()),
0,
$e
);
}

$loadLibraryNodes = $this->methodCallLoadLibraryNodeVisitor->getFoundNodes();
$loadModelNodes = $this->methodCallLoadModelNodeVisitor->getFoundNodes();
Expand Down