FIXES IN CODE STYLE

This commit is contained in:
Jeroen De Meerleer 2020-08-02 21:51:59 +02:00
parent c259d5178a
commit 4dbfe27e24
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="BLANK_LINES_BEFORE_RETURN_STATEMENT" value="1" />
<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="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="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" />
</PHPCodeStyleSettings>
<codeStyleSettings language="PHP">
<option name="RIGHT_MARGIN" value="120" />
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" 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_AROUND_FIELD" value="1" />
<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_BINARY_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="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_LPAREN_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_RPAREN_ON_NEXT_LINE" value="true" />
<option name="EXTENDS_LIST_WRAP" value="5" />
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
<option name="PARENTHESES_EXPRESSION_LPAREN_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="KEEP_SIMPLE_METHODS_IN_ONE_LINE" value="true" />
<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_LBRACE_ON_NEXT_LINE" value="true" />
<option name="ARRAY_INITIALIZER_RBRACE_ON_NEXT_LINE" value="true" />
<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="WHILE_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"
@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
@echo "Adding execution rights on the binaries"
@chmod +x bin/phpcs bin/phpcbf bin/phpdoc
@echo "Installation of devtools finished"
@echo "Please add $(shell echo $(PWD))/bin to your PATH"
@ -54,7 +56,7 @@ clean-repo: ## Cleans the git repository
git gc
cs: ## Fixes coding standard problems
vendor/bin/php-cs-fixer fix || true
php bin/phpcs || true
tag: ## Creates a new signed git tag
$(if $(TAG),,$(error TAG is not defined. Pass via "make tag TAG=X.X.X"))

View File

@ -1,13 +1,14 @@
<?php
/**
* Class Constants
*
* Static class for constants
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo;
@ -20,18 +21,35 @@ use JeroenED\Libpairtwo\Enums\Result;
*
* Static class for constants
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Constants
{
const Won = [ Result::Won, Result::WonForfait, Result::WonBye, Result::WonAdjourned ];
const Draw = [ Result::Draw, Result::DrawAdjourned ];
const Lost = [ Result::Absent, Result::Bye, Result::Lost, Result::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 ];
const Black = [ Color::Black ];
const White = [ Color::White ];
public const WON = [Result::WON, Result::WON_FORFAIT, Result::WON_BYE, Result::WON_ADJOURNED];
public const DRAW = [Result::DRAW, Result::DRAW_ADJOURNED];
public const LOST = [Result::ABSENT, Result::BYE, Result::LOST, Result::ADJOURNED];
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,13 +1,14 @@
<?php
/**
* Enum Color
*
* List of all compatible colors
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Enums;
@ -19,14 +20,16 @@ use MyCLabs\Enum\Enum;
*
* List of all compatible colors
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Color extends Enum
{
const Black = 'B';
const White = 'W';
const None = '*';
public const BLACK = 'B';
public const NONE = '*';
public const WHITE = 'W';
}

View File

@ -1,13 +1,14 @@
<?php
/**
* Enum Gameresult
*
* List of all compatible gameresults
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Enums;
@ -19,24 +20,36 @@ use MyCLabs\Enum\Enum;
*
* List of all compatible gameresults
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Gameresult extends Enum
{
const None = '-';
const WhiteWins = '1-0';
const Draw = '0.5-0.5';
const BlackWins = '0-1';
const WhiteWinsForfait = '1-0 FF';
const BlackWinsForfait = '0-1 FF';
const BothLoseForfait = '0-0 FF';
const BothWinAdjourned = '1-1 A';
const WhiteWinsBlackDrawsAdjourned = '1-0.5 A';
const WhiteDrawsBlackWinsAdjourned = '0.5-1 A';
const DrawAdjourned = '0.5-0.5 A';
const WhiteLoseBlackDrawsAdjourned = '0-0.5';
const WhiteDrawsBlackLoseAdjourned = '0.5-0';
public const BLACK_WINS = '0-1';
public const BLACK_WINS_FORFAIT = '0-1 FF';
public const BOTH_LOSE_FORFAIT = '0-0 FF';
public const BOTH_WIN_ADJOURNED = '1-1 A';
public const DRAW = '0.5-0.5';
public const DRAW_ADJOURNED = '0.5-0.5 A';
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,13 +1,14 @@
<?php
/**
* Enum Gender
*
* List of all compatible genders
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Enums;
@ -19,14 +20,16 @@ use MyCLabs\Enum\Enum;
*
* List of all compatible genders
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Gender extends Enum
{
const Neutral = 'X'; // Unforturnately, Incompatible with Pairtwo (Dinos)
const Male = 'M';
const Female = 'F';
public const FEMALE = 'F';
public const MALE = 'M';
public const NEUTRAL = 'X'; // Unfortunately, Incompatible with Pairtwo (Dinos)
}

View File

@ -1,13 +1,14 @@
<?php
/**
* Enum Result
*
* List of all compatible results
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Enums;
@ -19,22 +20,32 @@ use MyCLabs\Enum\Enum;
*
* List of all compatible results
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Result extends Enum
{
const None = '*';
const Lost = '0';
const Draw = '0.5';
const Won = '1';
const Absent = '0 FF';
const WonForfait = '1 FF';
const Adjourned = '0 A';
const DrawAdjourned = '0.5 A';
const WonAdjourned = '1 A';
const Bye = '0 Bye';
const WonBye = '1 Bye';
public const ABSENT = '0 FF';
public const ADJOURNED = '0 A';
public const BYE = '0 Bye';
public const DRAW = '0.5';
public const DRAW_ADJOURNED = '0.5 A';
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,13 +1,14 @@
<?php
/**
* Enum Tiebreak
*
* List of all compatible tiebreaks
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Enums;
@ -19,34 +20,56 @@ use MyCLabs\Enum\Enum;
*
* List of all compatible tiebreaks
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Tiebreak extends Enum
{
const None = "";
const Keizer = "Keizer";
const Points = "Points";
const Buchholz = "Buchholz";
const BuchholzMed = "Buchholz Median";
const BuchholzCut = "Buchholz Cut";
const BuchholzMed2 = "Buchholz Median 2";
const BuchholzCut2 = "Buchholz Cut 2";
const Sonneborn = "Sonneborn-Berger";
const Kashdan = "Kashdan";
const SoccerKashdan = "Soccer Kashdan";
const Cumulative = "Cumulative";
const Between = "Mutual Result";
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?
const AveragePerformance = "Average performance";
const Performance = "Performance";
const Aro = "Average Rating";
const AroCut = "Average Rating Cut";
const BlackPlayed = "Black played";
const BlackWin = "Black Winned";
const Testmatch = "Testmatch";
const Drawing = "Drawing of lot";
public const ARO = "Average Rating";
public const AROCUT = "Average Rating Cut";
public const AVERAGE_PERFORMANCE = "Average performance";
public 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 BETWEEN = "Mutual Result";
public const BLACK_PLAYED = "Black played";
public const BLACK_WIN = "Black Winned";
public const BUCHHOLZ = "Buchholz";
public const BUCHHOLZ_CUT = "Buchholz Cut";
public const BUCHHOLZ_CUT_2 = "Buchholz Cut 2";
public const BUCHHOLZ_MED = "Buchholz Median";
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,13 +1,14 @@
<?php
/**
* Enum Title
*
* List of all compatible titles
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Enums;
@ -19,24 +20,36 @@ use MyCLabs\Enum\Enum;
*
* List of all compatible titles
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Title extends Enum
{
const NONE = '*';
const ELO = 'Elo';
const NM = 'National Master';
const WCM = 'Woman Candidate Master';
const WFM = 'Woman Fide Master';
const CM = 'Candidate Master';
const WIM = 'Woman International Master';
const FM = 'Fide Master';
const WGM = 'Woman Grand Master';
const HM = 'Honorary International Master';
const IM = 'International Master';
const HG = 'Honorary Grand Master';
const GM = 'Grand Master';
public const CM = 'Candidate Master';
public const ELO = 'Elo';
public const FM = 'Fide Master';
public const GM = 'Grand Master';
public const HG = 'Honorary Grand Master';
public const HM = 'Honorary International 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,13 +1,14 @@
<?php
/**
* Enum TournamentSystem
*
* List of all compatible tournament systems
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Enums;
@ -19,15 +20,18 @@ use MyCLabs\Enum\Enum;
*
* List of all compatible tournament systems
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class TournamentSystem extends Enum
{
const Swiss = 'Swiss';
const Closed = 'Closed';
const American = 'American';
const Keizer = 'Keizer';
public const AMERICAN = 'American';
public const CLOSED = 'Closed';
public const KEIZER = 'Keizer';
public const SWISS = 'Swiss';
}

View File

@ -1,13 +1,14 @@
<?php
/**
* Exception IncompatibleReaderException
*
* Exception to be raised when a reader is used that is incompatible
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Exceptions;
@ -17,10 +18,10 @@ namespace JeroenED\Libpairtwo\Exceptions;
*
* Exception to be raised when a reader is used that is incompatible
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class IncompatibleReaderException extends LibpairtwoException
{

View File

@ -1,27 +1,30 @@
<?php
/**
* Exception LibpairtwoException
*
* General exception when something goes wrong with libpairtwo
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Exceptions;
use Exception;
/**
* Exception LibpairtwoException
*
* General exception when something goes wrong with libpairtwo
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class LibpairtwoException extends \Exception
class LibpairtwoException extends Exception
{
}

View File

@ -1,13 +1,14 @@
<?php
/**
* Class Games
*
* Class for a game of the tournament
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo;
@ -21,10 +22,10 @@ use DateTime;
*
* Class for a game of the tournament
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Game
{
@ -36,7 +37,7 @@ class Game
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
*/
@ -59,7 +60,8 @@ class Game
/**
* Returns fields that were not directly assigned.
* Class Game contains the special field Result containing the result of the game
* @param string $key
*
* @param string $key
* @return Gameresult
*/
public function __get(string $key)
@ -88,7 +90,7 @@ class Game
$whitesplit = explode(" ", $whiteResult);
$blacksplit = explode(" ", $blackResult);
$special='';
$special = '';
if (isset($whitesplit[1]) && $whitesplit[1] != 'Bye') {
$special = ' ' . $whitesplit[1];
}
@ -110,7 +112,7 @@ class Game
/**
* Checks if 2 games are equal
*
* @param Game $game
* @param Game $game
* @return bool
*/
public function equals(Game $game): bool
@ -118,6 +120,6 @@ class Game
return (
$this->White->Player === $game->White->Player &&
$this->Black->Player === $game->Black->Player &&
$this->Result == $game->Result);
$this->Result->getKey() == $game->Result->getKey());
}
}

