Removed calculated getters

This commit is contained in:
Jeroen De Meerleer 2019-11-16 14:46:01 +01:00
parent 9859984a2a
commit cded84ce03
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
5 changed files with 64 additions and 26 deletions

View File

@ -81,7 +81,7 @@ class Player
* @param Tournament $tournament * @param Tournament $tournament
* @return Player[] * @return Player[]
*/ */
public static function getPlayersByName(string $search, Tournament $tournament): array public static function PlayersByName(string $search, Tournament $tournament): array
{ {
/** @var Player[] */ /** @var Player[] */
$players = $tournament->Players; $players = $tournament->Players;
@ -154,7 +154,7 @@ class Player
* *
* @return int * @return int
*/ */
public function getNoOfWins(): int private function noOfWins(): int
{ {
$wins = 0; $wins = 0;
foreach ($this->Pairings as $pairing) { foreach ($this->Pairings as $pairing) {
@ -195,7 +195,7 @@ class Player
* *
* @return float * @return float
*/ */
public function getPointsForBuchholz(): float private function pointsForBuchholz(): float
{ {
$points = 0; $points = 0;
foreach ($this->Pairings as $pairing) { foreach ($this->Pairings as $pairing) {
@ -216,7 +216,7 @@ class Player
* *
* @return int * @return int
*/ */
public function getPerformance(string $type, int $unratedElo): float public function Performance(string $type, int $unratedElo): float
{ {
$total = 0; $total = 0;
$opponents = 0; $opponents = 0;
@ -243,7 +243,7 @@ class Player
* *
* @return int * @return int
*/ */
public function getPlayedGames(): int private function playedGames(): int
{ {
$total = 0; $total = 0;
foreach ($this->Pairings as $pairing) { foreach ($this->Pairings as $pairing) {
@ -255,14 +255,20 @@ class Player
} }
/** /**
* Returns binary data that was read out the pairing file but was not needed immediately * Magic method to read out several fields. If field was not found it is being searched in the binary data fields
* *
* @param string $key * @param string $key
* @return bool|DateTime|int|string|null * @return bool|DateTime|int|string|null
*/ */
public function __get(string $key) public function __get(string $key)
{ {
if (isset($this->BinaryData[$key])) { if($key == 'PlayedGames') {
return $this->playedGames();
} elseif ($key == 'NoOfWins') {
return $this->noOfWins();
} elseif ($key == 'PointsForBuchholz') {
return $this->pointsForBuchholz();
} elseif (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key]; return $this->BinaryData[$key];
} }
return null; return null;

View File

@ -492,7 +492,7 @@ class Pairtwo6 implements ReaderInterface
$offset += $length; $offset += $length;
for ($i = 0; $i < $this->NewPlayer; $i++) { for ($i = 0; $i < $this->NewPlayer; $i++) {
$player = $this->Tournament->getPlayerById($i); $player = $this->Tournament->PlayerById($i);
$namelength = $player->NameLength; $namelength = $player->NameLength;
$nameoffset = $player->NamePos; $nameoffset = $player->NamePos;
$player->Name = $this->readData("String", substr($this->PlayerNames, $nameoffset, $namelength)); $player->Name = $this->readData("String", substr($this->PlayerNames, $nameoffset, $namelength));
@ -640,12 +640,12 @@ class Pairtwo6 implements ReaderInterface
for ($x = 0; $x < $this->CreatedRounds; $x++) { for ($x = 0; $x < $this->CreatedRounds; $x++) {
$pairing = new Pairing(); $pairing = new Pairing();
$pairing->Player = $this->Tournament->getPlayerById($i); $pairing->Player = $this->Tournament->PlayerById($i);
$length = 4; $length = 4;
$opponent = $this->readData('Int', substr($swscontents, $offset, $length)); $opponent = $this->readData('Int', substr($swscontents, $offset, $length));
if ($opponent != 4294967295) { if ($opponent != 4294967295) {
$pairing->Opponent = $this->Tournament->getPlayerById($opponent); $pairing->Opponent = $this->Tournament->PlayerById($opponent);
} }
$offset += $length; $offset += $length;

View File

@ -432,10 +432,10 @@ class Swar4 implements ReaderInterface
while (null !== $this->Tournament->Pairing[$ptn]['round']) { while (null !== $this->Tournament->Pairing[$ptn]['round']) {
$pairing = new Pairing(); $pairing = new Pairing();
$pairing->Player = $this->Tournament->getPlayerById($this->Tournament->Pairing[$ptn]['player']); $pairing->Player = $this->Tournament->PlayerById($this->Tournament->Pairing[$ptn]['player']);
$pairing->Round = $this->Tournament->Pairing[$ptn]['round']; $pairing->Round = $this->Tournament->Pairing[$ptn]['round'];
if ($this->Tournament->Pairing[$ptn]['opponent'] != 4294967295) { if ($this->Tournament->Pairing[$ptn]['opponent'] != 4294967295) {
$pairing->Opponent = $this->Tournament->getPlayerById($inscriptionNos[$this->Tournament->Pairing[$ptn]['opponent']]); $pairing->Opponent = $this->Tournament->PlayerById($inscriptionNos[$this->Tournament->Pairing[$ptn]['opponent']]);
} }
switch ($this->Tournament->Pairing[$ptn]['result']) { switch ($this->Tournament->Pairing[$ptn]['result']) {
case '1000': case '1000':

View File

@ -84,7 +84,7 @@ class Round
* *
* @return Pairing[] * @return Pairing[]
*/ */
public function getBye(): array private function bye(): array
{ {
$allPairings = $this->Pairings; $allPairings = $this->Pairings;
$byePairings = []; $byePairings = [];
@ -101,7 +101,7 @@ class Round
* *
* @return Pairing[] * @return Pairing[]
*/ */
public function getAbsent(): array private function absent(): array
{ {
$allPairings = $this->Pairings; $allPairings = $this->Pairings;
$absentPairings = []; $absentPairings = [];
@ -118,7 +118,7 @@ class Round
* *
* @return Game[] * @return Game[]
*/ */
public function getGamesByBoard(): array private function gamesByBoard(): array
{ {
$allGames = $this->Games; $allGames = $this->Games;
usort($allGames, array($this, 'sortByBoard')); usort($allGames, array($this, 'sortByBoard'));
@ -139,4 +139,27 @@ class Round
} }
return ($a->Board > $b->Board) ? +1 : -1; return ($a->Board > $b->Board) ? +1 : -1;
} }
/**
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
*
* @param string $key
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)
{
if ($key == 'Bye') {
return $this->bye();
}
elseif ($key == 'Absent') {
return $this->absent();
}
elseif ($key == 'GamesByBoard') {
return $this->gamesByBoard();
}
elseif (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key];
}
return null;
}
} }

View File

@ -111,7 +111,7 @@ class Tournament
* @param integer $id * @param integer $id
* @return Player * @return Player
*/ */
public function getPlayerById(int $id): Player public function PlayerById(int $id): Player
{ {
return $this->Players[$id]; return $this->Players[$id];
} }
@ -175,7 +175,7 @@ class Tournament
* @param int $roundNo * @param int $roundNo
* @return Round * @return Round
*/ */
public function getRoundByNo(int $roundNo): Round public function RoundByNo(int $roundNo): Round
{ {
return $this->Rounds[$roundNo]; return $this->Rounds[$roundNo];
} }
@ -230,7 +230,7 @@ class Tournament
$round = $pairing->Round; $round = $pairing->Round;
$color = $pairing->Color; $color = $pairing->Color;
$this->getRoundByNo($round)->addPairing($pairing); $this->RoundByNo($round)->addPairing($pairing);
$opponent = null; $opponent = null;
/** /**
@ -328,7 +328,7 @@ class Tournament
$this->addRound($roundObj); $this->addRound($roundObj);
} }
$this->getRoundByNo($round)->addGame($game); $this->RoundByNo($round)->addGame($game);
} }
/** /**
@ -336,7 +336,7 @@ class Tournament
* *
* @return Player[] * @return Player[]
*/ */
public function getRanking(): array private function ranking(): array
{ {
$players = $this->Players; $players = $this->Players;
foreach ($this->Tiebreaks as $tbkey=>$tiebreak) { foreach ($this->Tiebreaks as $tbkey=>$tiebreak) {
@ -465,7 +465,7 @@ class Tournament
return $this->calculateAveragePerformance($player, $this->PriorityElo); return $this->calculateAveragePerformance($player, $this->PriorityElo);
break; break;
case Tiebreak::Performance: case Tiebreak::Performance:
return $player->getPerformance($this->PriorityElo, $this->NonRatedElo); return $player->Performance($this->PriorityElo, $this->NonRatedElo);
break; break;
default: default:
return null; return null;
@ -477,7 +477,7 @@ class Tournament
* *
* @return int * @return int
*/ */
public function getAverageElo(): int private function averageElo(): int
{ {
$totalrating = 0; $totalrating = 0;
$players = 0; $players = 0;
@ -498,7 +498,7 @@ class Tournament
* *
* @return int * @return int
*/ */
public function getParticipants(): int private function participants(): int
{ {
return count($this->Players); return count($this->Players);
} }
@ -665,7 +665,7 @@ class Tournament
$allratings = []; $allratings = [];
foreach ($pairings as $pairing) { foreach ($pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) === false) { if (array_search($pairing->Result, Constants::NotPlayed) === false) {
$toadd = $pairing->Opponent->getPerformance($type, $this->NonRatedElo); $toadd = $pairing->Opponent->Performance($type, $this->NonRatedElo);
if ($toadd != 0) { if ($toadd != 0) {
$allratings[] = $toadd; $allratings[] = $toadd;
} }
@ -820,14 +820,23 @@ class Tournament
} }
/** /**
* Returns binary data that was read out the pairing file but was not needed immediately * Magic method to read out several fields. If field was not found it is being searched in the binary data fields
* *
* @param string $key * @param string $key
* @return bool|DateTime|int|string|null * @return bool|DateTime|int|string|null
*/ */
public function __get(string $key) public function __get(string $key)
{ {
if (isset($this->BinaryData[$key])) { if ($key == 'Participants') {
return $this->participants();
}
elseif ($key == 'AverageElo') {
return $this->averageElo();
}
elseif ($key == 'Ranking') {
return $this->ranking();
}
elseif (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key]; return $this->BinaryData[$key];
} }
return null; return null;