From f925e08c296113a70841e9994e3f76e1eaa6ed90 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Sat, 3 Aug 2019 13:51:52 +0200 Subject: [PATCH] Don't read out old swar versions --- src/Readers/Swar4.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Readers/Swar4.php b/src/Readers/Swar4.php index e262294..a1b0173 100644 --- a/src/Readers/Swar4.php +++ b/src/Readers/Swar4.php @@ -15,6 +15,7 @@ namespace JeroenED\Libpairtwo\Readers; use DateTime; use JeroenED\Libpairtwo\Enums\TournamentSystem; +use JeroenED\Libpairtwo\Exceptions\IncompatibleReaderException; use JeroenED\Libpairtwo\Interfaces\ReaderInterface; use JeroenED\Libpairtwo\Tournament; @@ -33,9 +34,14 @@ class Swar4 implements ReaderInterface /** @var string */ private $release; + /** @var array */ + private const CompatibleVersions = ['v4.']; + + /** * @param string $filename * @return ReaderInterface + * @throws IncompatibleReaderException */ public function read(string $filename): ReaderInterface { @@ -43,6 +49,10 @@ class Swar4 implements ReaderInterface $this->setRelease($this->readData('String', $swshandle)); + if (array_search(substr($this->getRelease(), 0, 3), self::CompatibleVersions) === false) { + throw new IncompatibleReaderException("This file was not created with Swar 4"); + } + $this->setTournament(new Tournament()); $this->setBinaryData('Guid', $this->readData('String', $swshandle));