Moved tiebreaks to own class

This commit is contained in:
Jeroen De Meerleer 2019-05-28 17:04:53 +02:00
parent 74688ac8b8
commit 865893b30f
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 46 additions and 38 deletions

45
src/Tiebreaks.php Normal file
View File

@ -0,0 +1,45 @@
<?php
namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Models\Tournament;
abstract class Tiebreaks extends Tournament
{
/**
* @param int $key
*/
protected function calculateKeizer(int $key)
{
foreach ($this->getPlayers() as $player) {
$currentTiebreaks = $player->getTiebreaks();
$currentTiebreaks[$key] = $player->getBinaryData('ScoreAmerican');
$player->setTiebreaks($currentTiebreaks);
}
}
/**
* @param int $key
*/
protected function calculateAmerican(int $key)
{
foreach ($this->getPlayers() as $player) {
$currentTiebreaks = $player->getTiebreaks();
$currentTiebreaks[$key] = $player->getBinaryData('ScoreAmerican');
$player->setTiebreaks($currentTiebreaks);
}
}
/**
* @param int $key
*/
protected function calculatePoints(int $key)
{
foreach ($this->getPlayers() as $player) {
$currentTiebreaks = $player->getTiebreaks();
$currentTiebreaks[$key] = $player->getBinaryData('Points');
$player->setTiebreaks($currentTiebreaks);
}
}
}

View File

@ -9,10 +9,9 @@
namespace JeroenED\Libpairtwo; namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Enums\Tiebreak; use JeroenED\Libpairtwo\Enums\Tiebreak;
use JeroenED\Libpairtwo\Models\Tournament as TournamentModel;
use JeroenED\Libpairtwo\Enums\Color; use JeroenED\Libpairtwo\Enums\Color;
class Tournament extends TournamentModel class Tournament extends Tiebreaks
{ {
/** /**
* Gets a player by its ID * Gets a player by its ID
@ -246,40 +245,4 @@ class Tournament extends TournamentModel
} }
return $this; return $this;
} }
/**
* @param int $key
*/
private function calculateKeizer(int $key)
{
foreach ($this->getPlayers() as $player) {
$currentTiebreaks = $player->getTiebreaks();
$currentTiebreaks[$key] = $player->getBinaryData('ScoreAmerican');
$player->setTiebreaks($currentTiebreaks);
}
}
/**
* @param int $key
*/
private function calculateAmerican(int $key)
{
foreach ($this->getPlayers() as $player) {
$currentTiebreaks = $player->getTiebreaks();
$currentTiebreaks[$key] = $player->getBinaryData('ScoreAmerican');
$player->setTiebreaks($currentTiebreaks);
}
}
/**
* @param int $key
*/
private function calculatePoints(int $key)
{
foreach ($this->getPlayers() as $player) {
$currentTiebreaks = $player->getTiebreaks();
$currentTiebreaks[$key] = $player->getBinaryData('Points');
$player->setTiebreaks($currentTiebreaks);
}
}
} }