Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch error if file content could not be parsed #22

Merged
merged 1 commit into from
Feb 6, 2022
Merged
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased] - TBA
### Fixed
- Fixed `FileContentProvider` to throw an exception when the file does not exist
- Added `try/catch` to `FileSymbolProvider` to continue working instead of crashing if a file could not be parsed
### Added
### Changed
### Removed
Expand Down
5 changes: 5 additions & 0 deletions src/Exception/IOException.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public static function unableToOpenHandle(string $path): self
{
return new self('Unable to open resource ' . $path);
}

public static function fileDoesNotExist(string $path): self
{
return new self('File does not exist: ' . $path);
}
}
2 changes: 1 addition & 1 deletion src/Parser/PHP/AbstractCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

abstract class AbstractCollector extends NodeVisitorAbstract implements SymbolCollectorInterface
{
private ?Closure $includeCallback;
private ?Closure $includeCallback = null;

public function setFileIncludeCallback(Closure $includeCallback): void
{
Expand Down
15 changes: 10 additions & 5 deletions src/Symbol/Provider/FileSymbolProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ public function __construct(SymbolNameParserInterface $parser, FileContentProvid
public function provide(): Generator
{
foreach ($this->fileIterator as $file) {
$content = $this->fileContentProvider->getContent($file);
$this->parser->setCurrentFile($file);

foreach ($this->parser->parseSymbolNames($content) as $symbolName) {
yield $symbolName => new Symbol($symbolName);
try {
$content = $this->fileContentProvider->getContent($file);
$this->parser->setCurrentFile($file);

foreach ($this->parser->parseSymbolNames($content) as $symbolName) {
yield $symbolName => new Symbol($symbolName);
}
} catch (IOException $exception) {
// TODO add logging
continue;
}
}

Expand Down