Replaced setters by fluent setters

This commit is contained in:
Jeroen De Meerleer 2019-05-28 14:10:42 +02:00
parent d6c4e99983
commit e92240d56f
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
7 changed files with 240 additions and 124 deletions

View File

@ -13,60 +13,68 @@ use JeroenED\Libpairtwo\Pairing;
abstract class Game
{
/** @var Pairing */
/** @var Pairing|null */
private $white;
/** @var Pairing */
/** @var Pairing|null */
private $black;
/** @var GameResult */
private $result;
/**
* @return Pairing
* @return Pairing|null
*/
public function getWhite()
public function getWhite(): ?Pairing
{
return $this->white;
}
/**
* @param Pairing $white
* @param Pairing|null $white
* @return Game
*/
public function setWhite($white): void
public function setWhite(?Pairing $white): Game
{
$this->white = $white;
return $this;
}
/**
* @return Pairing
* @return Pairing|null
*/
public function getBlack()
public function getBlack(): ?Pairing
{
return $this->black;
}
/**
* @param Pairing $black
* @param Pairing|null $black
* @return Game
*/
public function setBlack($black): void
public function setBlack(?Pairing $black): Game
{
$this->black = $black;
return $this;
}
/**
* @return GameResult
* @return Gameresult
*/
public function getResult()
public function getResult(): Gameresult
{
return $this->result;
}
/**
* @param GameResult $result
* @param Gameresult $result
* @return Game
*/
public function setResult(GameResult $result): void
public function setResult(Gameresult $result): Game
{
$this->result = $result;
return $this;
}
}

View File

@ -14,10 +14,10 @@ use JeroenED\Libpairtwo\Player;
abstract class Pairing
{
/** @var Player */
/** @var Player|null */
private $Player;
/** @var Player */
/** @var Player|null */
private $Opponent;
/** @var Color */
@ -30,35 +30,39 @@ abstract class Pairing
private $Round;
/**
* @return Player
* @return Player|null
*/
public function getPlayer()
public function getPlayer(): ?Player
{
return $this->Player;
}
/**
* @param Player $Player
* @param Player|null $Player
* @return Pairing
*/
public function setPlayer(Player $Player): void
public function setPlayer(?Player $Player): Pairing
{
$this->Player = $Player;
return $this;
}
/**
* @return Player
* @return Player|null
*/
public function getOpponent()
public function getOpponent(): ?Player
{
return $this->Opponent;
}
/**
* @param Player $Opponent
* @param Player|null $Opponent
* @return Pairing
*/
public function setOpponent(Player $Opponent): void
public function setOpponent(?Player $Opponent): Pairing
{
$this->Opponent = $Opponent;
return $this;
}
/**
@ -71,10 +75,12 @@ abstract class Pairing
/**
* @param Color $Color
* @return Pairing
*/
public function setColor(Color $Color): void
public function setColor(Color $Color): Pairing
{
$this->Color = $Color;
return $this;
}
/**
@ -87,10 +93,12 @@ abstract class Pairing
/**
* @param Result $Result
* @return Pairing
*/
public function setResult(Result $Result): void
public function setResult(Result $Result): Pairing
{
$this->Result = $Result;
return $this;
}
/**
@ -103,9 +111,11 @@ abstract class Pairing
/**
* @param int $Round
* @return Pairing
*/
public function setRound(int $Round): void
public function setRound(int $Round): Pairing
{
$this->Round = $Round;
return $this;
}
}

View File

