Merge branch 'task/removing_files' into develop

This commit is contained in:
Jeroen De Meerleer 2020-08-02 21:52:03 +02:00
commit f4c526ff41
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
23 changed files with 692 additions and 579 deletions

View File

@ -15,32 +15,36 @@
<option name="VARIABLE_NAMING_STYLE" value="CAMEL_CASE" /> <option name="VARIABLE_NAMING_STYLE" value="CAMEL_CASE" />
<option name="BLANK_LINES_BEFORE_RETURN_STATEMENT" value="1" /> <option name="BLANK_LINES_BEFORE_RETURN_STATEMENT" value="1" />
<option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" /> <option name="KEEP_RPAREN_AND_LBRACE_ON_ONE_LINE" value="true" />
<option name="SPACES_AROUND_VAR_WITHIN_BRACKETS" value="true" />
<option name="BLANK_LINES_AROUND_CONSTANTS" value="1" /> <option name="BLANK_LINES_AROUND_CONSTANTS" value="1" />
<option name="KEEP_BLANK_LINES_AFTER_LBRACE" value="1" /> <option name="BLANK_LINES_AFTER_OPENING_TAG" value="1" />
<option name="KEEP_BLANK_LINES_AFTER_LBRACE" value="0" />
<option name="SPACE_BETWEEN_TERNARY_QUEST_AND_COLON" value="true" /> <option name="SPACE_BETWEEN_TERNARY_QUEST_AND_COLON" value="true" />
<option name="FORCE_SHORT_DECLARATION_ARRAY_STYLE" value="true" /> <option name="FORCE_SHORT_DECLARATION_ARRAY_STYLE" value="true" />
<option name="NEW_LINE_AFTER_PHP_OPENING_TAG" value="true" />
<option name="PLACE_PARENS_FOR_CONSTRUCTOR" value="1" /> <option name="PLACE_PARENS_FOR_CONSTRUCTOR" value="1" />
</PHPCodeStyleSettings> </PHPCodeStyleSettings>
<codeStyleSettings language="PHP"> <codeStyleSettings language="PHP">
<option name="RIGHT_MARGIN" value="120" /> <option name="RIGHT_MARGIN" value="120" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" /> <option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" /> <option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" /> <option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="BLANK_LINES_AFTER_PACKAGE" value="1" /> <option name="BLANK_LINES_AFTER_PACKAGE" value="1" />
<option name="BLANK_LINES_AROUND_FIELD" value="1" /> <option name="BLANK_LINES_AROUND_FIELD" value="1" />
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" /> <option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" /> <option name="ALIGN_MULTILINE_PARAMETERS_IN_CALLS" value="true" />
<option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" /> <option name="ALIGN_MULTILINE_BINARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" /> <option name="ALIGN_MULTILINE_TERNARY_OPERATION" value="true" />
<option name="ALIGN_MULTILINE_EXTENDS_LIST" value="true" />
<option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" /> <option name="ALIGN_MULTILINE_ARRAY_INITIALIZER_EXPRESSION" value="true" />
<option name="SPACE_WITHIN_BRACKETS" value="true" /> <option name="SPACE_WITHIN_BRACKETS" value="true" />
<option name="SPACE_WITHIN_ARRAY_INITIALIZER_BRACES" value="true" />
<option name="CALL_PARAMETERS_WRAP" value="5" /> <option name="CALL_PARAMETERS_WRAP" value="5" />
<option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" /> <option name="CALL_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" /> <option name="CALL_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_WRAP" value="5" />
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" /> <option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
<option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" /> <option name="METHOD_PARAMETERS_RPAREN_ON_NEXT_LINE" value="true" />
<option name="EXTENDS_LIST_WRAP" value="5" />
<option name="METHOD_CALL_CHAIN_WRAP" value="5" /> <option name="METHOD_CALL_CHAIN_WRAP" value="5" />
<option name="PARENTHESES_EXPRESSION_LPAREN_WRAP" value="true" /> <option name="PARENTHESES_EXPRESSION_LPAREN_WRAP" value="true" />
<option name="PARENTHESES_EXPRESSION_RPAREN_WRAP" value="true" /> <option name="PARENTHESES_EXPRESSION_RPAREN_WRAP" value="true" />
@ -49,11 +53,13 @@
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" /> <option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
<option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" /> <option name="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<option name="FOR_STATEMENT_WRAP" value="5" /> <option name="FOR_STATEMENT_WRAP" value="5" />
<option name="FOR_STATEMENT_LPAREN_ON_NEXT_LINE" value="true" />
<option name="FOR_STATEMENT_RPAREN_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_WRAP" value="5" /> <option name="ARRAY_INITIALIZER_WRAP" value="5" />
<option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" /> <option name="ARRAY_INITIALIZER_LBRACE_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" /> <option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
<option name="ASSIGNMENT_WRAP" value="5" /> <option name="ASSIGNMENT_WRAP" value="5" />
<option name="IF_BRACE_FORCE" value="1" /> <option name="IF_BRACE_FORCE" value="3" />
<option name="DOWHILE_BRACE_FORCE" value="3" /> <option name="DOWHILE_BRACE_FORCE" value="3" />
<option name="WHILE_BRACE_FORCE" value="3" /> <option name="WHILE_BRACE_FORCE" value="3" />
<option name="FOR_BRACE_FORCE" value="3" /> <option name="FOR_BRACE_FORCE" value="3" />

View File

@ -0,0 +1,17 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PhpCSValidationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="CODING_STANDARD" value="PSR12" />
<option name="EXTENSIONS" value="php,js,css,inc" />
</inspection_tool>
<inspection_tool class="PhpCompoundNamespaceDepthInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpLongTypeFormInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpMissingVisibilityInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpModifierOrderInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpNewClassMissingParameterListInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpSeparateElseIfInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpTraitsUseListInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpVarUsageInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
</profile>
</component>

12
.php_cs
View File

@ -1,12 +0,0 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude(['build', 'vendor'])
->in(__DIR__);
return PhpCsFixer\Config::create()
->setFinder($finder)
->setUsingCache(true)
->setRules([
'@PSR2' => true,
]);

View File