View File

@ -1,13 +1,14 @@
<?php
/**
* Class IOFactory
*
* Class for creating readers for pairing files
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo;
@ -21,10 +22,10 @@ use JeroenED\Libpairtwo\Readers\Pairtwo6;
*
* Class for creating readers for pairing files
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
abstract class IOFactory
{
@ -45,7 +46,7 @@ abstract class IOFactory
*
* Compatible types are Swar-4, Pairtwo-5, Pairtwo-6
*
* @param string $type
* @param string $type
* @return ReaderInterface
* @throws LibpairtwoException
*/
@ -57,8 +58,7 @@ abstract class IOFactory
// create reader class
$readerClass = self::$Readers[$type];
$reader = new $readerClass;
return $reader;
return new $readerClass();
}
}

View File

@ -1,13 +1,14 @@
<?php
/**
* Interface ReaderInterface
*
* Sets the methods a reader needs to implement
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Interfaces;
@ -19,18 +20,18 @@ use JeroenED\Libpairtwo\Tournament;
*
* Sets the methods a reader needs to implement
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
interface ReaderInterface
{
/**
* Reads out $filename
*
* @param $filename
* @return ReaderInterface
* @param $filename
* @return void
*/
public function read(string $filename): void;
}

View File

@ -1,13 +1,14 @@
<?php
/**
* Class Pairing
*
* Class for a pairing of the tournament
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo;
@ -20,10 +21,10 @@ use JeroenED\Libpairtwo\Enums\Result;
*
* Class for a pairing of the tournament
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Pairing
{
@ -51,6 +52,7 @@ class Pairing
/**
* The result of the Game. Possible values contain Won, Lost, Draw, Forfait, Bye, etc.
*
* @var Result
*/
public $Result;

View File

