From 925783db10587895aea19f62dcfa51a2aca1f1e4 Mon Sep 17 00:00:00 2001
From: Niels de Blaauw <niels@level-level.com>
Date: Sun, 20 Jan 2019 09:04:02 +0100
Subject: [PATCH] Fixes #1, now catches invalid php files instead of failing

---
 src/AnalysableFile.php | 11 ++++++++++-
 src/Output/Text.php    |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/AnalysableFile.php b/src/AnalysableFile.php
index 5f1b578..78e3db0 100644
--- a/src/AnalysableFile.php
+++ b/src/AnalysableFile.php
@@ -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);
diff --git a/src/Output/Text.php b/src/Output/Text.php
index 3afc82f..07e7920 100644
--- a/src/Output/Text.php
+++ b/src/Output/Text.php
@@ -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',