@ -82,10 +82,12 @@ abstract class Player
/**
* @param string $Name
* @return Player
*/
public function setName($Name): void
public function setName(string $Name): Player
{
$this->Name = $Name;
return $this;
}
/**
@ -98,10 +100,12 @@ abstract class Player
/**
* @param int $Rank
* @return Player
*/
public function setRank(int $Rank): void
public function setRank(int $Rank): Player
{
$this->Rank = $Rank;
return $this;
}
/**
@ -114,10 +118,12 @@ abstract class Player
/**
* @param int $FideId
* @return Player
*/
public function setFideId(int $FideId): void
public function setFideId(int $FideId): Player
{
$this->FideId = $FideId;
return $this;
}
/**
@ -130,10 +136,12 @@ abstract class Player
/**
* @param int $ExtraPts
* @return Player
*/
public function setExtraPts(int $ExtraPts): void
public function setExtraPts(int $ExtraPts): Player
{
$this->ExtraPts = $ExtraPts;
return $this;
}
/**
@ -146,10 +154,12 @@ abstract class Player
/**
* @param int $KbsbElo
* @return Player
*/
public function setKbsbElo(int $KbsbElo): void
public function setKbsbElo(int $KbsbElo): Player
{
$this->KbsbElo = $KbsbElo;
return $this;
}
/**
@ -162,10 +172,12 @@ abstract class Player
/**
* @param DateTime $dateofbirth
* @return Player
*/
public function setDateofbirth(DateTime $dateofbirth): void
public function setDateofbirth(DateTime $dateofbirth): Player
{
$this->dateofbirth = $dateofbirth;
return $this;
}
/**
@ -178,10 +190,12 @@ abstract class Player
/**
* @param int $KbsbID
* @return Player
*/
public function setKbsbID(int $KbsbID): void
public function setKbsbID(int $KbsbID): Player
{
$this->KbsbID = $KbsbID;
return $this;
}
/**
@ -194,10 +208,12 @@ abstract class Player
/**
* @param float $Points
* @return Player
*/
public function setPoints(float $Points): void
public function setPoints(float $Points): Player
{
$this->Points = $Points;
return $this;
}
/**
@ -210,10 +226,12 @@ abstract class Player
/**
* @param int $ClubNr
* @return Player
*/
public function setClubNr(int $ClubNr): void
public function setClubNr(int $ClubNr): Player
{
$this->ClubNr = $ClubNr;
return $this;
}
/**
@ -226,26 +244,30 @@ abstract class Player
/**
* @param float $ScoreBucholtz
* @return Player
*/
public function setScoreBucholtz(float $ScoreBucholtz): void
public function setScoreBucholtz(float $ScoreBucholtz): Player
{
$this->ScoreBucholtz = $ScoreBucholtz;
return $this;
}
/**
* @return int
* @return float
*/
public function getScoreAmerican(): int
public function getScoreAmerican(): float
{
return $this->ScoreAmerican;
}
/**
* @param int $ScoreAmerican
* @param float $ScoreAmerican
* @return Player
*/
public function setScoreAmerican(int $ScoreAmerican): void
public function setScoreAmerican(float $ScoreAmerican): Player
{
$this->ScoreAmerican = $ScoreAmerican;
return $this;
}
/**
@ -258,10 +280,12 @@ abstract class Player
/**
* @param int $FideElo
* @return Player
*/
public function setFideElo(int $FideElo): void
public function setFideElo(int $FideElo): Player
{
$this->FideElo = $FideElo;
return $this;
}
/**
@ -278,10 +302,12 @@ abstract class Player
* example value: BEL
*
* @param string $Nation
* @return Player
*/
public function setNation(string $Nation): void
public function setNation(string $Nation): Player
{
$this->Nation = $Nation;
return $this;
}
/**
@ -294,10 +320,12 @@ abstract class Player
/**
* @param string $Category
* @return Player
*/
public function setCategory(string $Category): void
public function setCategory(string $Category): Player
{
$this->Category = $Category;
return $this;
}
/**
@ -310,10 +338,12 @@ abstract class Player
/**
* @param Title $Title
* @return Player
*/
public function setTitle(Title $Title): void
public function setTitle(Title $Title): Player
{
$this->Title = $Title;
return $this;
}
/**
@ -326,10 +356,12 @@ abstract class Player
/**
* @param Gender $Gender
* @return Player
*/
public function setGender(Gender $Gender): void
public function setGender(Gender $Gender): Player
{
$this->Gender = $Gender;
return $this;
}
/**
@ -342,26 +374,30 @@ abstract class Player
/**
* @param int $NumberOfTies
* @return Player
*/
public function setNumberOfTies(int $NumberOfTies): void
public function setNumberOfTies(int $NumberOfTies): Player
{
$this->NumberOfTies = $NumberOfTies;
return $this;
}
/**
* @return bool
*/
public function getAbsent(): bool
public function isAbsent(): bool
{
return $this->Absent;
}
/**
* @param bool $Absent
* @return Player
*/
public function setAbsent(bool $Absent): void
public function setAbsent(bool $Absent): Player
{
$this->Absent = $Absent;
return $this;
}
/**
@ -374,9 +410,11 @@ abstract class Player
/**
* @param Pairing[] $Pairings
* @return Player
*/
public function setPairings(array $Pairings): void
public function setPairings(array $Pairings): Player
{
$this->Pairings = $Pairings;
return $this;
}
}

