From 63c7d8f6b56f2dd8584705b08e48ef25d000bc66 Mon Sep 17 00:00:00 2001 From: itismadness Date: Wed, 29 Apr 2020 13:04:11 +0100 Subject: [PATCH] Catch unknown ripper error in logchecker proper --- src/Check/Ripper.php | 2 +- src/Logchecker.php | 12 +++++++++++- tests/LogcheckerTest.php | 13 +++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Check/Ripper.php b/src/Check/Ripper.php index 9d0fa54..eedac67 100644 --- a/src/Check/Ripper.php +++ b/src/Check/Ripper.php @@ -8,7 +8,7 @@ use OrpheusNET\Logchecker\Exception\UnknownRipperException; class Ripper { - + public const UNKNOWN = 'unknown'; public const WHIPPER = 'whipper'; public const XLD = 'XLD'; public const EAC = 'EAC'; diff --git a/src/Logchecker.php b/src/Logchecker.php index 8256fed..7dedf12 100644 --- a/src/Logchecker.php +++ b/src/Logchecker.php @@ -3,6 +3,7 @@ namespace OrpheusNET\Logchecker; use OrpheusNET\Logchecker\Check\Ripper; +use OrpheusNET\Logchecker\Exception\UnknownRipperException; use OrpheusNET\Logchecker\Parser\EAC\Translator; use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Exception\ParseException; @@ -108,9 +109,18 @@ class Logchecker } catch (\Exception $exc) { $this->Score = 0; $this->account('Could not detect log encoding, log is corrupt.'); + return; + } + + try { + $this->ripper = Ripper::getRipper($this->log); + } catch (UnknownRipperException $exc) { + $this->Score = 0; + $this->account('Unknown log file, could not determine ripper.'); + $this->ripper = Ripper::UNKNOWN; + return; } - $this->ripper = Ripper::getRipper($this->log); if ($this->ripper === Ripper::WHIPPER) { $this->whipperParse(); } else { diff --git a/tests/LogcheckerTest.php b/tests/LogcheckerTest.php index aadb237..07ac024 100644 --- a/tests/LogcheckerTest.php +++ b/tests/LogcheckerTest.php @@ -70,4 +70,17 @@ class LogcheckerTest extends TestCase ); $this->assertSame($composer['version'], Logchecker::getLogcheckerVersion()); } + + public function testCheckUnknownLog(): void + { + $logchecker = new Logchecker(); + $logchecker->newFile(implode(DIRECTORY_SEPARATOR, [__DIR__, 'LogcheckerTest.php'])); + $logchecker->parse(); + + $this->assertSame(Ripper::UNKNOWN, $logchecker->getRipper()); + $this->assertNull($logchecker->getRipperVersion()); + $this->assertSame(0, $logchecker->getScore()); + $this->assertSame('en', $logchecker->getLanguage()); + $this->assertSame(['Unknown log file, could not determine ripper.'], $logchecker->getDetails()); + } }