Implemented fluent setters

This commit is contained in:
Jeroen De Meerleer 2019-06-20 14:23:32 +02:00
parent 12b95eef5b
commit ab6afa89ce
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 25 additions and 10 deletions

View File

@ -66,12 +66,14 @@ class Player
* Adds a pairing to the tournament
*
* @param Pairing $pairing
* @return Player
*/
public function addPairing(Pairing $pairing)
public function addPairing(Pairing $pairing): Player
{
$newArray = $this->GetPairings();
$newArray[] = $pairing;
$this->setPairings($newArray);
return $this;
}
/**
@ -145,7 +147,7 @@ class Player
/**
* @return int
*/
public function getNoOfWins()
public function getNoOfWins(): int
{
$wins = 0;
foreach ($this->getPairings() as $pairing) {
@ -176,7 +178,7 @@ class Player
/**
* @return int
*/
public function getPerformance(string $type, int $unratedElo) : float
public function getPerformance(string $type, int $unratedElo): float
{
$total = 0;
$opponents = 0;

View File

@ -107,7 +107,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 +116,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 +131,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 +184,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();
@ -230,6 +242,7 @@ class Tournament
}
}
}
return $this;
}
/**