View File

@ -28,35 +28,38 @@ abstract class Round
/**
* @return DateTime
*
*/
public function getDate()
public function getDate(): DateTime
{
return $this->date;
}
/**
* @param DateTime $date
* @return Round
*/
public function setDate($date): void
public function setDate(DateTime $date): Round
{
$this->date = $date;
return $this;
}
/**
* @return Game[]
*/
public function getGames()
public function getGames(): array
{
return $this->games;
}
/**
* @param Game[] $games
* @return Round
*/
public function setGames($games): void
public function setGames(array $games): Round
{
$this->games = $games;
return $this;
}
/**
@ -69,10 +72,12 @@ abstract class Round
/**
* @param int $roundNo
* @return Round
*/
public function setRoundNo(int $roundNo): void
public function setRoundNo(int $roundNo): Round
{
$this->roundNo = $roundNo;
return $this;
}
/**
@ -85,9 +90,11 @@ abstract class Round
/**
* @param Pairing[] $pairings
* @return Round
*/
public function setPairings(array $pairings): void
public function setPairings(array $pairings): Round
{
$this->pairings = $pairings;
return $this;
}
}

View File

@ -72,7 +72,7 @@ abstract class Tournament
private $NoOfRounds;
/** @var Round[] */
private $Rounds;
private $Rounds = [];
/** @var int */
private $Participants;
@ -96,13 +96,13 @@ abstract class Tournament
private $Federation;
/** @var Player[] */
private $Players;
private $Players = [];
/** @var int */
private $Year;
/** @var Pairing[] */
private $Pairings;
private $Pairings = [];
/** @var Tiebreak[] */
private $Tiebreaks = [];
@ -117,10 +117,12 @@ abstract class Tournament
/**
* @param string $Name
* @return Tournament
*/
public function setName(string $Name): void
public function setName(string $Name): Tournament
{
$this->Name = $Name;
return $this;
}
/**
@ -133,26 +135,12 @@ abstract class Tournament
/**
* @param string $Organiser
* @return Tournament
*/
public function setOrganiser(string $Organiser): void
public function setOrganiser(string $Organiser): Tournament
{
$this->Organiser = $Organiser;
}
/**
* @return string
*/
public function getOrganiserClub(): string
{
return $this->OrganiserClub;
}
/**
* @param string $OrganiserClub
*/
public function setOrganiserClub(string $OrganiserClub): void
{
$this->OrganiserClub = $OrganiserClub;
return $this;
}
/**
@ -165,10 +153,30 @@ abstract class Tournament
/**
* @param int $OrganiserClubNo
* @return Tournament
*/
public function setOrganiserClubNo(int $OrganiserClubNo): void
public function setOrganiserClubNo(int $OrganiserClubNo): Tournament
{
$this->OrganiserClubNo = $OrganiserClubNo;
return $this;
}
/**
* @return string
*/
public function getOrganiserClub(): string
{
return $this->OrganiserClub;
}
/**
* @param string $OrganiserClub
* @return Tournament
*/
public function setOrganiserClub(string $OrganiserClub): Tournament
{
$this->OrganiserClub = $OrganiserClub;
return $this;
}
/**
@ -181,10 +189,12 @@ abstract class Tournament
/**
* @param string $OrganiserPlace
* @return Tournament
*/
public function setOrganiserPlace(string $OrganiserPlace): void
public function setOrganiserPlace(string $OrganiserPlace): Tournament
{
$this->OrganiserPlace = $OrganiserPlace;
return $this;
}
/**
@ -197,10 +207,12 @@ abstract class Tournament
/**
* @param string $OrganiserCountry
* @return Tournament
*/
public function setOrganiserCountry(string $OrganiserCountry): void
public function setOrganiserCountry(string $OrganiserCountry): Tournament
{
$this->OrganiserCountry = $OrganiserCountry;
return $this;
}
/**
@ -213,10 +225,12 @@ abstract class Tournament
/**
* @param int $FideHomol
* @return Tournament
*/
public function setFideHomol(int $FideHomol): void
public function setFideHomol(int $FideHomol): Tournament
{
$this->FideHomol = $FideHomol;
return $this;
}
/**
@ -229,10 +243,12 @@ abstract class Tournament
/**
* @param DateTime $StartDate
* @return Tournament
*/
public function setStartDate(DateTime $StartDate): void
public function setStartDate(DateTime $StartDate): Tournament
{
$this->StartDate = $StartDate;
return $this;
}
/**
@ -245,10 +261,12 @@ abstract class Tournament
/**
* @param DateTime $EndDate
* @return Tournament
*/
public function setEndDate(DateTime $EndDate): void
public function setEndDate(DateTime $EndDate): Tournament
{
$this->EndDate = $EndDate;
return $this;
}
/**
@ -261,10 +279,12 @@ abstract class Tournament
/**
* @param string $Arbiter
* @return Tournament
*/
public function setArbiter(string $Arbiter): void
public function setArbiter(string $Arbiter): Tournament
{
$this->Arbiter = $Arbiter;
return $this;
}
/**
@ -277,26 +297,30 @@ abstract class Tournament
/**
* @param int $NoOfRounds
* @return Tournament
*/
public function setNoOfRounds(int $NoOfRounds): void
public function setNoOfRounds(int $NoOfRounds): Tournament
{
$this->NoOfRounds = $NoOfRounds;
return $this;
}
/**
* @return Round[]
*/
public function getRounds()
public function getRounds(): array
{
return $this->Rounds;
}
/**
* @param Round[] $Rounds
* @return Tournament
*/
public function setRounds(array $Rounds): void
public function setRounds(array $Rounds): Tournament
{
$this->Rounds = $Rounds;
return $this;
}
/**
@ -309,10 +333,12 @@ abstract class Tournament
/**
* @param int $Participants
* @return Tournament
*/
public function setParticipants(int $Participants): void
public function setParticipants(int $Participants): Tournament
{
$this->Participants = $Participants;
return $this;
}
/**
@ -325,10 +351,12 @@ abstract class Tournament
/**
* @param string $Tempo
* @return Tournament
*/
public function setTempo(string $Tempo): void
public function setTempo(string $Tempo): Tournament
{
$this->Tempo = $Tempo;
return $this;
}
/**
@ -341,10 +369,12 @@ abstract class Tournament
/**
* @param int $NonRatedElo
* @return Tournament
*/
public function setNonRatedElo(int $NonRatedElo): void
public function setNonRatedElo(int $NonRatedElo): Tournament
{
$this->NonRatedElo = $NonRatedElo;
return $this;
}
/**
@ -357,10 +387,12 @@ abstract class Tournament
/**
* @param TournamentSystem $System
* @return Tournament
*/
public function setSystem(TournamentSystem $System): void
public function setSystem(TournamentSystem $System): Tournament
{
$this->System = $System;
return $this;
}
/**
@ -373,10 +405,12 @@ abstract class Tournament
/**
* @param string $FirstPeriod
* @return Tournament
*/
public function setFirstPeriod(string $FirstPeriod): void
public function setFirstPeriod(string $FirstPeriod): Tournament
{
$this->FirstPeriod = $FirstPeriod;
return $this;
}
/**
@ -389,10 +423,12 @@ abstract class Tournament
/**
* @param string $SecondPeriod
* @return Tournament
*/
public function setSecondPeriod(string $SecondPeriod): void
public function setSecondPeriod(string $SecondPeriod): Tournament
{
$this->SecondPeriod = $SecondPeriod;
return $this;
}
/**
@ -405,26 +441,30 @@ abstract class Tournament
/**
* @param string $Federation
* @return Tournament
*/
public function setFederation(string $Federation): void
public function setFederation(string $Federation): Tournament
{
$this->Federation = $Federation;
return $this;
}
/**
* @return Player[]
*/
public function getPlayers()
public function getPlayers(): array
{
return $this->Players;
}
/**
* @param Player[] $Players
* @return Tournament
*/
public function setPlayers($Players): void
public function setPlayers(array $Players): Tournament
{
$this->Players = $Players;
return $this;
}
/**
@ -437,26 +477,30 @@ abstract class Tournament
/**
* @param int $Year
* @return Tournament
*/
public function setYear(int $Year): void
public function setYear(int $Year): Tournament
{
$this->Year = $Year;
return $this;
}
/**
* @return Pairing[]
*/
public function getPairings()
public function getPairings(): array
{
return $this->Pairings;
}
/**
* @param Pairing[] $Pairings
* @return Tournament
*/
public function setPairings($Pairings): void
public function setPairings(array $Pairings): Tournament
{
$this->Pairings = $Pairings;
return $this;
}
/**
@ -469,9 +513,12 @@ abstract class Tournament
/**
* @param Tiebreak[] $Tiebreaks
* @return Tournament
*/
public function setTiebreaks(array $Tiebreaks): void
public function setTiebreaks(array $Tiebreaks): Tournament
{
$this->Tiebreaks = $Tiebreaks;
return $this;
}
}