@ -12,6 +12,8 @@ install-dev: ## Installs the required common devtools
@echo "Downloading phpcs" @echo "Downloading phpcs"
@wget https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar -O bin/phpcs 2> /dev/null @wget https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar -O bin/phpcs 2> /dev/null
@wget https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar -O bin/phpcbf 2> /dev/null @wget https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar -O bin/phpcbf 2> /dev/null
@echo "Adding execution rights on the binaries"
@chmod +x bin/phpcs bin/phpcbf bin/phpdoc
@echo "Installation of devtools finished" @echo "Installation of devtools finished"
@echo "Please add $(shell echo $(PWD))/bin to your PATH" @echo "Please add $(shell echo $(PWD))/bin to your PATH"
@ -54,7 +56,7 @@ clean-repo: ## Cleans the git repository
git gc git gc
cs: ## Fixes coding standard problems cs: ## Fixes coding standard problems
vendor/bin/php-cs-fixer fix || true php bin/phpcs || true
tag: ## Creates a new signed git tag tag: ## Creates a new signed git tag
$(if $(TAG),,$(error TAG is not defined. Pass via "make tag TAG=X.X.X")) $(if $(TAG),,$(error TAG is not defined. Pass via "make tag TAG=X.X.X"))

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class Constants * Class Constants
* *
@ -27,11 +28,28 @@ use JeroenED\Libpairtwo\Enums\Result;
*/ */
class Constants class Constants
{ {
const Won = [ Result::Won, Result::WonForfait, Result::WonBye, Result::WonAdjourned ]; public const WON = [Result::WON, Result::WON_FORFAIT, Result::WON_BYE, Result::WON_ADJOURNED];
const Draw = [ Result::Draw, Result::DrawAdjourned ];
const Lost = [ Result::Absent, Result::Bye, Result::Lost, Result::Adjourned ]; public const DRAW = [Result::DRAW, Result::DRAW_ADJOURNED];
const NotPlayed = [ Result::Bye, Result::WonBye, Result::Absent ];
const Played = [ Result::Won, Result::WonForfait, Result::WonBye, Result::WonAdjourned, Result::Draw, Result::DrawAdjourned, Result::Absent, Result::Bye, Result::Lost, Result::Adjourned ]; public const LOST = [Result::ABSENT, Result::BYE, Result::LOST, Result::ADJOURNED];
const Black = [ Color::Black ];
const White = [ Color::White ]; public const NOTPLAYED = [Result::BYE, Result::WON_BYE, Result::ABSENT];
public const PLAYED = [
Result::WON,
Result::WON_FORFAIT,
Result::WON_BYE,
Result::WON_ADJOURNED,
Result::DRAW,
Result::DRAW_ADJOURNED,
Result::ABSENT,
Result::BYE,
Result::LOST,
Result::ADJOURNED
];
public const BLACK = [Color::BLACK];
public const WHITE = [Color::WHITE];
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Enum Color * Enum Color
* *
@ -26,7 +27,9 @@ use MyCLabs\Enum\Enum;
*/ */
class Color extends Enum class Color extends Enum
{ {
const Black = 'B'; public const BLACK = 'B';
const White = 'W';
const None = '*'; public const NONE = '*';
public const WHITE = 'W';
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Enum Gameresult * Enum Gameresult
* *
@ -26,17 +27,29 @@ use MyCLabs\Enum\Enum;
*/ */
class Gameresult extends Enum class Gameresult extends Enum
{ {
const None = '-'; public const BLACK_WINS = '0-1';
const WhiteWins = '1-0';
const Draw = '0.5-0.5'; public const BLACK_WINS_FORFAIT = '0-1 FF';
const BlackWins = '0-1';
const WhiteWinsForfait = '1-0 FF'; public const BOTH_LOSE_FORFAIT = '0-0 FF';
const BlackWinsForfait = '0-1 FF';
const BothLoseForfait = '0-0 FF'; public const BOTH_WIN_ADJOURNED = '1-1 A';
const BothWinAdjourned = '1-1 A';
const WhiteWinsBlackDrawsAdjourned = '1-0.5 A'; public const DRAW = '0.5-0.5';
const WhiteDrawsBlackWinsAdjourned = '0.5-1 A';
const DrawAdjourned = '0.5-0.5 A'; public const DRAW_ADJOURNED = '0.5-0.5 A';
const WhiteLoseBlackDrawsAdjourned = '0-0.5';
const WhiteDrawsBlackLoseAdjourned = '0.5-0'; public const NONE = '-';
public const WHITE_DRAWS_BLACK_LOSE_ADJOURNED = '0.5-0';
public const WHITE_DRAWS_BLACK_WINS_ADJOURNED = '0.5-1 A';
public const WHITE_LOST_BLACK_DRAWS_ADJOURNED = '0-0.5';
public const WHITE_WINS = '1-0';
public const WHITE_WINS_BLACK_DRAWS_ADJOURNED = '1-0.5 A';
public const WHITE_WINS_FORFAIT = '1-0 FF';
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Enum Gender * Enum Gender
* *
@ -26,7 +27,9 @@ use MyCLabs\Enum\Enum;
*/ */
class Gender extends Enum class Gender extends Enum
{ {
const Neutral = 'X'; // Unforturnately, Incompatible with Pairtwo (Dinos) public const FEMALE = 'F';
const Male = 'M';
const Female = 'F'; public const MALE = 'M';
public const NEUTRAL = 'X'; // Unfortunately, Incompatible with Pairtwo (Dinos)
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Enum Result * Enum Result
* *
@ -26,15 +27,25 @@ use MyCLabs\Enum\Enum;
*/ */
class Result extends Enum class Result extends Enum
{ {
const None = '*'; public const ABSENT = '0 FF';
const Lost = '0';
const Draw = '0.5'; public const ADJOURNED = '0 A';
const Won = '1';
const Absent = '0 FF'; public const BYE = '0 Bye';
const WonForfait = '1 FF';
const Adjourned = '0 A'; public const DRAW = '0.5';
const DrawAdjourned = '0.5 A';
const WonAdjourned = '1 A'; public const DRAW_ADJOURNED = '0.5 A';
const Bye = '0 Bye';
const WonBye = '1 Bye'; public const LOST = '0';
public const NONE = '*';
public const WON = '1';
public const WON_ADJOURNED = '1 A';
public const WON_BYE = '1 Bye';
public const WON_FORFAIT = '1 FF';
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Enum Tiebreak * Enum Tiebreak
* *
@ -26,27 +27,49 @@ use MyCLabs\Enum\Enum;
*/ */
class Tiebreak extends Enum class Tiebreak extends Enum
{ {
const None = ""; public const ARO = "Average Rating";
const Keizer = "Keizer";
const Points = "Points"; public const AROCUT = "Average Rating Cut";
const Buchholz = "Buchholz";
const BuchholzMed = "Buchholz Median"; public const AVERAGE_PERFORMANCE = "Average performance";
const BuchholzCut = "Buchholz Cut";
const BuchholzMed2 = "Buchholz Median 2"; public const BAUMBACH = "Most wins"; // Ref: https://en.wikipedia.org/wiki/Tie-breaking_in_Swiss-system_tournaments#Most_wins_(Baumbach) Please tell me why?
const BuchholzCut2 = "Buchholz Cut 2";
const Sonneborn = "Sonneborn-Berger"; public const BETWEEN = "Mutual Result";
const Kashdan = "Kashdan";
const SoccerKashdan = "Soccer Kashdan"; public const BLACK_PLAYED = "Black played";
const Cumulative = "Cumulative";
const Between = "Mutual Result"; public const BLACK_WIN = "Black Winned";
const Koya = "Koya";
const Baumbach = "Most wins"; // Ref: https://en.wikipedia.org/wiki/Tie-breaking_in_Swiss-system_tournaments#Most_wins_(Baumbach) Please tell me why? public const BUCHHOLZ = "Buchholz";
const AveragePerformance = "Average performance";
const Performance = "Performance"; public const BUCHHOLZ_CUT = "Buchholz Cut";
const Aro = "Average Rating";
const AroCut = "Average Rating Cut"; public const BUCHHOLZ_CUT_2 = "Buchholz Cut 2";
const BlackPlayed = "Black played";
const BlackWin = "Black Winned"; public const BUCHHOLZ_MED = "Buchholz Median";
const Testmatch = "Testmatch";
const Drawing = "Drawing of lot"; public const BUCHHOLZ_MED_2 = "Buchholz Median 2";
public const CUMULATIVE = "Cumulative";
public const DRAWING_OF_LOT = "Drawing of lot";
public const KASHDAN = "Kashdan";
public const KEIZER = "Keizer";
public const KOYA = "Koya";
public const NONE = "";
public const PERFORMANCE = "Performance";
public const POINTS = "Points";
public const SOCCER_KASHDAN = "Soccer Kashdan";
public const SONNEBORN = "Sonneborn-Berger";
public const TESTMATCH = "Testmatch";
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Enum Title * Enum Title
* *
@ -26,17 +27,29 @@ use MyCLabs\Enum\Enum;
*/ */
class Title extends Enum class Title extends Enum
{ {
const NONE = '*'; public const CM = 'Candidate Master';
const ELO = 'Elo';
const NM = 'National Master'; public const ELO = 'Elo';
const WCM = 'Woman Candidate Master';
const WFM = 'Woman Fide Master'; public const FM = 'Fide Master';
const CM = 'Candidate Master';
const WIM = 'Woman International Master'; public const GM = 'Grand Master';
const FM = 'Fide Master';
const WGM = 'Woman Grand Master'; public const HG = 'Honorary Grand Master';
const HM = 'Honorary International Master';
const IM = 'International Master'; public const HM = 'Honorary International Master';
const HG = 'Honorary Grand Master';
const GM = 'Grand Master'; public const IM = 'International Master';
public const NM = 'National Master';
public const NONE = '*';
public const WCM = 'Woman Candidate Master';
public const WFM = 'Woman Fide Master';
public const WGM = 'Woman Grand Master';
public const WIM = 'Woman International Master';
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Enum TournamentSystem * Enum TournamentSystem
* *
@ -26,8 +27,11 @@ use MyCLabs\Enum\Enum;
*/ */
class TournamentSystem extends Enum class TournamentSystem extends Enum
{ {
const Swiss = 'Swiss'; public const AMERICAN = 'American';
const Closed = 'Closed';
const American = 'American'; public const CLOSED = 'Closed';
const Keizer = 'Keizer';
public const KEIZER = 'Keizer';
public const SWISS = 'Swiss';
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Exception IncompatibleReaderException * Exception IncompatibleReaderException
* *

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Exception LibpairtwoException * Exception LibpairtwoException
* *
@ -12,6 +13,8 @@
namespace JeroenED\Libpairtwo\Exceptions; namespace JeroenED\Libpairtwo\Exceptions;
use Exception;
/** /**
* Exception LibpairtwoException * Exception LibpairtwoException
* *
@ -22,6 +25,6 @@ namespace JeroenED\Libpairtwo\Exceptions;
* @package Libpairtwo * @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be> * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/ */
class LibpairtwoException extends \Exception class LibpairtwoException extends Exception
{ {
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class Games * Class Games
* *
@ -36,7 +37,7 @@ class Game
public $White; public $White;
/** /**
* The pairing for this games as seen from blacks's side * The pairing for this games as seen from black's side
* *
* @var Pairing | null * @var Pairing | null
*/ */
@ -59,6 +60,7 @@ class Game
/** /**
* Returns fields that were not directly assigned. * Returns fields that were not directly assigned.
* Class Game contains the special field Result containing the result of the game * Class Game contains the special field Result containing the result of the game
*
* @param string $key * @param string $key
* @return Gameresult * @return Gameresult
*/ */
@ -118,6 +120,6 @@ class Game
return ( return (
$this->White->Player === $game->White->Player && $this->White->Player === $game->White->Player &&
$this->Black->Player === $game->Black->Player && $this->Black->Player === $game->Black->Player &&
$this->Result == $game->Result); $this->Result->getKey() == $game->Result->getKey());
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class IOFactory * Class IOFactory
* *
@ -57,8 +58,7 @@ abstract class IOFactory
// create reader class // create reader class
$readerClass = self::$Readers[$type]; $readerClass = self::$Readers[$type];
$reader = new $readerClass;
return $reader; return new $readerClass();
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Interface ReaderInterface * Interface ReaderInterface
* *
@ -30,7 +31,7 @@ interface ReaderInterface
* Reads out $filename * Reads out $filename
* *
* @param $filename * @param $filename
* @return ReaderInterface * @return void
*/ */
public function read(string $filename): void; public function read(string $filename): void;
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class Pairing * Class Pairing
* *
@ -51,6 +52,7 @@ class Pairing
/** /**
* The result of the Game. Possible values contain Won, Lost, Draw, Forfait, Bye, etc. * The result of the Game. Possible values contain Won, Lost, Draw, Forfait, Bye, etc.
*
* @var Result * @var Result
*/ */
public $Result; public $Result;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class Player * Class Player
* *
@ -128,10 +129,14 @@ class Player
*/ */
public static function PlayersByName(string $search, Tournament $tournament): array public static function PlayersByName(string $search, Tournament $tournament): array
{ {
/** @var Player[] */ /**
* @var Player[]
*/
$players = $tournament->Players; $players = $tournament->Players;
/** @var Player[] */ /**
* @var Player[]
*/
$return = []; $return = [];
foreach ($players as $player) { foreach ($players as $player) {
@ -145,6 +150,7 @@ class Player
/** /**
* Returns the elo of elotype for the player * Returns the elo of elotype for the player
*
* @param string $type * @param string $type
* @return int * @return int
*/ */
@ -203,7 +209,7 @@ class Player
{ {
$wins = 0; $wins = 0;
foreach ($this->Pairings as $pairing) { foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::WON) !== false) {
$wins++; $wins++;
} }
} }
@ -225,9 +231,9 @@ class Player
$points = 0; $points = 0;
foreach ($this->Pairings as $key => $pairing) { foreach ($this->Pairings as $key => $pairing) {
if ($key < $round || $round == -1) { if ($key < $round || $round == -1) {
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::WON) !== false) {
$points = $points + 1; $points = $points + 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$points = $points + 0.5; $points = $points + 0.5;
} }
} }
@ -264,11 +270,11 @@ class Player
{ {
$points = 0; $points = 0;
foreach ($this->Pairings as $pairing) { foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) !== false) { if (array_search($pairing->Result, Constants::NOTPLAYED) !== false) {
$points = $points + 0.5; $points = $points + 0.5;
} elseif (array_search($pairing->Result, Constants::Won) !== false) { } elseif (array_search($pairing->Result, Constants::WON) !== false) {
$points = $points + 1; $points = $points + 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$points = $points + 0.5; $points = $points + 0.5;
} }
} }
@ -281,21 +287,21 @@ class Player
* *
* @param $type * @param $type
* @param $unratedElo * @param $unratedElo
* @return int * @return float
*/ */
public function Performance(string $type, int $unratedElo): float public function Performance(string $type, int $unratedElo): float
{ {
$total = 0; $total = 0;
$opponents = 0; $opponents = 0;
foreach ($this->Pairings as $pairing) { foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) === false) { if (array_search($pairing->Result, Constants::NOTPLAYED) === false) {
$opponentElo = $pairing->Opponent->getElo($type); $opponentElo = $pairing->Opponent->getElo($type);
$opponentElo = $opponentElo != 0 ? $opponentElo : $unratedElo; $opponentElo = $opponentElo != 0 ? $opponentElo : $unratedElo;
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::WON) !== false) {
$total += $opponentElo + 400; $total += $opponentElo + 400;
} elseif (array_search($pairing->Result, Constants::Lost) !== false) { } elseif (array_search($pairing->Result, Constants::LOST) !== false) {
$total += $opponentElo - 400; $total += $opponentElo - 400;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$total += $opponentElo; $total += $opponentElo;
} }
$opponents++; $opponents++;
@ -314,7 +320,7 @@ class Player
{ {
$total = 0; $total = 0;
foreach ($this->Pairings as $pairing) { foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::Played) !== false) { if (array_search($pairing->Result, Constants::PLAYED) !== false) {
$total++; $total++;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Reader Pairtwo6 * Reader Pairtwo6
* *
@ -10,9 +11,9 @@
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be> * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/ */
namespace JeroenED\Libpairtwo\Readers; namespace JeroenED\Libpairtwo\Readers;
use InvalidArgumentException;
use JeroenED\Libpairtwo\Enums\Color; use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Gender; use JeroenED\Libpairtwo\Enums\Gender;
use JeroenED\Libpairtwo\Enums\Result; use JeroenED\Libpairtwo\Enums\Result;
@ -39,11 +40,15 @@ use DateTime;
*/ */
class Pairtwo6 implements ReaderInterface class Pairtwo6 implements ReaderInterface
{ {
const PT_DAYFACTOR = 32; public const PT_DAYFACTOR = 32;
const PT_MONTHFACTOR = 16;
const PT_YEARFACTOR = 512; public const PT_MONTHFACTOR = 16;
const PT_PASTOFFSET = 117;
const CompatibleVersions = ['6.', '5.']; public const PT_YEARFACTOR = 512;
public const PT_PASTOFFSET = 117;
public const COMPATIBLE_VERSIONS = ['6.', '5.'];
/** /**
* Version of Pairtwo this file was created with * Version of Pairtwo this file was created with
@ -61,6 +66,7 @@ class Pairtwo6 implements ReaderInterface
/** /**
* Binary data that was read out of the pairing file * Binary data that was read out of the pairing file
*
* @var bool|DateTime|int|string[] * @var bool|DateTime|int|string[]
*/ */
private $BinaryData; private $BinaryData;
@ -109,7 +115,7 @@ class Pairtwo6 implements ReaderInterface
$this->Release = $this->readData('String', substr($swscontents, $offset, $length)); $this->Release = $this->readData('String', substr($swscontents, $offset, $length));
$offset += $length; $offset += $length;
if (array_search(substr($this->Release, 0, 2), self::CompatibleVersions) === false) { if (array_search(substr($this->Release, 0, 2), self::COMPATIBLE_VERSIONS) === false) {
throw new IncompatibleReaderException("This file was not created with Pairtwo 5 or higher"); throw new IncompatibleReaderException("This file was not created with Pairtwo 5 or higher");
} }
@ -261,53 +267,53 @@ class Pairtwo6 implements ReaderInterface
$length = 4; $length = 4;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) { switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 1: case 1:
$tiebreak = Tiebreak::Buchholz; $tiebreak = Tiebreak::BUCHHOLZ;
break; break;
case 2: case 2:
$tiebreak = Tiebreak::BuchholzMed; $tiebreak = Tiebreak::BUCHHOLZ_MED;
break; break;
case 3: case 3:
$tiebreak = Tiebreak::BuchholzCut; $tiebreak = Tiebreak::BUCHHOLZ_CUT;
break; break;
case 4: case 4:
$tiebreak = Tiebreak::Sonneborn; $tiebreak = Tiebreak::SONNEBORN;
break; break;
case 5: case 5:
$tiebreak = Tiebreak::Kashdan; $tiebreak = Tiebreak::KASHDAN;
break; break;
case 6: case 6:
$tiebreak = Tiebreak::Cumulative; $tiebreak = Tiebreak::CUMULATIVE;
break; break;
case 7: case 7:
$tiebreak = Tiebreak::Between; $tiebreak = Tiebreak::BETWEEN;
break; break;
case 8: case 8:
$tiebreak = Tiebreak::Koya; $tiebreak = Tiebreak::KOYA;
break; break;
case 9: case 9:
$tiebreak = Tiebreak::Baumbach; $tiebreak = Tiebreak::BAUMBACH;
break; break;
case 10: case 10:
$tiebreak = Tiebreak::Performance; $tiebreak = Tiebreak::PERFORMANCE;
break; break;
case 11: case 11:
$tiebreak = Tiebreak::Aro; $tiebreak = Tiebreak::ARO;
break; break;
case 12: case 12:
$tiebreak = Tiebreak::AroCut; $tiebreak = Tiebreak::AROCUT;
break; break;
case 13: case 13:
$tiebreak = Tiebreak::BlackPlayed; $tiebreak = Tiebreak::BLACK_PLAYED;
break; break;
case 14: case 14:
$tiebreak = Tiebreak::Testmatch; $tiebreak = Tiebreak::TESTMATCH;
break; break;
case 15: case 15:
$tiebreak = Tiebreak::Drawing; $tiebreak = Tiebreak::DRAWING_OF_LOT;
break; break;
case 0: case 0:
default: default:
$tiebreak = Tiebreak::None; $tiebreak = Tiebreak::NONE;
break; break;
} }
$this->Tournament->addTieBreak(new Tiebreak($tiebreak)); $this->Tournament->addTieBreak(new Tiebreak($tiebreak));
@ -447,13 +453,13 @@ class Pairtwo6 implements ReaderInterface
$length = 1; $length = 1;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) { switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 1: case 1:
$gender = Gender::Male; $gender = Gender::MALE;
break; break;
case 2: case 2:
$gender = Gender::Female; $gender = Gender::FEMALE;
break; break;
default: default:
$gender = Gender::Neutral; $gender = Gender::NEUTRAL;
break; break;
} }
$player->Gender = new Gender($gender); $player->Gender = new Gender($gender);
@ -498,12 +504,12 @@ class Pairtwo6 implements ReaderInterface
$this->Tournament->addPlayer($player); $this->Tournament->addPlayer($player);
} }
// PlayerNames // PlayerNames
$length = (Integer)$this->NewNamePos + 0; $length = (int)$this->NewNamePos + 0;
$this->PlayerNames = substr($swscontents, $offset, $length); $this->PlayerNames = substr($swscontents, $offset, $length);
$offset += $length; $offset += $length;
for ($i = 0; $i < $this->NewPlayer; $i++) { for ($i = 0; $i < $this->NewPlayer; $i++) {
$player = $this->Tournament->PlayerById($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));
@ -585,17 +591,17 @@ class Pairtwo6 implements ReaderInterface
$length = 4; $length = 4;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) { switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 2: case 2:
$system = TournamentSystem::Closed; $system = TournamentSystem::CLOSED;
break; break;
case 4: case 4:
$system = TournamentSystem::American; $system = TournamentSystem::AMERICAN;
break; break;
case 6: case 6:
$system = TournamentSystem::Keizer; $system = TournamentSystem::KEIZER;
break; break;
case 0: case 0:
default: default:
$system = TournamentSystem::Swiss; $system = TournamentSystem::SWISS;
break; break;
} }
$this->Tournament->System = new TournamentSystem($system); $this->Tournament->System = new TournamentSystem($system);
@ -651,12 +657,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->PlayerById($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->PlayerById($opponent); $pairing->Opponent = $this->Tournament->playerById($opponent);
} }
$offset += $length; $offset += $length;
@ -665,15 +671,15 @@ class Pairtwo6 implements ReaderInterface
switch ($this->readData('Int', substr($swscontents, $offset, $length))) { switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 255: case 255:
case 253: case 253:
$color = Color::Black; $color = Color::BLACK;
break; break;
case 1: case 1:
case 3: case 3:
$color = Color::White; $color = Color::WHITE;
break; break;
case 0: case 0:
default: default:
$color = Color::None; $color = Color::NONE;
break; break;
} }
$pairing->Color = new Color($color); $pairing->Color = new Color($color);
@ -682,38 +688,38 @@ class Pairtwo6 implements ReaderInterface
$length = 1; $length = 1;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) { switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 1: case 1:
$result = Result::Lost; $result = Result::LOST;
break; break;
case 2: case 2:
$result = Result::Absent; $result = Result::ABSENT;
break; break;
case 3: case 3:
$result = Result::Adjourned; $result = Result::ADJOURNED;
break; break;
case 4: case 4:
$result = Result::Bye; $result = Result::BYE;
break; break;
case 6: case 6:
$result = Result::Draw; $result = Result::DRAW;
break; break;
case 8: case 8:
$result = Result::DrawAdjourned; $result = Result::DRAW_ADJOURNED;
break; break;
case 11: case 11:
$result = Result::Won; $result = Result::WON;
break; break;
case 12: case 12:
$result = Result::WonForfait; $result = Result::WON_FORFAIT;
break; break;
case 13: case 13:
$result = Result::WonAdjourned; $result = Result::WON_ADJOURNED;
break; break;
case 14: case 14:
$result = Result::WonBye; $result = Result::WON_BYE;
break; break;
case 0: case 0:
default: default:
$result = Result::None; $result = Result::NONE;
break; break;
} }
$pairing->Result = new Result($result); $pairing->Result = new Result($result);
@ -759,7 +765,6 @@ class Pairtwo6 implements ReaderInterface
return (is_null($default)) ? '' : $default; return (is_null($default)) ? '' : $default;
} }
return iconv('windows-1252', 'utf-8', $data); return iconv('windows-1252', 'utf-8', $data);
break;
case 'Hex': case 'Hex':
case 'Int': case 'Int':
case 'Bool': case 'Bool':
@ -793,12 +798,11 @@ class Pairtwo6 implements ReaderInterface
} }
return $this->convertUIntToTimestamp(hexdec($hex)); return $this->convertUIntToTimestamp(hexdec($hex));
} elseif ($type == 'Bool') { } elseif ($type == 'Bool') {
return ($hex == "01") ? true : false; return ($hex == "01");
} }
break; break;
default: default:
throw new \InvalidArgumentException("Datatype not known"); throw new InvalidArgumentException("Datatype not known");
break;
} }
return false; return false;
@ -844,13 +848,13 @@ class Pairtwo6 implements ReaderInterface
private function addTiebreaks(): void private function addTiebreaks(): void
{ {
switch ($this->Tournament->System) { switch ($this->Tournament->System) {
case TournamentSystem::Keizer: case TournamentSystem::KEIZER:
$firstElement = new Tiebreak(Tiebreak::Keizer); $firstElement = new Tiebreak(Tiebreak::KEIZER);
break; break;
case TournamentSystem::American: case TournamentSystem::AMERICAN:
case TournamentSystem::Closed: case TournamentSystem::CLOSED:
case TournamentSystem::Swiss: case TournamentSystem::SWISS:
$firstElement = new Tiebreak(Tiebreak::Points); $firstElement = new Tiebreak(Tiebreak::POINTS);
break; break;
} }
$tiebreaks = $this->Tournament->Tiebreaks; $tiebreaks = $this->Tournament->Tiebreaks;

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Reader Swar-4 * Reader Swar-4
* *
@ -9,8 +10,10 @@
* @package Libpairtwo * @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be> * @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/ */
namespace JeroenED\Libpairtwo\Readers; namespace JeroenED\Libpairtwo\Readers;
use InvalidArgumentException;
use JeroenED\Libpairtwo\Enums\Color; use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Gender; use JeroenED\Libpairtwo\Enums\Gender;
use JeroenED\Libpairtwo\Enums\Result; use JeroenED\Libpairtwo\Enums\Result;
@ -58,10 +61,12 @@ class Swar4 implements ReaderInterface
*/ */
private $BinaryData; private $BinaryData;
/** @var array */ /**
const CompatibleVersions = ['v4.']; * @var array
*/
public const COMPATIBLE_VERSIONS = ['v4.'];
const Tempos = [ public const TEMPOS = [
[ [
'105 min/40 moves + 15 min. QPF', '105 min/40 moves + 15 min. QPF',
'120 min/40 moves + 15 min. with incr. 30" starting from 40th move', '120 min/40 moves + 15 min. with incr. 30" starting from 40th move',
@ -78,7 +83,8 @@ class Swar4 implements ReaderInterface
'90 min with incr. 30"', '90 min with incr. 30"',
'50 min with incr. 10"', '50 min with incr. 10"',
'other' 'other'
],[ ],
[
'10 min. with incr. 10"', '10 min. with incr. 10"',
'10 min. with incr. 15"', '10 min. with incr. 15"',
'10 min. with incr.5"', '10 min. with incr.5"',
@ -102,7 +108,8 @@ class Swar4 implements ReaderInterface
'45 min. QPF', '45 min. QPF',
'8 min. with incr.4"', '8 min. with incr.4"',
'other' 'other'
],[ ],
[
'3 min. with incr. 2"', '3 min. with incr. 2"',
'3 min. with incr. 3"', '3 min. with incr. 3"',
'4 min. with incr. 2"', '4 min. with incr. 2"',
@ -124,6 +131,7 @@ class Swar4 implements ReaderInterface
* Actually reads the Swar-File * Actually reads the Swar-File
* *
* @param string $filename * @param string $filename
*
* @throws IncompatibleReaderException * @throws IncompatibleReaderException
*/ */
public function read(string $filename): void public function read(string $filename): void
@ -131,7 +139,7 @@ class Swar4 implements ReaderInterface
$swshandle = fopen($filename, 'rb'); $swshandle = fopen($filename, 'rb');
$this->Release = $this->readData('String', $swshandle); $this->Release = $this->readData('String', $swshandle);
if (array_search(substr($this->Release, 0, 3), self::CompatibleVersions) === false) { if (array_search(substr($this->Release, 0, 3), self::COMPATIBLE_VERSIONS) === false) {
throw new IncompatibleReaderException("This file was not created with Swar 4"); throw new IncompatibleReaderException("This file was not created with Swar 4");
} }
@ -181,16 +189,16 @@ class Swar4 implements ReaderInterface
case 3: case 3:
case 4: case 4:
default: default:
$system = TournamentSystem::Swiss; $system = TournamentSystem::SWISS;
break; break;
case 5: case 5:
case 6: case 6:
case 7: case 7:
$system = TournamentSystem::Closed; $system = TournamentSystem::CLOSED;
break; break;
case 8: case 8:
case 9: case 9:
$system = TournamentSystem::American; $system = TournamentSystem::AMERICAN;
break; break;
} }
$this->Tournament->System = new TournamentSystem($system); $this->Tournament->System = new TournamentSystem($system);
@ -244,7 +252,7 @@ class Swar4 implements ReaderInterface
// [DATES] // [DATES]
$this->readData('String', $swshandle); $this->readData('String', $swshandle);
$this->Tournament->Tempo = Self::Tempos[$this->Tournament->TournoiStd][$this->Tournament->TempoIndex]; $this->Tournament->Tempo = self::TEMPOS[ $this->Tournament->TournoiStd ][ $this->Tournament->TempoIndex ];
for ($i = 0; $i < $this->Tournament->NoOfRounds; $i++) { for ($i = 0; $i < $this->Tournament->NoOfRounds; $i++) {
$round = new Round(); $round = new Round();
@ -261,52 +269,52 @@ class Swar4 implements ReaderInterface
switch ($this->readData('Int', $swshandle)) { switch ($this->readData('Int', $swshandle)) {
case 0: case 0:
default: default:
$tiebreak = Tiebreak::None; $tiebreak = Tiebreak::NONE;
break; break;
case 1: case 1:
$tiebreak = Tiebreak::Buchholz; $tiebreak = Tiebreak::BUCHHOLZ;
break; break;
case 2: case 2:
$tiebreak = Tiebreak::BuchholzMed; $tiebreak = Tiebreak::BUCHHOLZ_MED;
break; break;
case 3: case 3:
$tiebreak = Tiebreak::BuchholzMed2; $tiebreak = Tiebreak::BUCHHOLZ_MED_2;
break; break;
case 4: case 4:
$tiebreak = Tiebreak::BuchholzCut; $tiebreak = Tiebreak::BUCHHOLZ_CUT;
break; break;
case 5: case 5:
$tiebreak = Tiebreak::BuchholzCut2; $tiebreak = Tiebreak::BUCHHOLZ_CUT_2;
break; break;
case 6: case 6:
$tiebreak = Tiebreak::Sonneborn; $tiebreak = Tiebreak::SONNEBORN;
break; break;
case 7: case 7:
$tiebreak = Tiebreak::Cumulative; $tiebreak = Tiebreak::CUMULATIVE;
break; break;
case 8: case 8:
$tiebreak = Tiebreak::Between; $tiebreak = Tiebreak::BETWEEN;
break; break;
case 9: case 9:
$tiebreak = Tiebreak::Koya; $tiebreak = Tiebreak::KOYA;
break; break;
case 10: case 10:
$tiebreak = Tiebreak::Baumbach; $tiebreak = Tiebreak::BAUMBACH;
break; break;
case 11: case 11:
$tiebreak = Tiebreak::AveragePerformance; $tiebreak = Tiebreak::AVERAGE_PERFORMANCE;
break; break;
case 12: case 12:
$tiebreak = Tiebreak::Aro; $tiebreak = Tiebreak::ARO;
break; break;
case 13: case 13:
$tiebreak = Tiebreak::AroCut; $tiebreak = Tiebreak::AROCUT;
break; break;
case 14: case 14:
$tiebreak = Tiebreak::BlackPlayed; $tiebreak = Tiebreak::BLACK_PLAYED;
break; break;
case 15: case 15:
$tiebreak = Tiebreak::BlackWin; $tiebreak = Tiebreak::BLACK_WIN;
break; break;
} }
$tiebreaks[] = new Tiebreak($tiebreak); $tiebreaks[] = new Tiebreak($tiebreak);
@ -357,13 +365,13 @@ class Swar4 implements ReaderInterface
$player->DateOfBirth = $this->readData('Date', $swshandle); $player->DateOfBirth = $this->readData('Date', $swshandle);
switch ($this->readData('Int', $swshandle)) { switch ($this->readData('Int', $swshandle)) {
case 1: case 1:
$gender = Gender::Male; $gender = Gender::MALE;
break; break;
case 2: case 2:
$gender = Gender::Female; $gender = Gender::FEMALE;
break; break;
default: default:
$gender = Gender::Neutral; $gender = Gender::NEUTRAL;
break; break;
} }
$player->Gender = new Gender($gender); $player->Gender = new Gender($gender);
@ -453,53 +461,54 @@ class Swar4 implements ReaderInterface
while (isset($this->Tournament->Pairing[ $ptn ][ 'round' ])) { while (isset($this->Tournament->Pairing[ $ptn ][ 'round' ])) {
$pairing = new Pairing(); $pairing = new Pairing();
$pairing->Player = $this->Tournament->PlayerById($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->PlayerById($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':
$result = Result::Lost; $result = Result::LOST;
break; break;
case '01': case '01':
$result = Result::Absent; $result = Result::ABSENT;
break; break;
case '0010': case '0010':
$result = Result::Bye; $result = Result::BYE;
break; break;
case '2000': case '2000':
$result = Result::Draw; $result = Result::DRAW;
break; break;
case '4000': case '4000':
$result = Result::Won; $result = Result::WON;
break; break;
case '04': case '04':
$result = Result::WonForfait; $result = Result::WON_FORFAIT;
break; break;
case '40': case '40':
$result = Result::WonBye; $result = Result::WON_BYE;
break; break;
case '00': case '00':
default: default:
$result = Result::None; $result = Result::NONE;
break; break;
} }
if (array_search($this->Tournament->Pairing[ $ptn ][ 'table' ], [16383, 8191]) !== false) { if (array_search($this->Tournament->Pairing[ $ptn ][ 'table' ], [16383, 8191]) !== false) {
$result = Result::Absent; $result = Result::ABSENT;
} }
$pairing->Result = new Result($result); $pairing->Result = new Result($result);
switch ($this->Tournament->Pairing[ $ptn ][ 'color' ]) { switch ($this->Tournament->Pairing[ $ptn ][ 'color' ]) {
case 4294967295: case 4294967295:
$color = Color::Black; $color = Color::BLACK;
break; break;
case 1: case 1:
$color = Color::White; $color = Color::WHITE;
break; break;
case 0: case 0:
default: default:
$color = Color::None; $color = Color::NONE;
break; break;
} }
$pairing->Color = new Color($color); $pairing->Color = new Color($color);
@ -526,6 +535,7 @@ class Swar4 implements ReaderInterface
* @param string $type * @param string $type
* @param $handle * @param $handle
* @param null $default * @param null $default
*
* @return array|bool|DateTime|false|float|int|string|null * @return array|bool|DateTime|false|float|int|string|null
*/ */
private function readData(string $type, $handle, $default = null) private function readData(string $type, $handle, $default = null)
@ -542,11 +552,13 @@ class Swar4 implements ReaderInterface
if ($data == '') { if ($data == '') {
return (is_null($default)) ? '' : $default; return (is_null($default)) ? '' : $default;
} }
return iconv('windows-1252', 'utf-8', $data); return iconv('windows-1252', 'utf-8', $data);
} elseif ($type == 'Date') { } elseif ($type == 'Date') {
if ($data == '') { if ($data == '') {
return (is_null($default)) ? $this->convertStringToDate('01/01/1900') : $default; return (is_null($default)) ? $this->convertStringToDate('01/01/1900') : $default;
} }
return $this->convertStringToDate($data); return $this->convertStringToDate($data);
} }
break; break;
@ -571,19 +583,20 @@ class Swar4 implements ReaderInterface
if ($hex == '00') { if ($hex == '00') {
return (is_null($default)) ? '00' : $default; return (is_null($default)) ? '00' : $default;
} }
return $hex; return $hex;
} elseif ($type == 'Int') { } elseif ($type == 'Int') {
if ($hex == '00') { if ($hex == '00') {
return (is_null($default)) ? 0 : $default; return (is_null($default)) ? 0 : $default;
} }
return hexdec($hex); return hexdec($hex);
} elseif ($type == 'Bool') { } elseif ($type == 'Bool') {
return ($hex == "01") ? true : false; return ($hex == "01");
} }
break; break;
default: default:
throw new \InvalidArgumentException("Datatype not known"); throw new InvalidArgumentException("Datatype not known");
break;
} }
return false; return false;
@ -593,6 +606,7 @@ class Swar4 implements ReaderInterface
* Returns binary data that was read out the swar file but was not needed immediately * Returns binary data that was read out the swar file but was not needed immediately
* *
* @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)
@ -600,6 +614,7 @@ class Swar4 implements ReaderInterface
if (isset($this->BinaryData[ $key ])) { if (isset($this->BinaryData[ $key ])) {
return $this->BinaryData[ $key ]; return $this->BinaryData[ $key ];
} }
return null; return null;
} }
@ -616,7 +631,9 @@ class Swar4 implements ReaderInterface
/** /**
* Converts a swar-4 string to a \DateTime object * Converts a swar-4 string to a \DateTime object
*
* @param string $string * @param string $string
*
* @return DateTime * @return DateTime
*/ */
public function convertStringToDate(string $string): DateTime public function convertStringToDate(string $string): DateTime
@ -625,6 +642,10 @@ class Swar4 implements ReaderInterface
return DateTime::createFromFormat('d/m/Y', $string); return DateTime::createFromFormat('d/m/Y', $string);
} elseif (strlen($string) == 8) { } elseif (strlen($string) == 8) {
return DateTime::createFromFormat('Ymd', $string); return DateTime::createFromFormat('Ymd', $string);
} else {
$default = new DateTime();
$default->setTimestamp(0);
return $default;
} }
} }
@ -634,11 +655,11 @@ class Swar4 implements ReaderInterface
private function addTiebreaks(): void private function addTiebreaks(): void
{ {
switch ($this->Tournament->System) { switch ($this->Tournament->System) {
case TournamentSystem::American: case TournamentSystem::AMERICAN:
case TournamentSystem::Closed: case TournamentSystem::CLOSED:
case TournamentSystem::Swiss: case TournamentSystem::SWISS:
default: default:
$firstElement = new Tiebreak(Tiebreak::Points); $firstElement = new Tiebreak(Tiebreak::POINTS);
} }
$tiebreaks = $this->Tournament->Tiebreaks; $tiebreaks = $this->Tournament->Tiebreaks;
array_unshift($tiebreaks, $firstElement); array_unshift($tiebreaks, $firstElement);

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Class Round * Class Round
* *
@ -89,7 +90,7 @@ class Round
$allPairings = $this->Pairings; $allPairings = $this->Pairings;
$byePairings = []; $byePairings = [];
foreach ($allPairings as $pairing) { foreach ($allPairings as $pairing) {
if ($pairing->Result == Result::WonBye) { if ($pairing->Result == Result::WON_BYE) {
$byePairings[] = $pairing; $byePairings[] = $pairing;
} }
} }
@ -106,7 +107,7 @@ class Round
$allPairings = $this->Pairings; $allPairings = $this->Pairings;
$absentPairings = []; $absentPairings = [];
foreach ($allPairings as $pairing) { foreach ($allPairings as $pairing) {
if ($pairing->Result == Result::Absent) { if ($pairing->Result == Result::ABSENT) {
$absentPairings[] = $pairing; $absentPairings[] = $pairing;
} }
} }

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* The file contains the Tournament class which takes care of almost every element in your tournament * The file contains the Tournament class which takes care of almost every element in your tournament
* *
@ -38,7 +39,6 @@ class Tournament
/** /**
* Organiser of the tournament (eg. Donald J. Trump) * Organiser of the tournament (eg. Donald J. Trump)
* *
*
* @var string * @var string
*/ */
public $Organiser; public $Organiser;
@ -80,6 +80,7 @@ class Tournament
/** /**
* Start date (First round or Players meeting) of the tournament * Start date (First round or Players meeting) of the tournament
*
* @var DateTime * @var DateTime
*/ */
public $StartDate; public $StartDate;
@ -114,6 +115,7 @@ class Tournament
/** /**
* The tempo of the tournament (eg. 90 min/40 moves + 30 sec. increment starting from move 1) * The tempo of the tournament (eg. 90 min/40 moves + 30 sec. increment starting from move 1)
*
* @var string * @var string
*/ */
public $Tempo; public $Tempo;
@ -205,10 +207,10 @@ class Tournament
/** /**
* Gets a player by its ID * Gets a player by its ID
* *
* @param integer $id * @param int $id
* @return Player * @return Player
*/ */
public function PlayerById(int $id): Player public function playerById(int $id): Player
{ {
return $this->Players[$id]; return $this->Players[$id];
} }
@ -217,7 +219,6 @@ class Tournament
* Adds a player * Adds a player
* *
* @param Player $Player * @param Player $Player
*
*/ */
public function addPlayer(Player $Player): void public function addPlayer(Player $Player): void
{ {
@ -231,7 +232,6 @@ class Tournament
* *
* @param int $id * @param int $id
* @param Player $player * @param Player $player
*
*/ */
public function updatePlayer(int $id, Player $player): void public function updatePlayer(int $id, Player $player): void
{ {
@ -244,7 +244,6 @@ class Tournament
* Adds a Tiebreak * Adds a Tiebreak
* *
* @param Tiebreak $tiebreak * @param Tiebreak $tiebreak
*
*/ */
public function addTiebreak(Tiebreak $tiebreak): void public function addTiebreak(Tiebreak $tiebreak): void
{ {
@ -257,7 +256,6 @@ class Tournament
* Adds a round with given Round object * Adds a round with given Round object
* *
* @param Round $round * @param Round $round
*
*/ */
public function addRound(Round $round): void public function addRound(Round $round): void
{ {
@ -272,7 +270,7 @@ class Tournament
* @param int $roundNo * @param int $roundNo
* @return Round * @return Round
*/ */
public function RoundByNo(int $roundNo): Round public function roundByNo(int $roundNo): Round
{ {
return $this->Rounds[$roundNo]; return $this->Rounds[$roundNo];
} }
@ -281,7 +279,6 @@ class Tournament
* Adds a pairing to the tournament * Adds a pairing to the tournament
* *
* @param Pairing $pairing * @param Pairing $pairing
*
*/ */
public function addPairing(Pairing $pairing): void public function addPairing(Pairing $pairing): void
{ {
@ -295,7 +292,6 @@ class Tournament
* Adds an arbiter to the tournament * Adds an arbiter to the tournament
* *
* @param string $Arbiter * @param string $Arbiter
*
*/ */
public function addArbiter(string $Arbiter): void public function addArbiter(string $Arbiter): void
{ {
@ -306,28 +302,23 @@ class Tournament
/** /**
* Converts pairings into games with a black and white player * Converts pairings into games with a black and white player
*
*
*/ */
public function pairingsToRounds(): void public function pairingsToRounds(): void
{ {
/** @var Pairing[] $pairings */
$pairings = $this->Pairings; $pairings = $this->Pairings;
/** @var Pairing[] */ /**
* @var Pairing[]
*/
$cache = array(); $cache = array();
/** @var int[] */
$lastboards;
/** @var Pairing $pairing */
foreach ($pairings as $pairing) { foreach ($pairings as $pairing) {
// Add pairing to player // Add pairing to player
$pairing->Player->addPairing($pairing); $pairing->Player->addPairing($pairing);
$round = $pairing->Round; $round = $pairing->Round;
$color = $pairing->Color; $color = $pairing->Color;
$this->RoundByNo($round)->addPairing($pairing); $this->roundByNo($round)->addPairing($pairing);
$opponent = null; $opponent = null;
/** /**
@ -344,19 +335,17 @@ class Tournament
} }
} }
$game = new Game(); $game = new Game();
if ($color->getValue() == Color::White) { if ($color->getValue() == Color::WHITE) {
$game->White = $pairing; $game->White = $pairing;
$game->Black = $opponent; $game->Black = $opponent;
} elseif ($color->getValue() == Color::Black) { } elseif ($color->getValue() == Color::BLACK) {
$game->White = $opponent; $game->White = $opponent;
$game->Black = $pairing; $game->Black = $pairing;
} }
if (is_null($game->White) || is_null($game->Black)) { if (is_null($game->White) || is_null($game->Black)) {
$cache[] = $pairing; $cache[] = $pairing;
} else { } elseif (!$this->gameExists($game, $round)) { // Check if game already exists
// Check if game already exists
if (!$this->gameExists($game, $round)) {
$game->Board = $game->White->Board; $game->Board = $game->White->Board;
// Add board if inexistent // Add board if inexistent
if ($game->Board == -1) { if ($game->Board == -1) {
@ -373,7 +362,6 @@ class Tournament
} }
} }
} }
}
/** /**
* Checks if a game already is already registered * Checks if a game already is already registered
@ -415,7 +403,6 @@ class Tournament
* *
* @param Game $game * @param Game $game
* @param int $round * @param int $round
*
*/ */
public function addGame(Game $game, int $round): void public function addGame(Game $game, int $round): void
{ {
@ -425,7 +412,7 @@ class Tournament
$this->addRound($roundObj); $this->addRound($roundObj);
} }
$this->RoundByNo($round)->addGame($game); $this->roundByNo($round)->addGame($game);
} }
/** /**
@ -503,66 +490,46 @@ class Tournament
private function calculateTiebreak(Tiebreak $tiebreak, Player $player, int $tbkey = 0): float private function calculateTiebreak(Tiebreak $tiebreak, Player $player, int $tbkey = 0): float
{ {
switch ($tiebreak) { switch ($tiebreak) {
case Tiebreak::Keizer: case Tiebreak::KEIZER:
return $this->calculateKeizer($player); return $this->calculateKeizer($player);
break; case Tiebreak::POINTS:
case Tiebreak::Points:
return $this->calculatePoints($player); return $this->calculatePoints($player);
break; case Tiebreak::BAUMBACH:
case Tiebreak::Baumbach:
return $this->calculateBaumbach($player); return $this->calculateBaumbach($player);
break; case Tiebreak::BLACK_PLAYED:
case Tiebreak::BlackPlayed:
return $this->calculateBlackPlayed($player); return $this->calculateBlackPlayed($player);
break; case Tiebreak::BLACK_WIN:
case Tiebreak::BlackWin:
return $this->calculateBlackWin($player); return $this->calculateBlackWin($player);
break; case Tiebreak::BETWEEN:
case Tiebreak::Between:
return $this->calculateMutualResult($player, $this->Players, $tbkey); return $this->calculateMutualResult($player, $this->Players, $tbkey);
break; case Tiebreak::ARO:
case Tiebreak::Aro:
return $this->calculateAverageRating($player, $this->PriorityElo); return $this->calculateAverageRating($player, $this->PriorityElo);
break; case Tiebreak::AROCUT:
case Tiebreak::AroCut:
return $this->calculateAverageRating($player, $this->PriorityElo, 1); return $this->calculateAverageRating($player, $this->PriorityElo, 1);
break; case Tiebreak::KOYA:
case Tiebreak::Koya:
return $this->calculateKoya($player); return $this->calculateKoya($player);
break; case Tiebreak::BUCHHOLZ:
case Tiebreak::Buchholz:
return $this->calculateBuchholz($player); return $this->calculateBuchholz($player);
break; case Tiebreak::BUCHHOLZ_CUT:
case Tiebreak::BuchholzCut:
return $this->calculateBuchholz($player, 1); return $this->calculateBuchholz($player, 1);
break; case Tiebreak::BUCHHOLZ_MED:
case Tiebreak::BuchholzMed:
return $this->calculateBuchholz($player, 1, 1); return $this->calculateBuchholz($player, 1, 1);
break; case Tiebreak::BUCHHOLZ_CUT_2:
case Tiebreak::BuchholzCut2:
return $this->calculateBuchholz($player, 2); return $this->calculateBuchholz($player, 2);
break; case Tiebreak::BUCHHOLZ_MED_2:
case Tiebreak::BuchholzMed2:
return $this->calculateBuchholz($player, 2, 2); return $this->calculateBuchholz($player, 2, 2);
break; case Tiebreak::SONNEBORN:
case Tiebreak::Sonneborn:
return $this->calculateSonneborn($player); return $this->calculateSonneborn($player);
break; case Tiebreak::KASHDAN:
case Tiebreak::Kashdan:
return $this->calculateKashdan($player, ["Won" => 4, "Draw" => 2, "Lost" => 1, "NotPlayed" => 0]); return $this->calculateKashdan($player, ["Won" => 4, "Draw" => 2, "Lost" => 1, "NotPlayed" => 0]);
break; case Tiebreak::SOCCER_KASHDAN:
case Tiebreak::SoccerKashdan:
return $this->calculateKashdan($player, ["Won" => 3, "Draw" => 1, "Lost" => 0, "NotPlayed" => -1]); return $this->calculateKashdan($player, ["Won" => 3, "Draw" => 1, "Lost" => 0, "NotPlayed" => -1]);
break; case Tiebreak::CUMULATIVE:
case Tiebreak::Cumulative:
return $this->calculateCumulative($player); return $this->calculateCumulative($player);
break; case Tiebreak::AVERAGE_PERFORMANCE:
case Tiebreak::AveragePerformance:
return $this->calculateAveragePerformance($player, $this->PriorityElo); return $this->calculateAveragePerformance($player, $this->PriorityElo);
break; case Tiebreak::PERFORMANCE:
case Tiebreak::Performance:
return $player->Performance($this->PriorityElo, $this->NonRatedElo); return $player->Performance($this->PriorityElo, $this->NonRatedElo);
break;
default: default:
return 0; return 0;
} }
@ -632,8 +599,8 @@ class Tournament
{ {
$totalwins = 0; $totalwins = 0;
foreach ($player->Pairings as $pairing) { foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) === false) { if (array_search($pairing->Result, Constants::NOTPLAYED) === false) {
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::WON) !== false) {
$totalwins++; $totalwins++;
} }
} }
@ -652,7 +619,7 @@ class Tournament
{ {
$totalwins = 0; $totalwins = 0;
foreach ($player->Pairings as $pairing) { foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Color, Constants::Black) !== false) { if (array_search($pairing->Color, Constants::BLACK) !== false) {
$totalwins++; $totalwins++;
} }
} }
@ -669,7 +636,7 @@ class Tournament
{ {
$totalwins = 0; $totalwins = 0;
foreach ($player->Pairings as $pairing) { foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Color, Constants::Black) !== false && array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Color, Constants::BLACK) !== false && array_search($pairing->Result, Constants::WON) !== false) {
$totalwins++; $totalwins++;
} }
} }
@ -713,9 +680,9 @@ class Tournament
$totalmatches = 0; $totalmatches = 0;
foreach ($player->Pairings as $pairing) { foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Opponent, $interestingplayers) !== false) { if (array_search($pairing->Opponent, $interestingplayers) !== false) {
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::WON) !== false) {
$points = $points + 1; $points = $points + 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$points = $points + 0.5; $points = $points + 0.5;
} }
$totalmatches++; $totalmatches++;
@ -741,7 +708,7 @@ class Tournament
$pairings = $player->Pairings; $pairings = $player->Pairings;
$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->getElo($type); $toadd = $pairing->Opponent->getElo($type);
if ($toadd != 0) { if ($toadd != 0) {
$allratings[] = $toadd; $allratings[] = $toadd;
@ -771,7 +738,7 @@ class Tournament
$pairings = $player->Pairings; $pairings = $player->Pairings;
$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->Performance($type, $this->NonRatedElo); $toadd = $pairing->Opponent->Performance($type, $this->NonRatedElo);
if ($toadd != 0) { if ($toadd != 0) {
$allratings[] = $toadd; $allratings[] = $toadd;
@ -796,9 +763,9 @@ class Tournament
$tiebreak = 0; $tiebreak = 0;
foreach ($player->Pairings as $plkey => $plpairing) { foreach ($player->Pairings as $plkey => $plpairing) {
if (($plpairing->Opponent->calculatePoints() / count($plpairing->Opponent->Pairings) * 100) >= $cut) { if (($plpairing->Opponent->calculatePoints() / count($plpairing->Opponent->Pairings) * 100) >= $cut) {
if (array_search($plpairing->Result, Constants::Won) !== false) { if (array_search($plpairing->Result, Constants::WON) !== false) {
$tiebreak += 1; $tiebreak += 1;
} elseif (array_search($plpairing->Result, Constants::Draw) !== false) { } elseif (array_search($plpairing->Result, Constants::DRAW) !== false) {
$tiebreak += 0.5; $tiebreak += 0.5;
} }
} }
@ -809,6 +776,7 @@ class Tournament
/** /**
* The combined points of the opponents * The combined points of the opponents
*
* @param Player $player * @param Player $player
* @param int $cutlowest * @param int $cutlowest
* @param int $cuthighest * @param int $cuthighest
@ -828,21 +796,24 @@ class Tournament
$intpairings[] = $player->calculatePointsForVirtualPlayer($key); $intpairings[] = $player->calculatePointsForVirtualPlayer($key);
} else { } else {
$intpairings[] = $pairing->Opponent->calculatePointsForTiebreaks(); $intpairings[] = $pairing->Opponent->calculatePointsForTiebreaks();
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::WON) !== false) {
$curpoints += 1; $curpoints += 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$curpoints += 0.5; $curpoints += 0.5;
} }
} }
$curround++; $curround++;
} }
usort($intpairings, function ($a, $b) { usort(
$intpairings,
function ($a, $b) {
if ($b == $a) { if ($b == $a) {
return 0; return 0;
} }
return ($a > $b) ? 1 : -1; return ($a > $b) ? 1 : -1;
}); }
);
$intpairings = array_slice($intpairings, $cutlowest); $intpairings = array_slice($intpairings, $cutlowest);
$intpairings = array_slice($intpairings, 0 - $cuthighest); $intpairings = array_slice($intpairings, 0 - $cuthighest);
@ -862,13 +833,13 @@ class Tournament
$tiebreak = 0; $tiebreak = 0;
foreach ($player->Pairings as $key => $pairing) { foreach ($player->Pairings as $key => $pairing) {
if ($pairing->Opponent) { if ($pairing->Opponent) {
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::WON) !== false) {
$tiebreak += $pairing->Opponent->calculatePointsForTiebreaks(); $tiebreak += $pairing->Opponent->calculatePointsForTiebreaks();
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$tiebreak += $pairing->Opponent->calculatePointsForTiebreaks() / 2; $tiebreak += $pairing->Opponent->calculatePointsForTiebreaks() / 2;
} }
} }
if (array_search($pairing->Result, Constants::NotPlayed) !== false) { if (array_search($pairing->Result, Constants::NOTPLAYED) !== false) {
$tiebreak += $player->calculatePointsForVirtualPlayer($key); $tiebreak += $player->calculatePointsForVirtualPlayer($key);
} }
} }
@ -888,15 +859,15 @@ class Tournament
$tiebreak = 0; $tiebreak = 0;
foreach ($player->Pairings as $pairing) { foreach ($player->Pairings as $pairing) {
$toadd = 0; $toadd = 0;
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::WON) !== false) {
$toadd = $points["Won"]; $toadd = $points["Won"];
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$toadd = $points["Draw"]; $toadd = $points["Draw"];
} elseif (array_search($pairing->Result, Constants::Lost) !== false) { } elseif (array_search($pairing->Result, Constants::LOST) !== false) {
$toadd = $points["Lost"]; $toadd = $points["Lost"];
} }
if (array_search($pairing->Result, Constants::NotPlayed) !== false) { if (array_search($pairing->Result, Constants::NOTPLAYED) !== false) {
$toadd = $points["NotPlayed"]; $toadd = $points["NotPlayed"];
} }
$tiebreak += $toadd; $tiebreak += $toadd;
@ -916,9 +887,9 @@ class Tournament
$score = []; $score = [];
foreach ($player->Pairings as $pairing) { foreach ($player->Pairings as $pairing) {
$toadd = 0; $toadd = 0;
if (array_search($pairing->Result, Constants::Won) !== false) { if (array_search($pairing->Result, Constants::WON) !== false) {
$toadd = 1; $toadd = 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) { } elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$toadd = 0.5; $toadd = 0.5;
} }
$tiebreak += $toadd; $tiebreak += $toadd;