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

View File

@ -107,7 +107,7 @@ class Tournament
* @param integer $id * @param integer $id
* @return Player * @return Player
*/ */
public function getPlayerById(int $id) public function getPlayerById(int $id): Player
{ {
return $this->GetPlayers()[$id]; return $this->GetPlayers()[$id];
} }
@ -116,12 +116,14 @@ class Tournament
* Adds a player * Adds a player
* *
* @param Player $Player * @param Player $Player
* @return Tournament
*/ */
public function addPlayer(Player $Player) public function addPlayer(Player $Player): Tournament
{ {
$newArray = $this->GetPlayers(); $newArray = $this->GetPlayers();
$newArray[] = $Player; $newArray[] = $Player;
$this->setPlayers($newArray); $this->setPlayers($newArray);
return $this;
} }
/** /**
@ -129,36 +131,42 @@ class Tournament
* *
* @param int $id * @param int $id
* @param Player $player * @param Player $player
* @return Tournament
*/ */
public function updatePlayer(int $id, Player $player) public function updatePlayer(int $id, Player $player): Tournament
{ {
$newArray = $this->GetPlayers(); $newArray = $this->GetPlayers();
$newArray[$id] = $player; $newArray[$id] = $player;
$this->setPlayers($newArray); $this->setPlayers($newArray);
return $this;
} }
/** /**
* Adds a Tiebreak * Adds a Tiebreak
* *
* @param Tiebreak $tiebreak * @param Tiebreak $tiebreak
* @return Tournament
*/ */
public function addTiebreak(Tiebreak $tiebreak) public function addTiebreak(Tiebreak $tiebreak): Tournament
{ {
$newArray = $this->getTiebreaks(); $newArray = $this->getTiebreaks();
$newArray[] = $tiebreak; $newArray[] = $tiebreak;
$this->setTiebreaks($newArray); $this->setTiebreaks($newArray);
return $this;
} }
/** /**
* Adds a round with given Round object * Adds a round with given Round object
* *
* @param Round $round * @param Round $round
* @return Tournament
*/ */
public function addRound(Round $round) public function addRound(Round $round): Tournament
{ {
$newArray = $this->getRounds(); $newArray = $this->getRounds();
$newArray[$round->getRoundNo()] = $round; $newArray[$round->getRoundNo()] = $round;
$this->setRounds($newArray); $this->setRounds($newArray);
return $this;
} }
/** /**
@ -176,18 +184,22 @@ class Tournament
* Adds a pairing to the tournament * Adds a pairing to the tournament
* *
* @param Pairing $pairing * @param Pairing $pairing
* @return Tournament
*/ */
public function addPairing(Pairing $pairing) public function addPairing(Pairing $pairing): Tournament
{ {
$newArray = $this->GetPairings(); $newArray = $this->GetPairings();
$newArray[] = $pairing; $newArray[] = $pairing;
$this->setPairings($newArray); $this->setPairings($newArray);
return $this;
} }
/** /**
* Converts pairings into games with a black and white player * Converts pairings into games with a black and white player
*
* @return Tournament
*/ */
public function pairingsToRounds(): void public function pairingsToRounds(): Tournament
{ {
/** @var Pairing[] $pairings */ /** @var Pairing[] $pairings */
$pairings = $this->getPairings(); $pairings = $this->getPairings();
@ -230,6 +242,7 @@ class Tournament
} }
} }
} }
return $this;
} }
/** /**