@ -12,6 +12,7 @@
namespace JeroenED\Libpairtwo;
use Closure;
use DateTime;
use JeroenED\Libpairtwo\Enums\Tiebreak;
use JeroenED\Libpairtwo\Enums\Color;
@ -107,7 +108,7 @@ class Tournament
* @param integer $id
* @return Player
*/
public function getPlayerById(int $id)
public function getPlayerById(int $id): Player
{
return $this->GetPlayers()[$id];
}
@ -116,12 +117,14 @@ class Tournament
* Adds a player
*
* @param Player $Player
* @return Tournament
*/
public function addPlayer(Player $Player)
public function addPlayer(Player $Player): Tournament
{
$newArray = $this->GetPlayers();
$newArray[] = $Player;
$this->setPlayers($newArray);
return $this;
}
/**
@ -129,36 +132,42 @@ class Tournament
*
* @param int $id
* @param Player $player
* @return Tournament
*/
public function updatePlayer(int $id, Player $player)
public function updatePlayer(int $id, Player $player): Tournament
{
$newArray = $this->GetPlayers();
$newArray[$id] = $player;
$this->setPlayers($newArray);
return $this;
}
/**
* Adds a Tiebreak
*
* @param Tiebreak $tiebreak
* @return Tournament
*/
public function addTiebreak(Tiebreak $tiebreak)
public function addTiebreak(Tiebreak $tiebreak): Tournament
{
$newArray = $this->getTiebreaks();
$newArray[] = $tiebreak;
$this->setTiebreaks($newArray);
return $this;
}
/**
* Adds a round with given Round object
*
* @param Round $round
* @return Tournament
*/
public function addRound(Round $round)
public function addRound(Round $round): Tournament
{
$newArray = $this->getRounds();
$newArray[$round->getRoundNo()] = $round;
$this->setRounds($newArray);
return $this;
}
/**
@ -176,18 +185,22 @@ class Tournament
* Adds a pairing to the tournament
*
* @param Pairing $pairing
* @return Tournament
*/
public function addPairing(Pairing $pairing)
public function addPairing(Pairing $pairing): Tournament
{
$newArray = $this->GetPairings();
$newArray[] = $pairing;
$this->setPairings($newArray);
return $this;
}
/**
* Converts pairings into games with a black and white player
*
* @return Tournament
*/
public function pairingsToRounds(): void
public function pairingsToRounds(): Tournament
{
/** @var Pairing[] $pairings */
$pairings = $this->getPairings();
@ -225,11 +238,12 @@ class Tournament
$cache[] = $pairing;
} else {
// Check if game already exists
if (!$this->G ameExists($game, $round)) {
if (!$this->g ameExists($game, $round)) {
$this->AddGame($game, $round);
}
}
}
return $this;
}
/**
@ -239,7 +253,7 @@ class Tournament
* @param int $round
* @return bool
*/
public function G ameExists(Game $game, int $round = -1): bool
public function g ameExists(Game $game, int $round = -1): bool
{
$search = [ $round ];
if ($round == -1) {
@ -275,8 +289,9 @@ class Tournament
*
* @param Game $game
* @param int $round
* @return Tournament
*/
public function addGame(Game $game, int $round)
public function addGame(Game $game, int $round): Tournament
{
if (!isset($this->getRounds()[$round])) {
$roundObj = new Round();
@ -285,6 +300,7 @@ class Tournament
}
$this->getRoundByNo($round)->addGame($game);
return $this;
}
/**
@ -292,7 +308,7 @@ class Tournament
*
* @return Player[]
*/
public function getRanking()
public function getRanking(): array
{
$players = $this->getPlayers();
foreach ($this->getTiebreaks() as $tbkey=>$tiebreak) {
@ -337,10 +353,10 @@ class Tournament
/**
* @param Player $a
* @param Player $b
* @return \ Closure
* @return Closure
*/
private function sortTiebreak(int $key)
private function sortTiebreak(int $key): Closure
{
return function (Player $a, Player $b) use ($key) {
if (($b->getTiebreaks()[$key] == $a->getTiebreaks()[$key]) || ($a->getTiebreaks()[$key] === false) || ($b->getTiebreaks()[$key] === false)) {
@ -352,7 +368,7 @@ class Tournament
/**
* @return float|null
* @return float | null
*/
private function calculateTiebreak(Tiebreak $tiebreak, Player $player, int $tbkey = 0): ?float
{
@ -452,7 +468,7 @@ class Tournament
/**
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculateKeizer(Player $player): ?float
{
@ -462,7 +478,7 @@ class Tournament
/**
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculateAmerican(Player $player): ?float
{
@ -472,7 +488,7 @@ class Tournament
/**
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculatePoints(Player $player): ?float
{
@ -482,7 +498,7 @@ class Tournament
/**
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculateBaumbach(Player $player): ?float
{
@ -498,7 +514,7 @@ class Tournament
/**
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculateBlackPlayed(Player $player): ?float
{
@ -513,7 +529,7 @@ class Tournament
/**
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculateBlackWin(Player $player): ?float
{
@ -528,10 +544,12 @@ class Tournament
/**
* Result between the tied players
*
* @param Player $player
* @param array $opponents
* @param int $key
* @return float|null
* @return float | null
*/
private function calculateMutualResult(Player $player, array $opponents, int $key): ?float
{
@ -568,6 +586,8 @@ class Tournament
/**
* The average rating of the opponents
*
* @param Player $player
* @param int $cut
* @return float
@ -591,9 +611,11 @@ class Tournament
/**
* The average performance of the opponents
*
* @param Player $player
* @param int $cut
* @return float|null
* @return float | null
*/
private function calculateAveragePerformance(Player $player, string $type, int $cut = 0): ?float
{
@ -614,9 +636,11 @@ class Tournament
/**
* Points against players who have more than $cut % points
*
* @param Player $player
* @param int $cut
* @return float|null
* @return float | null
*/
private function calculateKoya(Player $player, int $cut = 50): ?float
{
@ -635,10 +659,11 @@ class Tournament
/**
* The combined points of the opponents
* @param Player $player
* @param int $cutlowest
* @param int $cuthighest
* @return float|null
* @return float | null
*/
private function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0): ?float
{
@ -672,8 +697,10 @@ class Tournament
/**
* The points of $player's opponents who $player won against, plus half of the points of $player's opponents who $player drew against
*
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculateSonneborn(Player $player): ?float
{
@ -692,8 +719,10 @@ class Tournament
/**
* 3 points for each, 1 for each draw and no for losing. -1 for not played games
*
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculateSoccerKashdan(Player $player): ?float
{
@ -717,8 +746,10 @@ class Tournament
}
/**
* 4 points for each, 2 for each draw and 1 point for losing. 0 points for not played games
*
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculateKashdan(Player $player): ?float
{
@ -742,8 +773,10 @@ class Tournament
}
/**
* Combined score of $player after each round
*
* @param Player $player
* @return float|null
* @return float | null
*/
private function calculateCumulative(Player $player): ?float
{
@ -763,6 +796,8 @@ class Tournament
}
/**
* Returns the name of the tournament
*
* @return string
*/
public function getName(): string
@ -771,8 +806,10 @@ class Tournament
}
/**
* Sets the name of the tournament
*
* @param string $Name
* @return \JeroenED\Libpairtwo\Models\Tournament
* @return Tournament
*/
public function setName(string $Name): Tournament
{
@ -781,6 +818,8 @@ class Tournament
}
/**
* Returns the organiser of the tournament
*
* @return string
*/
public function getOrganiser(): string
@ -789,6 +828,8 @@ class Tournament
}
/**
* Sets the organiser of the tournament
*
* @param string $Organiser
* @return Tournament
*/
@ -799,6 +840,8 @@ class Tournament
}
/**
* Returns the clubidentifier of the tournament
*
* @return int
*/
public function getOrganiserClubNo(): int
@ -807,6 +850,8 @@ class Tournament
}
/**
* Sets the clubidentifier of the tournament
*
* @param int $OrganiserClubNo
* @return Tournament
*/
@ -817,6 +862,8 @@ class Tournament
}
/**
* Returns the club of the organiser
*
* @return string
*/
public function getOrganiserClub(): string
@ -825,6 +872,8 @@ class Tournament
}
/**
* Sets the club of the organiser
*
* @param string $OrganiserClub
* @return Tournament
*/
@ -835,6 +884,8 @@ class Tournament
}
/**
* Returns the location of the tournament
*
* @return string
*/
public function getOrganiserPlace(): string
@ -843,6 +894,8 @@ class Tournament
}
/**
* Sets the location of the tournament
*
* @param string $OrganiserPlace
* @return Tournament
*/
@ -853,6 +906,8 @@ class Tournament
}
/**
* Returns the country where the tournament is held
*
* @return string
*/
public function getOrganiserCountry(): string
@ -861,6 +916,8 @@ class Tournament
}
/**
* Sets the country where the tournament is held
*
* @param string $OrganiserCountry
* @return Tournament
*/
@ -871,6 +928,8 @@ class Tournament
}
/**
* Returns the fide homologation
*
* @return int
*/
public function getFideHomol(): int
@ -879,6 +938,8 @@ class Tournament
}
/**
* Sets the fide homologation
*
* @param int $FideHomol
* @return Tournament
*/
@ -889,6 +950,8 @@ class Tournament
}
/**
* Returns the start date of the tournament
*
* @return DateTime
*/
public function getStartDate(): DateTime
@ -897,6 +960,8 @@ class Tournament
}
/**
* Sets the start date of the tournament
*
* @param DateTime $StartDate
* @return Tournament
*/
@ -907,6 +972,8 @@ class Tournament
}
/**
* Returns the end date of the tournament
*
* @return DateTime
*/
public function getEndDate(): DateTime
@ -915,6 +982,8 @@ class Tournament
}
/**
* Sets the end date of the tournament
*
* @param DateTime $EndDate
* @return Tournament
*/
@ -925,6 +994,8 @@ class Tournament
}
/**
* Returns the arbiter of the tournament
*
* @return string
*/
public function getArbiter(): string
@ -933,6 +1004,8 @@ class Tournament
}
/**
* Sets the arbiter of the tournament
*
* @param string $Arbiter
* @return Tournament
*/
@ -943,6 +1016,8 @@ class Tournament
}
/**
* Returns the number of round
*
* @return int
*/
public function getNoOfRounds(): int
@ -951,6 +1026,8 @@ class Tournament
}
/**
* Sets the number of rounds
*
* @param int $NoOfRounds
* @return Tournament
*/
@ -961,6 +1038,8 @@ class Tournament
}
/**
* Returns an array containing all rounds of the tournament
*
* @return Round[]
*/
public function getRounds(): array
@ -969,6 +1048,8 @@ class Tournament
}
/**
* Sets an array containing all rounds of the tournament
*
* @param Round[] $Rounds
* @return Tournament
*/
@ -979,6 +1060,8 @@ class Tournament
}
/**
* Returns the tempo of the tournament
*
* @return string
*/
public function getTempo(): string
@ -987,6 +1070,8 @@ class Tournament
}
/**
* Sets the tempo of the tournament
*
* @param string $Tempo
* @return Tournament
*/
@ -997,6 +1082,8 @@ class Tournament
}
/**
* Returns the elo of a player if the player does not have one
*
* @return int
*/
public function getNonRatedElo(): int
@ -1005,6 +1092,8 @@ class Tournament
}
/**
* Sets the elo of a player if the player does not have one
*
* @param int $NonRatedElo
* @return Tournament
*/
@ -1015,6 +1104,8 @@ class Tournament
}
/**
* Returns the tournament system
*
* @return TournamentSystem
*/
public function getSystem(): TournamentSystem
@ -1023,6 +1114,8 @@ class Tournament
}
/**
* Sets the tournament system
*
* @param TournamentSystem $System
* @return Tournament
*/
@ -1033,6 +1126,8 @@ class Tournament
}
/**
* Returns the first period of the tempo
*
* @return string
*/
public function getFirstPeriod(): string
@ -1041,6 +1136,8 @@ class Tournament
}
/**
* Sets the first period of the tempo
*
* @param string $FirstPeriod
* @return Tournament
*/
@ -1051,6 +1148,8 @@ class Tournament
}
/**
* Returns the second period of the tempo
*
* @return string
*/
public function getSecondPeriod(): string
@ -1059,6 +1158,8 @@ class Tournament
}
/**
* Sets the second period of the tempo
*
* @param string $SecondPeriod
* @return Tournament
*/
@ -1069,6 +1170,8 @@ class Tournament
}
/**
* Returns the federation the tournament belongs to
*
* @return string
*/
public function getFederation(): string
@ -1077,6 +1180,8 @@ class Tournament
}
/**
* Sets the federation the tournament belongs to
*
* @param string $Federation
* @return Tournament
*/
@ -1087,6 +1192,8 @@ class Tournament
}
/**