ENHANCEMENT: Better Docs generation

* NEW FEATURE: Added clean-dist and clean-dev targets
* ENHANCEMENT: Resized logo in Doxygen for better fit
* ENHANCEMENT: Doxygen takes branch name or version tag as `PROJECT_NUMBER`
* CHANGE: Version tag directly put in distribution filename
* CHANGE: `Tournament::GameExists()` renamed to `Tournament::gameExists()`
* CHANGE: Updated composer metadata
* CHANGE: Some setters changed to fluent setters. (More info: 7aca35057c10d2b982f93a698499c0c01df2fdc5)
This commit is contained in:
Jeroen De Meerleer 2019-06-20 15:32:26 +02:00
parent 7e64ad2e1a
commit 922c1cfdbc
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
16 changed files with 322 additions and 145 deletions

2
.gitignore vendored
View File

@ -8,7 +8,7 @@ composer.lock
/.idea /.idea
/doc/api/* /doc/api/*
/libpairtwo-dist.zip /libpairtwo-*-dist.zip
/dist/vendor/ /dist/vendor/
/dist/composer.json /dist/composer.json

View File

@ -1,5 +1,15 @@
# CHANGELOG # CHANGELOG
## vx.y.z (Released: xx-yyy-zzzz)
* NEW FEATURE: Added clean-dist and clean-dev targets
* ENHANCEMENT: Better Docs generation
* ENHANCEMENT: Resied logo in Doxygen for better fit
* ENHANCEMENT: Doxygen takes branch name or version tag as `PROJECT_NUMBER`
* CHANGE: Version tag directly put in distribution filename
* CHANGE: `Tournament::GameExists()` renamed to `Tournament::gameExists()`
* CHANGE: Updated composer metadata
* CHANGE: Some setters changed to fluent setters. (More info: 7aca35057c10d2b982f93a698499c0c01df2fdc5)
## v1.1 (Released: 20-jun-2019) ## v1.1 (Released: 20-jun-2019)
* NEW FEATURE: Libpairtwo distribution releases (use these if you don't have knowledge of composer or dependency management) * NEW FEATURE: Libpairtwo distribution releases (use these if you don't have knowledge of composer or dependency management)
* NEW FEATURE: Soccer Kashdan (aka: kashdan using 3-1-0 scoring) * NEW FEATURE: Soccer Kashdan (aka: kashdan using 3-1-0 scoring)

View File

@ -38,7 +38,7 @@ PROJECT_NAME = libpairtwo
# could be handy for archiving the generated documentation or if some version # could be handy for archiving the generated documentation or if some version
# control system is used. # control system is used.
PROJECT_NUMBER = v1.1 PROJECT_NUMBER = $(VERSIONTAG)
# Using the PROJECT_BRIEF tag one can provide an optional one line description # Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a # for a project that appears at the top of each page and should give viewer a
@ -51,7 +51,7 @@ PROJECT_BRIEF = "A library written in PHP that are saved using common p
# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy # pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
# the logo to the output directory. # the logo to the output directory.
PROJECT_LOGO = ./res/logo-lightback-96px.png PROJECT_LOGO = ./res/logo-lightback-111px.png
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
# into which the generated documentation will be written. If a relative path is # into which the generated documentation will be written. If a relative path is

View File

@ -1,5 +1,7 @@
.PHONY: help tests dist .PHONY: help tests dist
.DEFAULT_GOAL := help .DEFAULT_GOAL := help
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
VERSION := $(if $(TAG),$(TAG),$(BRANCH))
help: help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-12s\033[0m %s\n", $$1, $$2}' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-12s\033[0m %s\n", $$1, $$2}'
@ -14,11 +16,11 @@ view-coverage: ## Shows the code coverage report
open build/coverage/index.html open build/coverage/index.html
api: ## Generates api-docs api: ## Generates api-docs
doxygen VERSIONTAG=$(VERSION) doxygen
dist: ## Generates distribution dist: ## Generates distribution
touch .libpairtwo-dist touch .libpairtwo-dist
git add -A git add .libpairtwo-dist
git commit -m "Commit before release" git commit -m "Commit before release"
cp dist/composer* res/ cp dist/composer* res/
mv dist/composer-dist.json dist/composer.json mv dist/composer-dist.json dist/composer.json
@ -26,23 +28,27 @@ dist: ## Generates distribution
rm dist/composer.json rm dist/composer.json
rm dist/composer.lock rm dist/composer.lock
mv dist/composer-dist-installed.json dist/composer.json mv dist/composer-dist-installed.json dist/composer.json
doxygen make api
mkdir -p dist/doc mkdir -p dist/doc
cp -r doc/api dist/doc cp -r doc/api dist/doc
cd dist && zip -r ../libpairtwo-dist * cd dist && zip -r ../libpairtwo-$(VERSION)-dist.zip *
git reset --hard HEAD^ git reset --hard HEAD^
mv res/composer* dist/ mv res/composer* dist/
clean: ## Cleans the repository clean: clean-dist clean-dev
rm -rf dist/doc
clean-dev:
rm -rf doc/api rm -rf doc/api
rm -rf .idea rm -rf .idea
rm -rf .libpairtwo-distro rm -rf .libpairtwo-distro
rm -rf vendor rm -rf vendor
rm -rf composer.lock rm -rf composer.lock
clean-dist:
rm -rf dist/doc
rm -rf dist/vendor rm -rf dist/vendor
rm -rf dist/composer.json rm -rf dist/composer.json
rm -rf libpairtwo-dist.zip rm -rf libpairtwo-*-dist.zip
cs: ## Fixes coding standard problems cs: ## Fixes coding standard problems
vendor/bin/php-cs-fixer fix || true vendor/bin/php-cs-fixer fix || true
@ -52,5 +58,6 @@ tag: ## Creates a new signed git tag
@echo Tagging $(TAG) @echo Tagging $(TAG)
chag update $(TAG) chag update $(TAG)
git add --all git add --all
git commit -m 'Release $(TAG)' git commit -m 'RELEASE: $(TAG) Release'
git tag -s $(TAG) -m 'Release $(TAG)' git tag -s $(TAG) -m 'RELEASE: $(TAG) Release'
make dist

View File

@ -1,8 +1,8 @@
{ {
"name": "jeroened/libpairtwo", "name": "jeroened/libpairtwo",
"type": "library", "type": "library",
"description": "PHP library that reads and writes SWS files from Pairtwo developed by the Belgian Chess Federation", "description": "A library written in PHP that are saved using common pairing applications",
"keywords": ["chess", "frbe-kbsb", "pairtwo"], "keywords": ["chess", "pairing"],
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
{ {

BIN
res/logo-darkback-111px.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

View File

@ -129,76 +129,4 @@ class Game
$this->result = $result; $this->result = $result;
return $this; return $this;
} }
/**
* @return DateTime
*/
public function getDate(): DateTime
{
return $this->date;
}
/**
* @param DateTime $date
* @return Round
*/
public function setDate(DateTime $date): Round
{
$this->date = $date;
return $this;
}
/**
* @return Game[]
*/
public function getGames(): array
{
return $this->games;
}
/**
* @param Game[] $games
* @return Round
*/
public function setGames(array $games): Round
{
$this->games = $games;
return $this;
}
/**
* @return int
*/
public function getRoundNo(): int
{
return $this->roundNo;
}
/**
* @param int $roundNo
* @return Round
*/
public function setRoundNo(int $roundNo): Round
{
$this->roundNo = $roundNo;
return $this;
}
/**
* @return Pairing[]
*/
public function getPairings(): array
{
return $this->pairings;
}
/**
* @param Pairing[] $pairings
* @return Round
*/
public function setPairings(array $pairings): Round
{
$this->pairings = $pairings;
return $this;
}
} }