@ -1,13 +1,14 @@
<?php
/**
* Class Player
*
* Class for a player of the tournament
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo;
@ -21,10 +22,10 @@ use DateTime;
*
* Class for a player of the tournament
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Player
{
@ -122,16 +123,20 @@ class Player
/**
* Returns an array of Player objects where name matches $search
*
* @param string $search
* @param Tournament $tournament
* @param string $search
* @param Tournament $tournament
* @return Player[]
*/
public static function PlayersByName(string $search, Tournament $tournament): array
{
/** @var Player[] */
/**
* @var Player[]
*/
$players = $tournament->Players;
/** @var Player[] */
/**
* @var Player[]
*/
$return = [];
foreach ($players as $player) {
@ -145,7 +150,8 @@ class Player
/**
* Returns the elo of elotype for the player
* @param string $type
*
* @param string $type
* @return int
*/
public function getElo(string $type): int
@ -157,7 +163,7 @@ class Player
* Sets the elo of elotype for the player
*
* @param string $type
* @param int $value
* @param int $value
*/
public function setElo(string $type, int $value): void
{
@ -171,7 +177,7 @@ class Player
*
* Common possible values are Fide or National
*
* @param string $type
* @param string $type
* @return string
*/
public function getId(string $type): string
@ -203,7 +209,7 @@ class Player
{
$wins = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$wins++;
}
}
@ -217,17 +223,17 @@ class Player
* 0.5 points are awarded for draw
* 0 points are awarded for loss
*
* @param int $round
* @param int $round
* @return float
*/
public function calculatePoints(int $round = -1): float
{
$points = 0;
foreach ($this->Pairings as $key=>$pairing) {
foreach ($this->Pairings as $key => $pairing) {
if ($key < $round || $round == -1) {
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$points = $points + 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$points = $points + 0.5;
}
}
@ -240,13 +246,13 @@ class Player
*
* Return the same score for all rounds until $byeround and added with a half point for each subsequent round
*
* @param int $byeround
* @param int $byeround
* @return float
*/
public function calculatePointsForVirtualPlayer(int $byeround): float
{
$points = $this->calculatePoints($byeround);
foreach (array_slice($this->Pairings, $byeround +1) as $key=>$pairing) {
foreach (array_slice($this->Pairings, $byeround + 1) as $key => $pairing) {
$points += 0.5;
}
return $points;
@ -264,11 +270,11 @@ class Player
{
$points = 0;
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;
} elseif (array_search($pairing->Result, Constants::Won) !== false) {
} elseif (array_search($pairing->Result, Constants::WON) !== false) {
$points = $points + 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$points = $points + 0.5;
}
}
@ -279,23 +285,23 @@ class Player
*
* WARNING: Calculation currently incorrect. Uses the rule of 400 as temporary solution
*
* @param $type
* @param $unratedElo
* @return int
* @param $type
* @param $unratedElo
* @return float
*/
public function Performance(string $type, int $unratedElo): float
{
$total = 0;
$opponents = 0;
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 = $opponentElo != 0 ? $opponentElo : $unratedElo;
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$total += $opponentElo + 400;
} elseif (array_search($pairing->Result, Constants::Lost) !== false) {
} elseif (array_search($pairing->Result, Constants::LOST) !== false) {
$total += $opponentElo - 400;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$total += $opponentElo;
}
$opponents++;
@ -314,7 +320,7 @@ class Player
{
$total = 0;
foreach ($this->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::Played) !== false) {
if (array_search($pairing->Result, Constants::PLAYED) !== false) {
$total++;
}
}
@ -324,7 +330,7 @@ class Player
/**
* Returns if player has played against all players of the array
*
* @param Player[] $players
* @param Player[] $players
* @return bool
*/
public function hasPlayedAllPlayersOfArray(array $players): bool
@ -362,7 +368,7 @@ class Player
/**
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
*
* @param string $key
* @param string $key
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)
@ -382,7 +388,7 @@ class Player
/**
* Sets binary data that is read out the pairing file but is not needed immediately
*
* @param string $key
* @param string $key
* @param bool|int|DateTime|string $value
*/
public function __set(string $key, $value): void

View File

@ -1,18 +1,19 @@
<?php
/**
* Reader Pairtwo6
*
* Reads out Pairtwo-6 and Pairtwo-5 files
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Readers;
use InvalidArgumentException;
use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Gender;
use JeroenED\Libpairtwo\Enums\Result;
@ -32,18 +33,22 @@ use DateTime;
*
* Reads out Pairtwo-6 files
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Pairtwo6 implements ReaderInterface
{
const PT_DAYFACTOR = 32;
const PT_MONTHFACTOR = 16;
const PT_YEARFACTOR = 512;
const PT_PASTOFFSET = 117;
const CompatibleVersions = ['6.', '5.'];
public const PT_DAYFACTOR = 32;
public const PT_MONTHFACTOR = 16;
public const PT_YEARFACTOR = 512;
public const PT_PASTOFFSET = 117;
public const COMPATIBLE_VERSIONS = ['6.', '5.'];
/**
* 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
*
* @var bool|DateTime|int|string[]
*/
private $BinaryData;
@ -68,7 +74,7 @@ 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|null
*/
public function __get(string $key)
@ -82,7 +88,7 @@ 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
*/
public function __set(string $key, $value): void
@ -93,7 +99,7 @@ class Pairtwo6 implements ReaderInterface
/**
* Actually reads the Swar-File
*
* @param string $filename
* @param string $filename
* @throws IncompatibleReaderException
*/
public function read(string $filename): void
@ -109,7 +115,7 @@ class Pairtwo6 implements ReaderInterface
$this->Release = $this->readData('String', substr($swscontents, $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");
}
@ -261,53 +267,53 @@ class Pairtwo6 implements ReaderInterface
$length = 4;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 1:
$tiebreak = Tiebreak::Buchholz;
$tiebreak = Tiebreak::BUCHHOLZ;
break;
case 2:
$tiebreak = Tiebreak::BuchholzMed;
$tiebreak = Tiebreak::BUCHHOLZ_MED;
break;
case 3:
$tiebreak = Tiebreak::BuchholzCut;
$tiebreak = Tiebreak::BUCHHOLZ_CUT;
break;
case 4:
$tiebreak = Tiebreak::Sonneborn;
$tiebreak = Tiebreak::SONNEBORN;
break;
case 5:
$tiebreak = Tiebreak::Kashdan;
$tiebreak = Tiebreak::KASHDAN;
break;
case 6:
$tiebreak = Tiebreak::Cumulative;
$tiebreak = Tiebreak::CUMULATIVE;
break;
case 7:
$tiebreak = Tiebreak::Between;
$tiebreak = Tiebreak::BETWEEN;
break;
case 8:
$tiebreak = Tiebreak::Koya;
$tiebreak = Tiebreak::KOYA;
break;
case 9:
$tiebreak = Tiebreak::Baumbach;
$tiebreak = Tiebreak::BAUMBACH;
break;
case 10:
$tiebreak = Tiebreak::Performance;
$tiebreak = Tiebreak::PERFORMANCE;
break;
case 11:
$tiebreak = Tiebreak::Aro;
$tiebreak = Tiebreak::ARO;
break;
case 12:
$tiebreak = Tiebreak::AroCut;
$tiebreak = Tiebreak::AROCUT;
break;
case 13:
$tiebreak = Tiebreak::BlackPlayed;
$tiebreak = Tiebreak::BLACK_PLAYED;
break;
case 14:
$tiebreak = Tiebreak::Testmatch;
$tiebreak = Tiebreak::TESTMATCH;
break;
case 15:
$tiebreak = Tiebreak::Drawing;
$tiebreak = Tiebreak::DRAWING_OF_LOT;
break;
case 0:
default:
$tiebreak = Tiebreak::None;
$tiebreak = Tiebreak::NONE;
break;
}
$this->Tournament->addTieBreak(new Tiebreak($tiebreak));
@ -447,13 +453,13 @@ class Pairtwo6 implements ReaderInterface
$length = 1;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 1:
$gender = Gender::Male;
$gender = Gender::MALE;
break;
case 2:
$gender = Gender::Female;
$gender = Gender::FEMALE;
break;
default:
$gender = Gender::Neutral;
$gender = Gender::NEUTRAL;
break;
}
$player->Gender = new Gender($gender);
@ -498,12 +504,12 @@ class Pairtwo6 implements ReaderInterface
$this->Tournament->addPlayer($player);
}
// PlayerNames
$length = (Integer)$this->NewNamePos + 0;
$length = (int)$this->NewNamePos + 0;
$this->PlayerNames = substr($swscontents, $offset, $length);
$offset += $length;
for ($i = 0; $i < $this->NewPlayer; $i++) {
$player = $this->Tournament->PlayerById($i);
$player = $this->Tournament->playerById($i);
$namelength = $player->NameLength;
$nameoffset = $player->NamePos;
$player->Name = $this->readData("String", substr($this->PlayerNames, $nameoffset, $namelength));
@ -585,17 +591,17 @@ class Pairtwo6 implements ReaderInterface
$length = 4;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 2:
$system = TournamentSystem::Closed;
$system = TournamentSystem::CLOSED;
break;
case 4:
$system = TournamentSystem::American;
$system = TournamentSystem::AMERICAN;
break;
case 6:
$system = TournamentSystem::Keizer;
$system = TournamentSystem::KEIZER;
break;
case 0:
default:
$system = TournamentSystem::Swiss;
$system = TournamentSystem::SWISS;
break;
}
$this->Tournament->System = new TournamentSystem($system);
@ -651,12 +657,12 @@ class Pairtwo6 implements ReaderInterface
for ($x = 0; $x < $this->CreatedRounds; $x++) {
$pairing = new Pairing();
$pairing->Player = $this->Tournament->PlayerById($i);
$pairing->Player = $this->Tournament->playerById($i);
$length = 4;
$opponent = $this->readData('Int', substr($swscontents, $offset, $length));
if ($opponent != 4294967295) {
$pairing->Opponent = $this->Tournament->PlayerById($opponent);
$pairing->Opponent = $this->Tournament->playerById($opponent);
}
$offset += $length;
@ -665,15 +671,15 @@ class Pairtwo6 implements ReaderInterface
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 255:
case 253:
$color = Color::Black;
$color = Color::BLACK;
break;
case 1:
case 3:
$color = Color::White;
break;
$color = Color::WHITE;
break;
case 0:
default:
$color = Color::None;
$color = Color::NONE;
break;
}
$pairing->Color = new Color($color);
@ -682,38 +688,38 @@ class Pairtwo6 implements ReaderInterface
$length = 1;
switch ($this->readData('Int', substr($swscontents, $offset, $length))) {
case 1:
$result = Result::Lost;
$result = Result::LOST;
break;
case 2:
$result = Result::Absent;
$result = Result::ABSENT;
break;
case 3:
$result = Result::Adjourned;
$result = Result::ADJOURNED;
break;
case 4:
$result = Result::Bye;
$result = Result::BYE;
break;
case 6:
$result = Result::Draw;
$result = Result::DRAW;
break;
case 8:
$result = Result::DrawAdjourned;
$result = Result::DRAW_ADJOURNED;
break;
case 11:
$result = Result::Won;
$result = Result::WON;
break;
case 12:
$result = Result::WonForfait;
$result = Result::WON_FORFAIT;
break;
case 13:
$result = Result::WonAdjourned;
$result = Result::WON_ADJOURNED;
break;
case 14:
$result = Result::WonBye;
$result = Result::WON_BYE;
break;
case 0:
default:
$result = Result::None;
$result = Result::NONE;
break;
}
$pairing->Result = new Result($result);
@ -745,9 +751,9 @@ class Pairtwo6 implements ReaderInterface
* * Bool (Boolean representation of $data. Default: false)
* * Date (Date representation of $data. Default: 1902/01/01)
*
* @param string $type
* @param string $data
* @param mixed $default
* @param string $type
* @param string $data
* @param mixed $default
* @return bool|DateTime|int|string
*/
private function readData(string $type, string $data, $default = null)
@ -759,7 +765,6 @@ class Pairtwo6 implements ReaderInterface
return (is_null($default)) ? '' : $default;
}
return iconv('windows-1252', 'utf-8', $data);
break;
case 'Hex':
case 'Int':
case 'Bool':
@ -793,12 +798,11 @@ class Pairtwo6 implements ReaderInterface
}
return $this->convertUIntToTimestamp(hexdec($hex));
} elseif ($type == 'Bool') {
return ($hex == "01") ? true : false;
return ($hex == "01");
}
break;
default:
throw new \InvalidArgumentException("Datatype not known");
break;
throw new InvalidArgumentException("Datatype not known");
}
return false;
@ -807,7 +811,7 @@ class Pairtwo6 implements ReaderInterface
/**
* Converts integer value to a date representation
*
* @param int $date
* @param int $date
* @return bool|DateTime
*/
private function convertUIntToTimestamp(int $date)
@ -844,13 +848,13 @@ class Pairtwo6 implements ReaderInterface
private function addTiebreaks(): void
{
switch ($this->Tournament->System) {
case TournamentSystem::Keizer:
$firstElement = new Tiebreak(Tiebreak::Keizer);
case TournamentSystem::KEIZER:
$firstElement = new Tiebreak(Tiebreak::KEIZER);
break;
case TournamentSystem::American:
case TournamentSystem::Closed:
case TournamentSystem::Swiss:
$firstElement = new Tiebreak(Tiebreak::Points);
case TournamentSystem::AMERICAN:
case TournamentSystem::CLOSED:
case TournamentSystem::SWISS:
$firstElement = new Tiebreak(Tiebreak::POINTS);
break;
}
$tiebreaks = $this->Tournament->Tiebreaks;

View File

@ -1,16 +1,19 @@
<?php
/**
* Reader Swar-4
*
* Reads out Swar-4 files
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo\Readers;
use InvalidArgumentException;
use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Gender;
use JeroenED\Libpairtwo\Enums\Result;
@ -30,10 +33,10 @@ use DateTime;
*
* Reads out Swar-4 files
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Swar4 implements ReaderInterface
{
@ -58,10 +61,12 @@ class Swar4 implements ReaderInterface
*/
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',
'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"',
'50 min with incr. 10"',
'other'
],[
],
[
'10 min. with incr. 10"',
'10 min. with incr. 15"',
'10 min. with incr.5"',
@ -102,7 +108,8 @@ class Swar4 implements ReaderInterface
'45 min. QPF',
'8 min. with incr.4"',
'other'
],[
],
[
'3 min. with incr. 2"',
'3 min. with incr. 3"',
'4 min. with incr. 2"',
@ -124,6 +131,7 @@ class Swar4 implements ReaderInterface
* Actually reads the Swar-File
*
* @param string $filename
*
* @throws IncompatibleReaderException
*/
public function read(string $filename): void
@ -131,7 +139,7 @@ class Swar4 implements ReaderInterface
$swshandle = fopen($filename, 'rb');
$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");
}
@ -181,16 +189,16 @@ class Swar4 implements ReaderInterface
case 3:
case 4:
default:
$system = TournamentSystem::Swiss;
$system = TournamentSystem::SWISS;
break;
case 5:
case 6:
case 7:
$system = TournamentSystem::Closed;
$system = TournamentSystem::CLOSED;
break;
case 8:
case 9:
$system = TournamentSystem::American;
$system = TournamentSystem::AMERICAN;
break;
}
$this->Tournament->System = new TournamentSystem($system);
@ -244,7 +252,7 @@ class Swar4 implements ReaderInterface
// [DATES]
$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++) {
$round = new Round();
@ -261,52 +269,52 @@ class Swar4 implements ReaderInterface
switch ($this->readData('Int', $swshandle)) {
case 0:
default:
$tiebreak = Tiebreak::None;
$tiebreak = Tiebreak::NONE;
break;
case 1:
$tiebreak = Tiebreak::Buchholz;
$tiebreak = Tiebreak::BUCHHOLZ;
break;
case 2:
$tiebreak = Tiebreak::BuchholzMed;
$tiebreak = Tiebreak::BUCHHOLZ_MED;
break;
case 3:
$tiebreak = Tiebreak::BuchholzMed2;
$tiebreak = Tiebreak::BUCHHOLZ_MED_2;
break;
case 4:
$tiebreak = Tiebreak::BuchholzCut;
$tiebreak = Tiebreak::BUCHHOLZ_CUT;
break;
case 5:
$tiebreak = Tiebreak::BuchholzCut2;
$tiebreak = Tiebreak::BUCHHOLZ_CUT_2;
break;
case 6:
$tiebreak = Tiebreak::Sonneborn;
$tiebreak = Tiebreak::SONNEBORN;
break;
case 7:
$tiebreak = Tiebreak::Cumulative;
$tiebreak = Tiebreak::CUMULATIVE;
break;
case 8:
$tiebreak = Tiebreak::Between;
$tiebreak = Tiebreak::BETWEEN;
break;
case 9:
$tiebreak = Tiebreak::Koya;
$tiebreak = Tiebreak::KOYA;
break;
case 10:
$tiebreak = Tiebreak::Baumbach;
$tiebreak = Tiebreak::BAUMBACH;
break;
case 11:
$tiebreak = Tiebreak::AveragePerformance;
$tiebreak = Tiebreak::AVERAGE_PERFORMANCE;
break;
case 12:
$tiebreak = Tiebreak::Aro;
$tiebreak = Tiebreak::ARO;
break;
case 13:
$tiebreak = Tiebreak::AroCut;
$tiebreak = Tiebreak::AROCUT;
break;
case 14:
$tiebreak = Tiebreak::BlackPlayed;
$tiebreak = Tiebreak::BLACK_PLAYED;
break;
case 15:
$tiebreak = Tiebreak::BlackWin;
$tiebreak = Tiebreak::BLACK_WIN;
break;
}
$tiebreaks[] = new Tiebreak($tiebreak);
@ -323,19 +331,19 @@ class Swar4 implements ReaderInterface
$this->Tournament->Catogory_type = $this->readData('Int', $swshandle);
for ($i = 0; $i <= 12; $i++) {
$category[$i]['Cat1'] =$this->readData('String', $swshandle);
$category[ $i ][ 'Cat1' ] = $this->readData('String', $swshandle);
}
for ($i = 0; $i <= 12; $i++) {
$category[$i]['Cat2'] =$this->readData('String', $swshandle);
$category[ $i ][ 'Cat2' ] = $this->readData('String', $swshandle);
}
$this->Tournament->Category = $category;
// [XTRA_POINTS]
$this->readData('String', $swshandle);
for ($i = 0; $i < 4; $i++) {
$extrapoints[$i]['pts'] = $this->readData('Int', $swshandle);
$extrapoints[$i]['elo'] = $this->readData('Int', $swshandle);
$extrapoints[ $i ][ 'pts' ] = $this->readData('Int', $swshandle);
$extrapoints[ $i ][ 'elo' ] = $this->readData('Int', $swshandle);
}
$this->Tournament->Extrapoints = $extrapoints;
@ -351,19 +359,19 @@ class Swar4 implements ReaderInterface
$player = new Player();
$player->Classement = $this->readData('Int', $swshandle);
$player->Name = $this->readData('String', $swshandle);
$inscriptionNos[$this->readData('Int', $swshandle)] = $i;
$inscriptionNos[ $this->readData('Int', $swshandle) ] = $i;
$player->Rank = $this->readData('Int', $swshandle);
$player->CatIndex = $this->readData('Int', $swshandle);
$player->DateOfBirth = $this->readData('Date', $swshandle);
switch ($this->readData('Int', $swshandle)) {
case 1:
$gender = Gender::Male;
$gender = Gender::MALE;
break;
case 2:
$gender = Gender::Female;
$gender = Gender::FEMALE;
break;
default:
$gender = Gender::Neutral;
$gender = Gender::NEUTRAL;
break;
}
$player->Gender = new Gender($gender);
@ -415,10 +423,10 @@ class Swar4 implements ReaderInterface
$player->setId('Club', $this->readData('Int', $swshandle));
$player->ClubName = $this->readData('String', $swshandle);
$player->NoOfMatchesNoBye = $this->readData('Int', $swshandle);
$player->Points = $this->readData('Int', $swshandle); // To Calculate by libpairtwo
$player->Points = $this->readData('Int', $swshandle); // To Calculate by libpairtwo
$player->AmericanPoints = $this->readData('Int', $swshandle); // To Calculate by libpairtwo
for ($t = 0; $t < 5; $t++) {
$tiebreaks[$t] = $this->readData('Int', $swshandle); // To Calculate by libpairtwo
$tiebreaks[ $t ] = $this->readData('Int', $swshandle); // To Calculate by libpairtwo
}
$player->Tiebreak = $tiebreaks;
$player->Performance = $this->readData('Int', $swshandle); // To Calculate by libpairtwo
@ -432,14 +440,14 @@ class Swar4 implements ReaderInterface
if ($player->AllocatedRounds != 0) {
for ($j = 0; $j < $player->AllocatedRounds; $j++) {
$pairing[$pt]['player'] = $i;
$pairing[$pt]['round'] = $this->readData('Int', $swshandle) - 1;
$pairing[$pt]['table'] = $this->readData('Int', $swshandle) - 1;
$pairing[$pt]['opponent'] = $this->readData('Int', $swshandle);
$pairing[$pt]['result'] = $this->readData('Hex', $swshandle);
$pairing[$pt]['color'] = $this->readData('Int', $swshandle);
$pairing[$pt]['float'] = $this->readData('Int', $swshandle);
$pairing[$pt]['extrapoints'] = $this->readData('Int', $swshandle);
$pairing[ $pt ][ 'player' ] = $i;
$pairing[ $pt ][ 'round' ] = $this->readData('Int', $swshandle) - 1;
$pairing[ $pt ][ 'table' ] = $this->readData('Int', $swshandle) - 1;
$pairing[ $pt ][ 'opponent' ] = $this->readData('Int', $swshandle);
$pairing[ $pt ][ 'result' ] = $this->readData('Hex', $swshandle);
$pairing[ $pt ][ 'color' ] = $this->readData('Int', $swshandle);
$pairing[ $pt ][ 'float' ] = $this->readData('Int', $swshandle);
$pairing[ $pt ][ 'extrapoints' ] = $this->readData('Int', $swshandle);
$pt++;
}
@ -450,61 +458,62 @@ class Swar4 implements ReaderInterface
}
$ptn = 0;
while (isset($this->Tournament->Pairing[$ptn]['round'])) {
while (isset($this->Tournament->Pairing[ $ptn ][ 'round' ])) {
$pairing = new Pairing();
$pairing->Player = $this->Tournament->PlayerById($this->Tournament->Pairing[$ptn]['player']);
$pairing->Round = $this->Tournament->Pairing[$ptn]['round'];
if ($this->Tournament->Pairing[$ptn]['opponent'] != 4294967295) {
$pairing->Opponent = $this->Tournament->PlayerById($inscriptionNos[$this->Tournament->Pairing[$ptn]['opponent']]);
$pairing->Player = $this->Tournament->playerById($this->Tournament->Pairing[ $ptn ][ 'player' ]);
$pairing->Round = $this->Tournament->Pairing[ $ptn ][ 'round' ];
if ($this->Tournament->Pairing[ $ptn ][ 'opponent' ] != 4294967295) {
$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':
$result = Result::Lost;
$result = Result::LOST;
break;
case '01':
$result = Result::Absent;
$result = Result::ABSENT;
break;
case '0010':
$result = Result::Bye;
$result = Result::BYE;
break;
case '2000':
$result = Result::Draw;
$result = Result::DRAW;
break;
case '4000':
$result = Result::Won;
$result = Result::WON;
break;
case '04':
$result = Result::WonForfait;
$result = Result::WON_FORFAIT;
break;
case '40':
$result = Result::WonBye;
$result = Result::WON_BYE;
break;
case '00':
default:
$result = Result::None;
$result = Result::NONE;
break;
}
if (array_search($this->Tournament->Pairing[$ptn]['table'], [ 16383, 8191 ]) !== false) {
$result = Result::Absent;
if (array_search($this->Tournament->Pairing[ $ptn ][ 'table' ], [16383, 8191]) !== false) {
$result = Result::ABSENT;
}
$pairing->Result = new Result($result);
switch ($this->Tournament->Pairing[$ptn]['color']) {
switch ($this->Tournament->Pairing[ $ptn ][ 'color' ]) {
case 4294967295:
$color = Color::Black;
$color = Color::BLACK;
break;
case 1:
$color = Color::White;
$color = Color::WHITE;
break;
case 0:
default:
$color = Color::None;
$color = Color::NONE;
break;
}
$pairing->Color = new Color($color);
$pairing->Board = $this->Tournament->Pairing[$ptn]['table'];
$pairing->Board = $this->Tournament->Pairing[ $ptn ][ 'table' ];
$ptn++;
$this->Tournament->addPairing($pairing);
}
@ -525,7 +534,8 @@ class Swar4 implements ReaderInterface
*
* @param string $type
* @param $handle
* @param null $default
* @param null $default
*
* @return array|bool|DateTime|false|float|int|string|null
*/
private function readData(string $type, $handle, $default = null)
@ -542,11 +552,13 @@ class Swar4 implements ReaderInterface
if ($data == '') {
return (is_null($default)) ? '' : $default;
}
return iconv('windows-1252', 'utf-8', $data);
} elseif ($type == 'Date') {
if ($data == '') {
return (is_null($default)) ? $this->convertStringToDate('01/01/1900') : $default;
}
return $this->convertStringToDate($data);
}
break;
@ -559,7 +571,7 @@ class Swar4 implements ReaderInterface
foreach ($hex as $key => $item) {
if ($item == "00") {
$hex[$key] = "";
$hex[ $key ] = "";
} else {
break;
}
@ -571,19 +583,20 @@ class Swar4 implements ReaderInterface
if ($hex == '00') {
return (is_null($default)) ? '00' : $default;
}
return $hex;
} elseif ($type == 'Int') {
if ($hex == '00') {
return (is_null($default)) ? 0 : $default;
}
return hexdec($hex);
} elseif ($type == 'Bool') {
return ($hex == "01") ? true : false;
return ($hex == "01");
}
break;
default:
throw new \InvalidArgumentException("Datatype not known");
break;
throw new InvalidArgumentException("Datatype not known");
}
return false;
@ -593,30 +606,34 @@ class Swar4 implements ReaderInterface
* Returns binary data that was read out the swar file but was not needed immediately
*
* @param string $key
*
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)
{
if (isset($this->BinaryData[$key])) {
return $this->BinaryData[$key];
if (isset($this->BinaryData[ $key ])) {
return $this->BinaryData[ $key ];
}
return null;
}
/**
* Sets binary data that is read out the swar file but is not needed immediately
*
* @param string $key
* @param string $key
* @param bool|int|DateTime|string $value
*/
public function __set(string $key, $value): void
{
$this->BinaryData[$key] = $value;
$this->BinaryData[ $key ] = $value;
}
/**
* Converts a swar-4 string to a \DateTime object
*
* @param string $string
*
* @return DateTime
*/
public function convertStringToDate(string $string): DateTime
@ -625,6 +642,10 @@ class Swar4 implements ReaderInterface
return DateTime::createFromFormat('d/m/Y', $string);
} elseif (strlen($string) == 8) {
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
{
switch ($this->Tournament->System) {
case TournamentSystem::American:
case TournamentSystem::Closed:
case TournamentSystem::Swiss:
case TournamentSystem::AMERICAN:
case TournamentSystem::CLOSED:
case TournamentSystem::SWISS:
default:
$firstElement = new Tiebreak(Tiebreak::Points);
$firstElement = new Tiebreak(Tiebreak::POINTS);
}
$tiebreaks = $this->Tournament->Tiebreaks;
array_unshift($tiebreaks, $firstElement);

View File

@ -1,13 +1,14 @@
<?php
/**
* Class Round
*
* Class for a round of the tournament
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo;
@ -20,10 +21,10 @@ use JeroenED\Libpairtwo\Enums\Result;
*
* Class for a round of the tournament
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Round
{
@ -89,7 +90,7 @@ class Round
$allPairings = $this->Pairings;
$byePairings = [];
foreach ($allPairings as $pairing) {
if ($pairing->Result == Result::WonBye) {
if ($pairing->Result == Result::WON_BYE) {
$byePairings[] = $pairing;
}
}
@ -106,7 +107,7 @@ class Round
$allPairings = $this->Pairings;
$absentPairings = [];
foreach ($allPairings as $pairing) {
if ($pairing->Result == Result::Absent) {
if ($pairing->Result == Result::ABSENT) {
$absentPairings[] = $pairing;
}
}
@ -128,8 +129,8 @@ class Round
/**
* Sort by board
*
* @param Game $a
* @param Game $b
* @param Game $a
* @param Game $b
* @return int
*/
private function sortByBoard(Game $a, Game $b): int
@ -143,7 +144,7 @@ class Round
/**
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
*
* @param string $key
* @param string $key
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)

View File

@ -1,11 +1,12 @@
<?php
/**
* The file contains the Tournament class which takes care of almost every element in your tournament
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
namespace JeroenED\Libpairtwo;
@ -21,10 +22,10 @@ use DateTime;
*
* Class for the tournament from the pairing file
*
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
* @author Jeroen De Meerleer <schaak@jeroened.be>
* @category Main
* @package Libpairtwo
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
*/
class Tournament
{
@ -38,7 +39,6 @@ class Tournament
/**
* Organiser of the tournament (eg. Donald J. Trump)
*
*
* @var string
*/
public $Organiser;
@ -80,6 +80,7 @@ class Tournament
/**
* Start date (First round or Players meeting) of the tournament
*
* @var DateTime
*/
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)
*
* @var string
*/
public $Tempo;
@ -205,10 +207,10 @@ class Tournament
/**
* Gets a player by its ID
*
* @param integer $id
* @param int $id
* @return Player
*/
public function PlayerById(int $id): Player
public function playerById(int $id): Player
{
return $this->Players[$id];
}
@ -217,7 +219,6 @@ class Tournament
* Adds a player
*
* @param Player $Player
*
*/
public function addPlayer(Player $Player): void
{
@ -229,9 +230,8 @@ class Tournament
/**
* Updates player on id to the given Player object
*
* @param int $id
* @param int $id
* @param Player $player
*
*/
public function updatePlayer(int $id, Player $player): void
{
@ -244,7 +244,6 @@ class Tournament
* Adds a Tiebreak
*
* @param Tiebreak $tiebreak
*
*/
public function addTiebreak(Tiebreak $tiebreak): void
{
@ -257,7 +256,6 @@ class Tournament
* Adds a round with given Round object
*
* @param Round $round
*
*/
public function addRound(Round $round): void
{
@ -269,10 +267,10 @@ class Tournament
/**
* Gets a round by its number.
*
* @param int $roundNo
* @param int $roundNo
* @return Round
*/
public function RoundByNo(int $roundNo): Round
public function roundByNo(int $roundNo): Round
{
return $this->Rounds[$roundNo];
}
@ -281,7 +279,6 @@ class Tournament
* Adds a pairing to the tournament
*
* @param Pairing $pairing
*
*/
public function addPairing(Pairing $pairing): void
{
@ -295,7 +292,6 @@ class Tournament
* Adds an arbiter to the tournament
*
* @param string $Arbiter
*
*/
public function addArbiter(string $Arbiter): void
{
@ -306,35 +302,30 @@ class Tournament
/**
* Converts pairings into games with a black and white player
*
*
*/
public function pairingsToRounds(): void
{
/** @var Pairing[] $pairings */
$pairings = $this->Pairings;
/** @var Pairing[] */
/**
* @var Pairing[]
*/
$cache = array();
/** @var int[] */
$lastboards;
/** @var Pairing $pairing */
foreach ($pairings as $pairing) {
// Add pairing to player
$pairing->Player->addPairing($pairing);
$round = $pairing->Round;
$color = $pairing->Color;
$this->RoundByNo($round)->addPairing($pairing);
$this->roundByNo($round)->addPairing($pairing);
$opponent = null;
/**
* @var int $key
* @var Pairing $cached
*/
foreach ($cache as $key=>$cached) {
foreach ($cache as $key => $cached) {
if (!is_null($cached)) {
if (($cached->Opponent == $pairing->Player) && ($cached->Round == $pairing->Round)) {
$opponent = $cached;
@ -344,33 +335,30 @@ class Tournament
}
}
$game = new Game();
if ($color->getValue() == Color::White) {
if ($color->getValue() == Color::WHITE) {
$game->White = $pairing;
$game->Black = $opponent;
} elseif ($color->getValue() == Color::Black) {
} elseif ($color->getValue() == Color::BLACK) {
$game->White = $opponent;
$game->Black = $pairing;
}
if (is_null($game->White) || is_null($game->Black)) {
$cache[] = $pairing;
} else {
// Check if game already exists
if (!$this->gameExists($game, $round)) {
$game->Board = $game->White->Board;
// Add board if inexistent
if ($game->Board == -1) {
if (isset($lastboards[$round])) {
$lastboards[$round] += 1;
} else {
$lastboards[$round] = 0;
}
$game->Board = $lastboards[$round];
$game->White->Board = $lastboards[$round];
$game->Black->Board = $lastboards[$round];
} elseif (!$this->gameExists($game, $round)) { // Check if game already exists
$game->Board = $game->White->Board;
// Add board if inexistent
if ($game->Board == -1) {
if (isset($lastboards[$round])) {
$lastboards[$round] += 1;
} else {
$lastboards[$round] = 0;
}
$this->AddGame($game, $round);
$game->Board = $lastboards[$round];
$game->White->Board = $lastboards[$round];
$game->Black->Board = $lastboards[$round];
}
$this->AddGame($game, $round);
}
}
}
@ -378,8 +366,8 @@ class Tournament
/**
* Checks if a game already is already registered
*
* @param Game $game
* @param int $round
* @param Game $game
* @param int $round
* @return bool
*/
public function gameExists(Game $game, int $round = -1): bool
@ -414,8 +402,7 @@ class Tournament
* Adds a game to the tournament
*
* @param Game $game
* @param int $round
*
* @param int $round
*/
public function addGame(Game $game, int $round): void
{
@ -425,7 +412,7 @@ class Tournament
$this->addRound($roundObj);
}
$this->RoundByNo($round)->addGame($game);
$this->roundByNo($round)->addGame($game);
}
/**
@ -436,7 +423,7 @@ class Tournament
private function ranking(): array
{
$players = $this->Players;
foreach ($this->Tiebreaks as $tbkey=>$tiebreak) {
foreach ($this->Tiebreaks as $tbkey => $tiebreak) {
foreach ($players as $pkey => $player) {
$break = $this->calculateTiebreak($tiebreak, $player, $tbkey);
$tiebreaks = $player->Tiebreaks;
@ -446,11 +433,11 @@ class Tournament
}
}
$sortedplayers[0] = $players;
foreach ($this->Tiebreaks as $tbkey=>$tiebreak) {
foreach ($this->Tiebreaks as $tbkey => $tiebreak) {
$newgroupkey = 0;
$tosortplayers = $sortedplayers;
$sortedplayers = [];
foreach ($tosortplayers as $groupkey=>$sortedplayerselem) {
foreach ($tosortplayers as $groupkey => $sortedplayerselem) {
usort($tosortplayers[$groupkey], $this->sortTiebreak($tbkey));
foreach ($tosortplayers[$groupkey] as $playerkey => $player) {
if (!is_null($player->Tiebreaks[$tbkey])) {
@ -478,7 +465,7 @@ class Tournament
/**
* Sort by tiebreak
*
* @param int $key
* @param int $key
* @return Closure
*/
private function sortTiebreak(int $key): Closure
@ -495,74 +482,54 @@ class Tournament
/**
* Calculates a specific tiebreak for $player
*
* @param Tiebreak $tiebreak
* @param Player $player
* @param int $tbkey
* @param Tiebreak $tiebreak
* @param Player $player
* @param int $tbkey
* @return float
*/
private function calculateTiebreak(Tiebreak $tiebreak, Player $player, int $tbkey = 0): float
{
switch ($tiebreak) {
case Tiebreak::Keizer:
case Tiebreak::KEIZER:
return $this->calculateKeizer($player);
break;
case Tiebreak::Points:
case Tiebreak::POINTS:
return $this->calculatePoints($player);
break;
case Tiebreak::Baumbach:
case Tiebreak::BAUMBACH:
return $this->calculateBaumbach($player);
break;
case Tiebreak::BlackPlayed:
case Tiebreak::BLACK_PLAYED:
return $this->calculateBlackPlayed($player);
break;
case Tiebreak::BlackWin:
case Tiebreak::BLACK_WIN:
return $this->calculateBlackWin($player);
break;
case Tiebreak::Between:
case Tiebreak::BETWEEN:
return $this->calculateMutualResult($player, $this->Players, $tbkey);
break;
case Tiebreak::Aro:
case Tiebreak::ARO:
return $this->calculateAverageRating($player, $this->PriorityElo);
break;
case Tiebreak::AroCut:
case Tiebreak::AROCUT:
return $this->calculateAverageRating($player, $this->PriorityElo, 1);
break;
case Tiebreak::Koya:
case Tiebreak::KOYA:
return $this->calculateKoya($player);
break;
case Tiebreak::Buchholz:
case Tiebreak::BUCHHOLZ:
return $this->calculateBuchholz($player);
break;
case Tiebreak::BuchholzCut:
case Tiebreak::BUCHHOLZ_CUT:
return $this->calculateBuchholz($player, 1);
break;
case Tiebreak::BuchholzMed:
case Tiebreak::BUCHHOLZ_MED:
return $this->calculateBuchholz($player, 1, 1);
break;
case Tiebreak::BuchholzCut2:
case Tiebreak::BUCHHOLZ_CUT_2:
return $this->calculateBuchholz($player, 2);
break;
case Tiebreak::BuchholzMed2:
case Tiebreak::BUCHHOLZ_MED_2:
return $this->calculateBuchholz($player, 2, 2);
break;
case Tiebreak::Sonneborn:
case Tiebreak::SONNEBORN:
return $this->calculateSonneborn($player);
break;
case Tiebreak::Kashdan:
case Tiebreak::KASHDAN:
return $this->calculateKashdan($player, ["Won" => 4, "Draw" => 2, "Lost" => 1, "NotPlayed" => 0]);
break;
case Tiebreak::SoccerKashdan:
case Tiebreak::SOCCER_KASHDAN:
return $this->calculateKashdan($player, ["Won" => 3, "Draw" => 1, "Lost" => 0, "NotPlayed" => -1]);
break;
case Tiebreak::Cumulative:
case Tiebreak::CUMULATIVE:
return $this->calculateCumulative($player);
break;
case Tiebreak::AveragePerformance:
case Tiebreak::AVERAGE_PERFORMANCE:
return $this->calculateAveragePerformance($player, $this->PriorityElo);
break;
case Tiebreak::Performance:
case Tiebreak::PERFORMANCE:
return $player->Performance($this->PriorityElo, $this->NonRatedElo);
break;
default:
return 0;
}
@ -602,7 +569,7 @@ class Tournament
/**
* Points following keizer system
*
* @param Player $player
* @param Player $player
* @return float
*/
private function calculateKeizer(Player $player): float
@ -613,7 +580,7 @@ class Tournament
/**
* Number of points
*
* @param Player $player
* @param Player $player
* @return float
*/
private function calculatePoints(Player $player): float
@ -625,15 +592,15 @@ class Tournament
/**
* Number of won games
*
* @param Player $player
* @param Player $player
* @return float
*/
private function calculateBaumbach(Player $player): float
{
$totalwins = 0;
foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Result, Constants::NotPlayed) === false) {
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) === false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$totalwins++;
}
}
@ -645,14 +612,14 @@ class Tournament
/**
* Number of played games with black
*
* @param Player $player
* @param Player $player
* @return float
*/
private function calculateBlackPlayed(Player $player): float
{
$totalwins = 0;
foreach ($player->Pairings as $pairing) {
if (array_search($pairing->Color, Constants::Black) !== false) {
if (array_search($pairing->Color, Constants::BLACK) !== false) {
$totalwins++;
}
}
@ -662,14 +629,14 @@ class Tournament
/**
* Number of won games with black
*
* @param Player $player
* @param Player $player
* @return float
*/
private function calculateBlackWin(Player $player): float
{
$totalwins = 0;
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++;
}
}
@ -680,9 +647,9 @@ class Tournament
/**
* Result between the tied players
*
* @param Player $player
* @param array $opponents
* @param int $key
* @param Player $player
* @param array $opponents
* @param int $key
* @return float
*/
private function calculateMutualResult(Player $player, array $opponents, int $key): float
@ -713,9 +680,9 @@ class Tournament
$totalmatches = 0;
foreach ($player->Pairings as $pairing) {
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;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$points = $points + 0.5;
}
$totalmatches++;
@ -731,9 +698,9 @@ class Tournament
/**
* The average rating of the opponents
*
* @param Player $player
* @param string $type
* @param int $cut
* @param Player $player
* @param string $type
* @param int $cut
* @return float
*/
private function calculateAverageRating(Player $player, string $type, int $cut = 0): float
@ -741,7 +708,7 @@ class Tournament
$pairings = $player->Pairings;
$allratings = [];
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);
if ($toadd != 0) {
$allratings[] = $toadd;
@ -761,9 +728,9 @@ class Tournament
/**
* The average performance of the opponents
*
* @param Player $player
* @param string $type
* @param int $cut
* @param Player $player
* @param string $type
* @param int $cut
* @return float
*/
private function calculateAveragePerformance(Player $player, string $type, int $cut = 0): float
@ -771,7 +738,7 @@ class Tournament
$pairings = $player->Pairings;
$allratings = [];
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);
if ($toadd != 0) {
$allratings[] = $toadd;
@ -787,8 +754,8 @@ class Tournament
/**
* Points against players who have more than $cut % points
*
* @param Player $player
* @param int $cut
* @param Player $player
* @param int $cut
* @return float
*/
private function calculateKoya(Player $player, int $cut = 50): float
@ -796,9 +763,9 @@ class Tournament
$tiebreak = 0;
foreach ($player->Pairings as $plkey => $plpairing) {
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;
} elseif (array_search($plpairing->Result, Constants::Draw) !== false) {
} elseif (array_search($plpairing->Result, Constants::DRAW) !== false) {
$tiebreak += 0.5;
}
}
@ -809,9 +776,10 @@ class Tournament
/**
* The combined points of the opponents
* @param Player $player
* @param int $cutlowest
* @param int $cuthighest
*
* @param Player $player
* @param int $cutlowest
* @param int $cuthighest
* @return float
*/
private function calculateBuchholz(Player $player, int $cutlowest = 0, int $cuthighest = 0): float
@ -822,27 +790,30 @@ class Tournament
$intpairings = [];
$curpoints = 0;
$curround = 1;
foreach ($intpairingsWithBye as $key=>$pairing) {
foreach ($intpairingsWithBye as $key => $pairing) {
$roundstoplay = (count($intpairingsWithBye)) - $curround;
if (is_null($pairing->Opponent)) {
$intpairings[] = $player->calculatePointsForVirtualPlayer($key);
} else {
$intpairings[] = $pairing->Opponent->calculatePointsForTiebreaks();
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$curpoints += 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$curpoints += 0.5;
}
}
$curround++;
}
usort($intpairings, function ($a, $b) {
if ($b == $a) {
return 0;
usort(
$intpairings,
function ($a, $b) {
if ($b == $a) {
return 0;
}
return ($a > $b) ? 1 : -1;
}
return ($a > $b) ? 1 : -1;
});
);
$intpairings = array_slice($intpairings, $cutlowest);
$intpairings = array_slice($intpairings, 0 - $cuthighest);
@ -854,7 +825,7 @@ 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
*/
private function calculateSonneborn(Player $player): float
@ -862,13 +833,13 @@ class Tournament
$tiebreak = 0;
foreach ($player->Pairings as $key => $pairing) {
if ($pairing->Opponent) {
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$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;
}
}
if (array_search($pairing->Result, Constants::NotPlayed) !== false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) !== false) {
$tiebreak += $player->calculatePointsForVirtualPlayer($key);
}
}
@ -879,8 +850,8 @@ class Tournament
/**
* $points["Won"] points for each win, $points["Draw"] for each draw and $points["Lost"] point for losing. $points["NotPlayed"] points for not played games
*
* @param Player $player
* @param int[] $points
* @param Player $player
* @param int[] $points
* @return float
*/
private function calculateKashdan(Player $player, array $points): float
@ -888,15 +859,15 @@ class Tournament
$tiebreak = 0;
foreach ($player->Pairings as $pairing) {
$toadd = 0;
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$toadd = $points["Won"];
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$toadd = $points["Draw"];
} elseif (array_search($pairing->Result, Constants::Lost) !== false) {
} elseif (array_search($pairing->Result, Constants::LOST) !== false) {
$toadd = $points["Lost"];
}
if (array_search($pairing->Result, Constants::NotPlayed) !== false) {
if (array_search($pairing->Result, Constants::NOTPLAYED) !== false) {
$toadd = $points["NotPlayed"];
}
$tiebreak += $toadd;
@ -907,7 +878,7 @@ class Tournament
/**
* Combined score of $player after each round
*
* @param Player $player
* @param Player $player
* @return float
*/
private function calculateCumulative(Player $player): float
@ -916,9 +887,9 @@ class Tournament
$score = [];
foreach ($player->Pairings as $pairing) {
$toadd = 0;
if (array_search($pairing->Result, Constants::Won) !== false) {
if (array_search($pairing->Result, Constants::WON) !== false) {
$toadd = 1;
} elseif (array_search($pairing->Result, Constants::Draw) !== false) {
} elseif (array_search($pairing->Result, Constants::DRAW) !== false) {
$toadd = 0.5;
}
$tiebreak += $toadd;
@ -930,7 +901,7 @@ class Tournament
/**
* Magic method to read out several fields. If field was not found it is being searched in the binary data fields
*
* @param string $key
* @param string $key
* @return bool|DateTime|int|string|null
*/
public function __get(string $key)
@ -950,8 +921,8 @@ class Tournament
/**
* Sets binary data that is read out the pairing file but is not needed immediately
*
* @param string $key
* @param bool|int|DateTime|string $value
* @param string $key
* @param bool|int|DateTime|string $value
* @return void
*/
public function __set(string $key, $value): void