View File

@ -16,7 +16,7 @@ abstract class Pairtwo6
private $BinaryData;
/**
* @return String
* @return string
*/
public function getRelease(): string
{
@ -24,11 +24,13 @@ abstract class Pairtwo6
}
/**
* @param String $Release
* @param string $Release
* @return Pairtwo6
*/
public function setRelease(string $Release): void
public function setRelease(string $Release): Pairtwo6
{
$this->Release = $Release;
return $this;
}
/**
@ -41,31 +43,35 @@ abstract class Pairtwo6
/**
* @param Tournament $Tournament
* @return Pairtwo6
*/
public function setTournament(Tournament $Tournament): void
public function setTournament(Tournament $Tournament): Pairtwo6
{
$this->Tournament = $Tournament;
return $this;
}
/**
* Returns binary data from the sws-file
*
* @param string
* @return string
*/
public function getBinaryData(string $key)
{
return $this->BinaryData[$key];
}
/**
* Sets binary data
*
* @param string
* @param mixed
* @param string $Key
* @return bool|DateTime|int|string
*/
public function setBinaryData(string $key, $data): void
public function getBinaryData(string $Key)
{
$this->BinaryData[$key] = $data;
return $this->BinaryData[$Key];
}
/**
* @param string $Key
* @param bool|int|DateTime|string $Value
* @return Pairtwo6
*/
public function setBinaryData(string $Key, $Value): Pairtwo6
{
$this->BinaryData[$Key] = $Value;
return $this;
}
}

