Don't read out old swar versions

This commit is contained in:
Jeroen De Meerleer 2019-08-03 13:51:52 +02:00
parent f491a86ab6
commit f925e08c29
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -15,6 +15,7 @@ namespace JeroenED\Libpairtwo\Readers;
use DateTime; use DateTime;
use JeroenED\Libpairtwo\Enums\TournamentSystem; use JeroenED\Libpairtwo\Enums\TournamentSystem;
use JeroenED\Libpairtwo\Exceptions\IncompatibleReaderException;
use JeroenED\Libpairtwo\Interfaces\ReaderInterface; use JeroenED\Libpairtwo\Interfaces\ReaderInterface;
use JeroenED\Libpairtwo\Tournament; use JeroenED\Libpairtwo\Tournament;
@ -33,9 +34,14 @@ class Swar4 implements ReaderInterface
/** @var string */ /** @var string */
private $release; private $release;
/** @var array */
private const CompatibleVersions = ['v4.'];
/** /**
* @param string $filename * @param string $filename
* @return ReaderInterface * @return ReaderInterface
* @throws IncompatibleReaderException
*/ */
public function read(string $filename): ReaderInterface public function read(string $filename): ReaderInterface
{ {
@ -43,6 +49,10 @@ class Swar4 implements ReaderInterface
$this->setRelease($this->readData('String', $swshandle)); $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->setTournament(new Tournament());
$this->setBinaryData('Guid', $this->readData('String', $swshandle)); $this->setBinaryData('Guid', $this->readData('String', $swshandle));