View File

@ -42,8 +42,11 @@ abstract class IOFactory
/** /**
* Creates a reader for $type * Creates a reader for $type
* *
* Compatible types are Pairtwo-5 and Pairtwo-6
*
* @param string $type * @param string $type
* @return ReaderInterface * @return ReaderInterface
* @throws LibpairtwoException
*/ */
public static function createReader(string $type): ReaderInterface public static function createReader(string $type): ReaderInterface
{ {

View File

@ -43,6 +43,8 @@ class Pairing
private $Round; private $Round;
/** /**
* Returns the player of the pairing
*
* @return Player | null * @return Player | null
*/ */
public function getPlayer(): ?Player public function getPlayer(): ?Player
@ -51,6 +53,8 @@ class Pairing
} }
/** /**
* Sets the player of the pairing
*
* @param Player | null $Player * @param Player | null $Player
* @return Pairing * @return Pairing
*/ */
@ -61,6 +65,8 @@ class Pairing
} }
/** /**
* Returns the opponent of the pairing
*
* @return Player | null * @return Player | null
*/ */
public function getOpponent(): ?Player public function getOpponent(): ?Player
@ -69,6 +75,8 @@ class Pairing
} }
/** /**
* Sets the opponent of the pairing
*
* @param Player | null $Opponent * @param Player | null $Opponent
* @return Pairing * @return Pairing
*/ */
@ -79,6 +87,8 @@ class Pairing
} }
/** /**
* Returns the color of the pairing
*
* @return Color * @return Color
*/ */
public function getColor(): Color public function getColor(): Color
@ -87,6 +97,8 @@ class Pairing
} }
/** /**
* Sets the color of the pairing
*
* @param Color $Color * @param Color $Color
* @return Pairing * @return Pairing
*/ */
@ -97,6 +109,8 @@ class Pairing
} }
/** /**
* Returns the individual result of the pairing
*
* @return Result * @return Result
*/ */
public function getResult(): Result public function getResult(): Result
@ -105,6 +119,8 @@ class Pairing
} }
/** /**
* Sets the individual result of the pairing
*
* @param Result $Result * @param Result $Result
* @return Pairing * @return Pairing
*/ */
@ -115,6 +131,8 @@ class Pairing
} }
/** /**
* Returns the round number of the pairing
*
* @return int * @return int
*/ */
public function getRound(): int public function getRound(): int
@ -123,6 +141,8 @@ class Pairing
} }
/** /**
* Sets the round number of the pairing
*
* @param int $Round * @param int $Round
* @return Pairing * @return Pairing
*/ */

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;
} }
/** /**
@ -99,6 +101,7 @@ class Player
} }
/** /**
* Returns the elo of elotype for the player
* @param string $type * @param string $type
* @return int * @return int
*/ */
@ -108,6 +111,8 @@ class Player
} }
/** /**
* Sets the elo of elotype for the player
*
* @param string $type * @param string $type
* @param int $value * @param int $value
* @return Player * @return Player
@ -121,6 +126,10 @@ class Player
} }
/** /**
* Returns the identifier of type for the player
*
* Common possible values are Fide or National
*
* @param string $type * @param string $type
* @return string * @return string
*/ */
@ -130,6 +139,10 @@ class Player
} }
/** /**
* Sets the identifier of type for the player
*
* Common possible values are Fide or National
*
* @param string $type * @param string $type
* @param string $value * @param string $value
* @return Player * @return Player
@ -143,9 +156,11 @@ class Player
} }
/** /**
* Returns the number of won matches for the 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) {
@ -157,6 +172,11 @@ class Player
} }
/** /**
* Returns the points of the player.
*
* 1 Point is awarded for winning
* 0.5 points are awarded for draw
*
* @return float * @return float
*/ */
public function getPoints(): float public function getPoints(): float
@ -174,6 +194,10 @@ class Player
/** /**
* Returns the performance rating of the player
*
* WARNING: Calculation currently incorrect. Uses the rule of 400 as temporary solution
*
* @return int * @return int
*/ */
public function getPerformance(string $type, int $unratedElo): float public function getPerformance(string $type, int $unratedElo): float
@ -199,6 +223,8 @@ class Player
/** /**
* Returns the number of played games of the player
*
* @return int * @return int
*/ */
public function getPlayedGames(): int public function getPlayedGames(): int
@ -213,6 +239,8 @@ class Player
} }
/** /**
* Returns the name of the player
*
* @return string * @return string
*/ */
public function getName(): string public function getName(): string
@ -221,8 +249,10 @@ class Player
} }
/** /**
* Sets the name of the player
*
* @param string $Name * @param string $Name
* @return \JeroenED\Libpairtwo\Models\Player * @return Player
*/ */
public function setName(string $Name): Player public function setName(string $Name): Player
{ {
@ -231,6 +261,8 @@ class Player
} }
/** /**
* Returns an array of all ID's of the player
*
* @return string[] * @return string[]
*/ */
public function getIds(): ?array public function getIds(): ?array
@ -239,6 +271,8 @@ class Player
} }
/** /**
* Sets an array of all ID's of the player
*
* @param string[] $Ids * @param string[] $Ids
* @return Player * @return Player
*/ */
@ -249,6 +283,8 @@ class Player
} }
/** /**
* Returns an array of all elos of the player
*
* @return int[] * @return int[]
*/ */
public function getElos(): ?array public function getElos(): ?array
@ -257,6 +293,8 @@ class Player
} }
/** /**
* Sets an array of all elos of the player
*
* @param int[] $Elos * @param int[] $Elos
* @return Player * @return Player
*/ */
@ -267,24 +305,30 @@ class Player
} }
/** /**
* @return \DateTime * Returns the date of birth of the player
*
* @return DateTime
*/ */
public function getDateOfBirth(): \DateTime public function getDateOfBirth(): DateTime
{ {
return $this->DateOfBirth; return $this->DateOfBirth;
} }
/** /**
* @param \DateTime $DateOfBirth * Sets the date of birth of the player
*
* @param DateTime $DateOfBirth
* @return Player * @return Player
*/ */
public function setDateOfBirth(\DateTime $DateOfBirth): Player public function setDateOfBirth(DateTime $DateOfBirth): Player
{ {
$this->DateOfBirth = $DateOfBirth; $this->DateOfBirth = $DateOfBirth;
return $this; return $this;
} }
/** /**
* Returns an array of all tiebreaks for the player
*
* @return float[] * @return float[]
*/ */
public function getTiebreaks(): array public function getTiebreaks(): array
@ -293,6 +337,8 @@ class Player
} }
/** /**
* Sets an array of all tiebreaks for the player
*
* @param float[] $Tiebreaks * @param float[] $Tiebreaks
* @return Player * @return Player
*/ */
@ -303,6 +349,7 @@ class Player
} }
/** /**
* Returns the nation of the player
* example value: BEL * example value: BEL
* *
* @return string * @return string
@ -313,6 +360,7 @@ class Player
} }
/** /**
* Sets the nation of the player
* example value: BEL * example value: BEL
* *
* @param string $Nation * @param string $Nation
@ -325,6 +373,8 @@ class Player
} }
/** /**
* Returns the category of the player
*
* @return string * @return string
*/ */
public function getCategory(): string public function getCategory(): string
@ -333,6 +383,8 @@ class Player
} }
/** /**
* Sets the category of the player
*
* @param string $Category * @param string $Category
* @return Player * @return Player
*/ */
@ -343,6 +395,8 @@ class Player
} }
/** /**
* Returns the title of the player
*
* @return Title * @return Title
*/ */
public function getTitle(): Title public function getTitle(): Title
@ -351,6 +405,8 @@ class Player
} }
/** /**
* Sets the title of the player
*
* @param Title $Title * @param Title $Title
* @return Player * @return Player
*/ */
@ -361,6 +417,8 @@ class Player
} }
/** /**
* Returns the gender of the player
*
* @return Gender * @return Gender
*/ */
public function getGender(): Gender public function getGender(): Gender
@ -369,6 +427,8 @@ class Player
} }
/** /**
* Sets the gender of the player
*
* @param Gender $Gender * @param Gender $Gender
* @return Player * @return Player
*/ */
@ -379,6 +439,8 @@ class Player
} }
/** /**
* Returns an array of all pairings of the player
*
* @return Pairing[] * @return Pairing[]
*/ */
public function getPairings(): array public function getPairings(): array
@ -387,6 +449,8 @@ class Player
} }
/** /**
* Sets an array of all pairings of the player
*
* @param Pairing[] $Pairings * @param Pairing[] $Pairings
* @return Player * @return Player
*/ */
@ -397,6 +461,8 @@ class Player
} }
/** /**
* Returns binary data that was read out the pairtwo file but was not needed immediately
*
* @param string $Key * @param string $Key
* @return bool|DateTime|int|string * @return bool|DateTime|int|string
*/ */
@ -406,6 +472,8 @@ class Player
} }
/** /**
* Sets binary data that is read out the pairtwo file but is not needed immediately
*
* @param string $Key * @param string $Key
* @param bool|int|DateTime|string $Value * @param bool|int|DateTime|string $Value
* @return Player * @return Player

View File

@ -55,6 +55,8 @@ class Pairtwo6 implements ReaderInterface
private $BinaryData; private $BinaryData;
/** /**
* Returns the version tag of Pairtwo which created the pairtwo file
*
* @return string * @return string
*/ */
public function getRelease(): string public function getRelease(): string
@ -63,8 +65,10 @@ class Pairtwo6 implements ReaderInterface
} }
/** /**
* Sets the version tag of Pairtwo which created the pairtwo file
*
* @param string $Release * @param string $Release
* @return \JeroenED\Libpairtwo\Readers\Models\Pairtwo6 * @return Pairtwo6
*/ */
public function setRelease(string $Release): Pairtwo6 public function setRelease(string $Release): Pairtwo6
{ {
@ -73,6 +77,8 @@ class Pairtwo6 implements ReaderInterface
} }
/** /**
* Returns the tournament that was read out of the pairtwo file
*
* @return Tournament * @return Tournament
*/ */
public function getTournament(): Tournament public function getTournament(): Tournament
@ -81,6 +87,8 @@ class Pairtwo6 implements ReaderInterface
} }
/** /**
* Sets the tournament that was read out of the pairtwo file
*
* @param Tournament $Tournament * @param Tournament $Tournament
* @return Pairtwo6 * @return Pairtwo6
*/ */
@ -92,6 +100,8 @@ class Pairtwo6 implements ReaderInterface
/** /**
* Returns binary data that was read out the pairtwo file but was not needed immediately
*
* @param string $Key * @param string $Key
* @return bool|DateTime|int|string * @return bool|DateTime|int|string
*/ */
@ -102,6 +112,8 @@ class Pairtwo6 implements ReaderInterface
/** /**
* Sets binary data that is read out the pairtwo file but is not needed immediately
*
* @param string $Key * @param string $Key
* @param bool|int|DateTime|string $Value * @param bool|int|DateTime|string $Value
* @return Pairtwo6 * @return Pairtwo6
@ -119,7 +131,7 @@ class Pairtwo6 implements ReaderInterface
* @return Pairtwo6 * @return Pairtwo6
* @throws IncompatibleReaderException * @throws IncompatibleReaderException
*/ */
public function read($filename): ReaderInterface public function read(string $filename): ReaderInterface
{ {
$swshandle = fopen($filename, 'rb'); $swshandle = fopen($filename, 'rb');
$swscontents = fread($swshandle, filesize($filename)); $swscontents = fread($swshandle, filesize($filename));

View File

@ -142,7 +142,7 @@ class Round
return $this; return $this;
} }
/** /**
* Returns an array of all games in the tournament * Returns an array of all games for the round
* *
* @return Game[] * @return Game[]
*/ */
@ -151,7 +151,7 @@ class Round
return $this->games; return $this->games;
} }
/** /**
* Sets Round::games to $games * Sets an array of all games for the round
* *
* @param Game[] $games * @param Game[] $games
* @return Round * @return Round
@ -162,7 +162,7 @@ class Round
return $this; return $this;
} }
/** /**
* Returns the round number * Returns the round number of the round
* *
* @return int * @return int
*/ */
@ -171,7 +171,7 @@ class Round
return $this->roundNo; return $this->roundNo;
} }
/** /**
* Sets the round number * Sets the round number of the round
* *
* @param int $roundNo * @param int $roundNo
* @return Round * @return Round
@ -182,7 +182,7 @@ class Round
return $this; return $this;
} }
/** /**
* Returns an array of all pairings for this round * Returns an array of all pairings for the round
* *
* @return Pairing[] * @return Pairing[]
*/ */
@ -191,7 +191,7 @@ class Round
return $this->pairings; return $this->pairings;
} }
/** /**
* Sets Round::Pairings to $pairings * Sets an array of all pairings for the round
* *
* @param Pairing[] $pairings * @param Pairing[] $pairings
* @return Round * @return Round

View File

@ -12,6 +12,7 @@
namespace JeroenED\Libpairtwo; namespace JeroenED\Libpairtwo;
use Closure;
use DateTime; use DateTime;
use JeroenED\Libpairtwo\Enums\Tiebreak; use JeroenED\Libpairtwo\Enums\Tiebreak;
use JeroenED\Libpairtwo\Enums\Color; use JeroenED\Libpairtwo\Enums\Color;
@ -107,7 +108,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 +117,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 +132,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 +185,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();
@ -225,11 +238,12 @@ class Tournament
$cache[] = $pairing; $cache[] = $pairing;
} else { } else {
// Check if game already exists // Check if game already exists
if (!$this->GameExists($game, $round)) { if (!$this->gameExists($game, $round)) {
$this->AddGame($game, $round); $this->AddGame($game, $round);
} }
} }
} }
return $this;
} }
/** /**
@ -239,7 +253,7 @@ class Tournament
* @param int $round * @param int $round
* @return bool * @return bool
*/ */
public function GameExists(Game $game, int $round = -1): bool public function gameExists(Game $game, int $round = -1): bool
{ {
$search = [ $round ]; $search = [ $round ];
if ($round == -1) { if ($round == -1) {
@ -275,8 +289,9 @@ class Tournament
* *
* @param Game $game * @param Game $game
* @param int $round * @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])) { if (!isset($this->getRounds()[$round])) {
$roundObj = new Round(); $roundObj = new Round();
@ -285,6 +300,7 @@ class Tournament
} }
$this->getRoundByNo($round)->addGame($game); $this->getRoundByNo($round)->addGame($game);
return $this;
} }
/** /**
@ -292,7 +308,7 @@ class Tournament
* *
* @return Player[] * @return Player[]
*/ */
public function getRanking() public function getRanking(): array
{ {
$players = $this->getPlayers(); $players = $this->getPlayers();
foreach ($this->getTiebreaks() as $tbkey=>$tiebreak) { foreach ($this->getTiebreaks() as $tbkey=>$tiebreak) {
@ -337,10 +353,10 @@ class Tournament
/** /**
* @param Player $a * @param Player $a
* @param Player $b * @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) { return function (Player $a, Player $b) use ($key) {
if (($b->getTiebreaks()[$key] == $a->getTiebreaks()[$key]) || ($a->getTiebreaks()[$key] === false) || ($b->getTiebreaks()[$key] === false)) { if (($b->getTiebreaks()[$key] == $a->getTiebreaks()[$key]) || ($a->getTiebreaks()[$key] === false) || ($b->getTiebreaks()[$key] === false)) {
@ -528,6 +544,8 @@ class Tournament
/** /**
* Result between the tied players
*
* @param Player $player * @param Player $player
* @param array $opponents * @param array $opponents
* @param int $key * @param int $key
@ -568,6 +586,8 @@ class Tournament
/** /**
* The average rating of the opponents
*
* @param Player $player * @param Player $player
* @param int $cut * @param int $cut
* @return float * @return float
@ -591,6 +611,8 @@ class Tournament
/** /**
* The average performance of the opponents
*
* @param Player $player * @param Player $player
* @param int $cut * @param int $cut
* @return float | null * @return float | null
@ -614,6 +636,8 @@ class Tournament
/** /**
* Points against players who have more than $cut % points
*
* @param Player $player * @param Player $player
* @param int $cut * @param int $cut
* @return float | null * @return float | null
@ -635,6 +659,7 @@ class Tournament
/** /**
* The combined points of the opponents
* @param Player $player * @param Player $player
* @param int $cutlowest * @param int $cutlowest
* @param int $cuthighest * @param int $cuthighest
@ -672,6 +697,8 @@ 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 * @param Player $player
* @return float | null * @return float | null
*/ */
@ -692,6 +719,8 @@ class Tournament
/** /**
* 3 points for each, 1 for each draw and no for losing. -1 for not played games
*
* @param Player $player * @param Player $player
* @return float | null * @return float | null
*/ */
@ -717,6 +746,8 @@ class Tournament
} }
/** /**
* 4 points for each, 2 for each draw and 1 point for losing. 0 points for not played games
*
* @param Player $player * @param Player $player
* @return float | null * @return float | null
*/ */
@ -742,6 +773,8 @@ class Tournament
} }
/** /**
* Combined score of $player after each round
*
* @param Player $player * @param Player $player
* @return float | null * @return float | null
*/ */
@ -763,6 +796,8 @@ class Tournament
} }
/** /**
* Returns the name of the tournament
*
* @return string * @return string
*/ */
public function getName(): string public function getName(): string
@ -771,8 +806,10 @@ class Tournament
} }
/** /**
* Sets the name of the tournament
*
* @param string $Name * @param string $Name
* @return \JeroenED\Libpairtwo\Models\Tournament * @return Tournament
*/ */
public function setName(string $Name): Tournament public function setName(string $Name): Tournament
{ {
@ -781,6 +818,8 @@ class Tournament
} }
/** /**
* Returns the organiser of the tournament
*
* @return string * @return string
*/ */
public function getOrganiser(): string public function getOrganiser(): string
@ -789,6 +828,8 @@ class Tournament
} }
/** /**
* Sets the organiser of the tournament
*
* @param string $Organiser * @param string $Organiser
* @return Tournament * @return Tournament
*/ */
@ -799,6 +840,8 @@ class Tournament
} }
/** /**
* Returns the clubidentifier of the tournament
*
* @return int * @return int
*/ */
public function getOrganiserClubNo(): int public function getOrganiserClubNo(): int
@ -807,6 +850,8 @@ class Tournament
} }
/** /**
* Sets the clubidentifier of the tournament
*
* @param int $OrganiserClubNo * @param int $OrganiserClubNo
* @return Tournament * @return Tournament
*/ */
@ -817,6 +862,8 @@ class Tournament
} }
/** /**
* Returns the club of the organiser
*
* @return string * @return string
*/ */
public function getOrganiserClub(): string public function getOrganiserClub(): string
@ -825,6 +872,8 @@ class Tournament
} }
/** /**
* Sets the club of the organiser
*
* @param string $OrganiserClub * @param string $OrganiserClub
* @return Tournament * @return Tournament
*/ */
@ -835,6 +884,8 @@ class Tournament
} }
/** /**
* Returns the location of the tournament
*
* @return string * @return string
*/ */
public function getOrganiserPlace(): string public function getOrganiserPlace(): string
@ -843,6 +894,8 @@ class Tournament
} }
/** /**
* Sets the location of the tournament
*
* @param string $OrganiserPlace * @param string $OrganiserPlace
* @return Tournament * @return Tournament
*/ */
@ -853,6 +906,8 @@ class Tournament
} }
/** /**
* Returns the country where the tournament is held
*
* @return string * @return string
*/ */
public function getOrganiserCountry(): string public function getOrganiserCountry(): string
@ -861,6 +916,8 @@ class Tournament
} }
/** /**
* Sets the country where the tournament is held
*
* @param string $OrganiserCountry * @param string $OrganiserCountry
* @return Tournament * @return Tournament
*/ */
@ -871,6 +928,8 @@ class Tournament
} }
/** /**
* Returns the fide homologation
*
* @return int * @return int
*/ */
public function getFideHomol(): int public function getFideHomol(): int
@ -879,6 +938,8 @@ class Tournament
} }
/** /**
* Sets the fide homologation
*
* @param int $FideHomol * @param int $FideHomol
* @return Tournament * @return Tournament
*/ */
@ -889,6 +950,8 @@ class Tournament
} }
/** /**
* Returns the start date of the tournament
*
* @return DateTime * @return DateTime
*/ */
public function getStartDate(): DateTime public function getStartDate(): DateTime
@ -897,6 +960,8 @@ class Tournament
} }
/** /**
* Sets the start date of the tournament
*
* @param DateTime $StartDate * @param DateTime $StartDate
* @return Tournament * @return Tournament
*/ */
@ -907,6 +972,8 @@ class Tournament
} }
/** /**
* Returns the end date of the tournament
*
* @return DateTime * @return DateTime
*/ */
public function getEndDate(): DateTime public function getEndDate(): DateTime
@ -915,6 +982,8 @@ class Tournament
} }
/** /**
* Sets the end date of the tournament
*
* @param DateTime $EndDate * @param DateTime $EndDate
* @return Tournament * @return Tournament
*/ */
@ -925,6 +994,8 @@ class Tournament
} }
/** /**
* Returns the arbiter of the tournament
*
* @return string * @return string
*/ */
public function getArbiter(): string public function getArbiter(): string
@ -933,6 +1004,8 @@ class Tournament
} }
/** /**
* Sets the arbiter of the tournament
*
* @param string $Arbiter * @param string $Arbiter
* @return Tournament * @return Tournament
*/ */
@ -943,6 +1016,8 @@ class Tournament
} }
/** /**
* Returns the number of round
*
* @return int * @return int
*/ */
public function getNoOfRounds(): int public function getNoOfRounds(): int
@ -951,6 +1026,8 @@ class Tournament
} }
/** /**
* Sets the number of rounds
*
* @param int $NoOfRounds * @param int $NoOfRounds
* @return Tournament * @return Tournament
*/ */
@ -961,6 +1038,8 @@ class Tournament
} }
/** /**
* Returns an array containing all rounds of the tournament
*
* @return Round[] * @return Round[]
*/ */
public function getRounds(): array public function getRounds(): array
@ -969,6 +1048,8 @@ class Tournament
} }
/** /**
* Sets an array containing all rounds of the tournament
*
* @param Round[] $Rounds * @param Round[] $Rounds
* @return Tournament * @return Tournament
*/ */
@ -979,6 +1060,8 @@ class Tournament
} }
/** /**
* Returns the tempo of the tournament
*
* @return string * @return string
*/ */
public function getTempo(): string public function getTempo(): string
@ -987,6 +1070,8 @@ class Tournament
} }
/** /**
* Sets the tempo of the tournament
*
* @param string $Tempo * @param string $Tempo
* @return Tournament * @return Tournament
*/ */
@ -997,6 +1082,8 @@ class Tournament
} }
/** /**
* Returns the elo of a player if the player does not have one
*
* @return int * @return int
*/ */
public function getNonRatedElo(): 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 * @param int $NonRatedElo
* @return Tournament * @return Tournament
*/ */
@ -1015,6 +1104,8 @@ class Tournament
} }
/** /**
* Returns the tournament system
*
* @return TournamentSystem * @return TournamentSystem
*/ */
public function getSystem(): TournamentSystem public function getSystem(): TournamentSystem
@ -1023,6 +1114,8 @@ class Tournament
} }
/** /**
* Sets the tournament system
*
* @param TournamentSystem $System * @param TournamentSystem $System
* @return Tournament * @return Tournament
*/ */
@ -1033,6 +1126,8 @@ class Tournament
} }
/** /**
* Returns the first period of the tempo
*
* @return string * @return string
*/ */
public function getFirstPeriod(): string public function getFirstPeriod(): string
@ -1041,6 +1136,8 @@ class Tournament
} }
/** /**
* Sets the first period of the tempo
*
* @param string $FirstPeriod * @param string $FirstPeriod
* @return Tournament * @return Tournament
*/ */
@ -1051,6 +1148,8 @@ class Tournament
} }
/** /**
* Returns the second period of the tempo
*
* @return string * @return string
*/ */
public function getSecondPeriod(): string public function getSecondPeriod(): string
@ -1059,6 +1158,8 @@ class Tournament
} }
/** /**
* Sets the second period of the tempo
*
* @param string $SecondPeriod * @param string $SecondPeriod
* @return Tournament * @return Tournament
*/ */
@ -1069,6 +1170,8 @@ class Tournament
} }
/** /**
* Returns the federation the tournament belongs to
*
* @return string * @return string
*/ */
public function getFederation(): string public function getFederation(): string
@ -1077,6 +1180,8 @@ class Tournament
} }
/** /**
* Sets the federation the tournament belongs to
*
* @param string $Federation * @param string $Federation
* @return Tournament * @return Tournament
*/ */
@ -1087,6 +1192,8 @@ class Tournament
} }
/** /**
* Returns an array of all players of the tournament
*
* @return Player[] * @return Player[]
*/ */
public function getPlayers(): array public function getPlayers(): array
@ -1095,6 +1202,8 @@ class Tournament
} }
/** /**
* Sets an array of all players of the tournament
*
* @param Player[] $Players * @param Player[] $Players
* @return Tournament * @return Tournament
*/ */
@ -1105,6 +1214,8 @@ class Tournament
} }
/** /**
* Returns the year the tournament is held in
*
* @return int * @return int
*/ */
public function getYear(): int public function getYear(): int
@ -1113,6 +1224,8 @@ class Tournament
} }
/** /**
* Sets the year the tournament is held in
*
* @param int $Year * @param int $Year
* @return Tournament * @return Tournament
*/ */
@ -1123,6 +1236,8 @@ class Tournament
} }
/** /**
* Returns an array of all pairings of the tournament
*
* @return Pairing[] * @return Pairing[]
*/ */
public function getPairings(): array public function getPairings(): array
@ -1131,6 +1246,8 @@ class Tournament
} }
/** /**
* Sets an array of all pairings of the tournament
*
* @param Pairing[] $Pairings * @param Pairing[] $Pairings
* @return Tournament * @return Tournament
*/ */
@ -1141,6 +1258,8 @@ class Tournament
} }
/** /**
* Returns an array of all tiebreaks of the tournament
*
* @return Tiebreak[] * @return Tiebreak[]
*/ */
public function getTiebreaks(): array public function getTiebreaks(): array
@ -1149,6 +1268,8 @@ class Tournament
} }
/** /**
* Sets an array of all tiebreaks of the tournament
*
* @param Tiebreak[] $Tiebreaks * @param Tiebreak[] $Tiebreaks
* @return Tournament * @return Tournament
*/ */
@ -1159,6 +1280,8 @@ class Tournament
} }
/** /**
* Returns the elo that has priority
*
* @return string * @return string
*/ */
public function getPriorityElo(): string public function getPriorityElo(): string
@ -1167,6 +1290,8 @@ class Tournament
} }
/** /**
* Sets the elo that has priority
*
* @param string $PriorityElo * @param string $PriorityElo
* @return Tournament * @return Tournament
*/ */
@ -1176,6 +1301,8 @@ class Tournament
return $this; return $this;
} }
/** /**
* Returns the identifier that has priority
*
* @return string * @return string
*/ */
public function getPriorityId(): string public function getPriorityId(): string
@ -1184,6 +1311,8 @@ class Tournament
} }
/** /**
* Sets the identifier that has priority
*
* @param string $PriorityId * @param string $PriorityId
* @return Tournament * @return Tournament
*/ */