Skip to content

Commit

Permalink
Fixes #1, now catches invalid php files instead of failing
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsdeBlaauw committed Jan 20, 2019
1 parent 41942f6 commit 925783d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/AnalysableFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ public function __construct(\SplFileInfo $file, \PhpParser\Parser $parser, $argu

public function analyse()
{
$statements = $this->parser->parse(file_get_contents($this->file->getRealPath()));
try {
$statements = $this->parser->parse(file_get_contents($this->file->getRealPath()));
} catch (\PhpParser\Error $e) {
$this->has_errors = true;
$this->findings[] = new \NdB\PhpDocCheck\Findings\Error(
sprintf('Failed parsing: %s', $e->getRawMessage()),
$e->getStartLine()
);
return 'I';
}
$traverser = new \PhpParser\NodeTraverser();
$traverser->addVisitor(new \NdB\PhpDocCheck\NodeVisitor($this));
$traverser->traverse($statements);
Expand Down
2 changes: 1 addition & 1 deletion src/Output/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function get()
foreach ($this->files as $file) {
if (!empty($file->findings)) {
$output .= "\n";
$output .= sprintf("Missing documentation in %s\n", $file->file->getRealPath());
$output .= sprintf("File: %s\n", $file->file->getRealPath());
$header = array(
'Severity',
'Message',
Expand Down

0 comments on commit 925783d

Please sign in to comment.