View File

@ -58,9 +58,9 @@ echo "Name P3: " . $sws->getTournament()->getPlayerById(2)->getName() . PHP
echo "Gender P1: " . $sws->getTournament()->getPlayerById(0)->getGender()->getKey() . PHP_EOL;
echo "Gender P2: " . $sws->getTournament()->getPlayerById(1)->getGender()->getKey() . PHP_EOL;
echo "Gender P3: " . $sws->getTournament()->getPlayerById(2)->getGender()->getKey() . PHP_EOL;
echo "Absent P1: " . $sws->getTournament()->getPlayerById(0)->getAbsent() . PHP_EOL;
echo "Absent P2: " . $sws->getTournament()->getPlayerById(1)->getAbsent() . PHP_EOL;
echo "Absent P3: " . $sws->getTournament()->getPlayerById(2)->getAbsent() . PHP_EOL;
echo "Absent P1: " . $sws->getTournament()->getPlayerById(0)->isAbsent() . PHP_EOL;
echo "Absent P2: " . $sws->getTournament()->getPlayerById(1)->isAbsent() . PHP_EOL;
echo "Absent P3: " . $sws->getTournament()->getPlayerById(2)->isAbsent() . PHP_EOL;
echo "Date Round 1: " . $sws->getTournament()->getRoundByNo(0)->getDate()->format('d/m/Y') . PHP_EOL;
echo "Date Round 2: " . $sws->getTournament()->getRoundByNo(1)->getDate()->format('d/m/Y') . PHP_EOL;
echo "Date Round 3: " . $sws->getTournament()->getRoundByNo(2)->getDate()->format('d/m/Y') . PHP_EOL;