From 057e35f1da0e32801faa9353c1e487c40a6104a7 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 27 May 2019 21:45:19 +0200 Subject: [PATCH 1/3] Added reading out the order of tiebreaks --- src/Enums/Tiebreak.php | 27 ++++++++++++++++++ src/Models/Tournament.php | 20 +++++++++++++ src/Readers/Pairtwo6.php | 60 +++++++++++++++++++++++++++++++++++++-- src/Tournament.php | 13 +++++++++ 4 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 src/Enums/Tiebreak.php diff --git a/src/Enums/Tiebreak.php b/src/Enums/Tiebreak.php new file mode 100644 index 0000000..c552efe --- /dev/null +++ b/src/Enums/Tiebreak.php @@ -0,0 +1,27 @@ +Pairings = $Pairings; } + + /** + * @return Tiebreak[] + */ + public function getTiebreaks(): array + { + return $this->Tiebreaks; + } + + /** + * @param Tiebreak[] $Tiebreaks + */ + public function setTiebreaks(array $Tiebreaks): void + { + $this->Tiebreaks = $Tiebreaks; + } } diff --git a/src/Readers/Pairtwo6.php b/src/Readers/Pairtwo6.php index 6117f36..1efbe31 100644 --- a/src/Readers/Pairtwo6.php +++ b/src/Readers/Pairtwo6.php @@ -26,6 +26,7 @@ namespace JeroenED\Libpairtwo\Readers; +use JeroenED\Libpairtwo\Enums\Tiebreak; use JeroenED\Libpairtwo\Enums\Title; use JeroenED\Libpairtwo\Enums\Gender; use JeroenED\Libpairtwo\Enums\Color; @@ -218,9 +219,62 @@ class Pairtwo6 extends Pairtwo6Model implements ReaderInterface $offset += $length; // TieOrder - $length = 4 * 5; - $this->setBinaryData("TieOrder", $this->readData('Int', substr($swscontents, $offset, $length))); - $offset += $length; + for ($i = 0; $i < 5; $i++) { + $length = 4; + switch ($this->readData('Int', substr($swscontents, $offset, $length))) { + case 1: + $tiebreak = Tiebreak::Buchholz; + break; + case 2: + $tiebreak = Tiebreak::BuchholzMed; + break; + case 3: + $tiebreak = Tiebreak::BuchholzMed; + break; + case 4: + $tiebreak = Tiebreak::Sonneborn; + break; + case 5: + $tiebreak = Tiebreak::Kashdan; + break; + case 6: + $tiebreak = Tiebreak::Cumulative; + break; + case 7: + $tiebreak = Tiebreak::Between; + break; + case 8: + $tiebreak = Tiebreak::Koya; + break; + case 9: + $tiebreak = Tiebreak::Baumbach; + break; + case 10: + $tiebreak = Tiebreak::Performance; + break; + case 11: + $tiebreak = Tiebreak::Aro; + break; + case 12: + $tiebreak = Tiebreak::AroCut; + break; + case 13: + $tiebreak = Tiebreak::BlackPlayed; + break; + case 14: + $tiebreak = Tiebreak::Testmatch; + break; + case 15: + $tiebreak = Tiebreak::Drawing; + break; + case 0: + default: + $tiebreak = Tiebreak::None; + break; + } + $this->getTournament()->addTieBreak(new Tiebreak($tiebreak)); + $offset += $length; + } // Categorie $length = 4 * 10; diff --git a/src/Tournament.php b/src/Tournament.php index e8d794b..bbe728c 100644 --- a/src/Tournament.php +++ b/src/Tournament.php @@ -8,6 +8,7 @@ namespace JeroenED\Libpairtwo; +use JeroenED\Libpairtwo\Enums\Tiebreak; use JeroenED\Libpairtwo\Models\Tournament as TournamentModel; use JeroenED\Libpairtwo\Enums\Color; @@ -49,6 +50,18 @@ class Tournament extends TournamentModel $this->setPlayers($newArray); } + /** + * Adds a Tiebreak + * + * @param Tiebreak $tiebreak + */ + public function addTiebreak(Tiebreak $tiebreak) + { + $newArray = $this->getTiebreaks(); + $newArray[] = $tiebreak; + $this->setTiebreaks($newArray); + } + /** * Adds a round with given Round object * From b91dd1ea9aaea36acf46771c3f8827e6b4dea929 Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 27 May 2019 21:46:03 +0200 Subject: [PATCH 2/3] Added tests for tiebreak order --- tests/ReadSws_test.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/ReadSws_test.php b/tests/ReadSws_test.php index 2b78ce8..880ae88 100644 --- a/tests/ReadSws_test.php +++ b/tests/ReadSws_test.php @@ -70,3 +70,6 @@ echo "Color Pairing 3: " . $sws->getTournament()->getPairings()[3]->getColor()-> echo "Player Pairing 1: " . $sws->getTournament()->getPairings()[0]->getPlayer()->getName() . PHP_EOL; echo "Player Pairing 2: " . $sws->getTournament()->getPairings()[1]->getPlayer()->getName() . PHP_EOL; echo "Player Pairing 3: " . $sws->getTournament()->getPairings()[2]->getPlayer()->getName() . PHP_EOL; +echo "Tiebreak 1: " . $sws->getTournament()->getTiebreaks()[0]->getValue() . PHP_EOL; +echo "Tiebreak 2: " . $sws->getTournament()->getTiebreaks()[1]->getValue() . PHP_EOL; +echo "Tiebreak 3: " . $sws->getTournament()->getTiebreaks()[2]->getValue() . PHP_EOL; From a70a9fcda37eef924bd332197bbeedf13e56d93f Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Mon, 27 May 2019 21:46:39 +0200 Subject: [PATCH 3/3] Code style --- src/Exceptions/IncompatibleReaderException.php | 6 ++---- src/Exceptions/LibpairtwoException.php | 4 +--- src/Sws.php | 6 +++--- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Exceptions/IncompatibleReaderException.php b/src/Exceptions/IncompatibleReaderException.php index a44401c..8785357 100644 --- a/src/Exceptions/IncompatibleReaderException.php +++ b/src/Exceptions/IncompatibleReaderException.php @@ -3,8 +3,6 @@ namespace JeroenED\Libpairtwo\Exceptions; - -class IncompatibleReaderException Extends LibpairtwoException +class IncompatibleReaderException extends LibpairtwoException { - -} \ No newline at end of file +} diff --git a/src/Exceptions/LibpairtwoException.php b/src/Exceptions/LibpairtwoException.php index ac8d606..e909fcc 100644 --- a/src/Exceptions/LibpairtwoException.php +++ b/src/Exceptions/LibpairtwoException.php @@ -3,8 +3,6 @@ namespace JeroenED\LibPairtwo\Exceptions; - class LibpairtwoException extends \Exception { - -} \ No newline at end of file +} diff --git a/src/Sws.php b/src/Sws.php index 18e6386..62f1944 100644 --- a/src/Sws.php +++ b/src/Sws.php @@ -26,7 +26,7 @@ namespace JeroenED\Libpairtwo; - +use JeroenED\LibPairtwo\Exceptions\LibpairtwoException; /** * This class reads a SWS file @@ -41,13 +41,13 @@ class Sws * Reads out $swsfile and returns a Pairtwo6 class object * * @param string $swsfile + * @throws LibpairtwoException * @deprecated */ public static function ReadSws(string $swsfile) { - trigger_error ( "This function is deprecated. Please convert your code to use the new pattern. More info to be found on Github (https://github.com/JeroenED/libpairtwo/wiki/Converting-your-code-to-the-generalized-format).", E_USER_DEPRECATED); + trigger_error("This function is deprecated. Please convert your code to use the new pattern. More info to be found on Github (https://github.com/JeroenED/libpairtwo/wiki/Converting-your-code-to-the-generalized-format).", E_USER_DEPRECATED); $reader = IOFactory::createReader("Pairtwo-6"); return $reader->read($swsfile); } - }