Class fields fixup

Beware of breaking change with own readers!!
AllFieldsAreNowPascalCased
This commit is contained in:
Jeroen De Meerleer 2019-09-28 20:31:38 +02:00
parent 1fbd910ffb
commit db9c205bd1
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
9 changed files with 97 additions and 97 deletions

View File

@ -27,11 +27,11 @@ use JeroenED\Libpairtwo\Enums\Result;
*/ */
class Constants class Constants
{ {
const Won = [ Result::won, Result::wonforfait, Result::wonbye, Result::wonadjourned ]; const Won = [ Result::Won, Result::WonForfait, Result::WonBye, Result::WonAdjourned ];
const Draw = [ Result::draw, Result::drawadjourned ]; const Draw = [ Result::Draw, Result::DrawAdjourned ];
const Lost = [ Result::absent, Result::bye, Result::lost, Result::adjourned ]; const Lost = [ Result::Absent, Result::Bye, Result::Lost, Result::Adjourned ];
const NotPlayed = [ Result::bye, Result::wonbye, Result::absent ]; 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 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 Black = [ Color::Black ];
const White = [ Color::white ]; const White = [ Color::White ];
} }

View File

@ -26,7 +26,7 @@ use MyCLabs\Enum\Enum;
*/ */
class Color extends Enum class Color extends Enum
{ {
const black = 'B'; const Black = 'B';
const white = 'W'; const White = 'W';
const none = '*'; const None = '*';
} }

View File

@ -26,15 +26,15 @@ use MyCLabs\Enum\Enum;
*/ */
class Result extends Enum class Result extends Enum
{ {
const none = '*'; const None = '*';
const lost = '0'; const Lost = '0';
const draw = '0.5'; const Draw = '0.5';
const won = '1'; const Won = '1';
const absent = '0 FF'; const Absent = '0 FF';
const wonforfait = '1 FF'; const WonForfait = '1 FF';
const adjourned = '0 A'; const Adjourned = '0 A';
const drawadjourned = '0.5 A'; const DrawAdjourned = '0.5 A';
const wonadjourned = '1 A'; const WonAdjourned = '1 A';
const bye = '0 Bye'; const Bye = '0 Bye';
const wonbye = '1 Bye'; const WonBye = '1 Bye';
} }

View File

@ -29,13 +29,13 @@ use DateTime;
class Game class Game
{ {
/** @var Pairing | null */ /** @var Pairing | null */
private $white; private $White;
/** @var Pairing | null */ /** @var Pairing | null */
private $black; private $Black;
/** @var GameResult | null */ /** @var GameResult | null */
private $result; private $Result;
/** @var int */ /** @var int */
private $Board; private $Board;
@ -47,8 +47,8 @@ class Game
*/ */
public function getResult(): Gameresult public function getResult(): Gameresult
{ {
if (!is_null($this->result)) { if (!is_null($this->Result)) {
return $this->result; return $this->Result;
} }
$whiteResult = $this->getWhite()->getResult(); $whiteResult = $this->getWhite()->getResult();
@ -83,18 +83,18 @@ class Game
*/ */
public function getWhite(): ?Pairing public function getWhite(): ?Pairing
{ {
return $this->white; return $this->White;
} }
/** /**
* Sets pairing for white player * Sets pairing for white player
* *
* @param Pairing | null $white * @param Pairing | null $White
* @return Game * @return Game
*/ */
public function setWhite(?Pairing $white): Game public function setWhite(?Pairing $White): Game
{ {
$this->white = $white; $this->White = $White;
return $this; return $this;
} }
@ -105,30 +105,30 @@ class Game
*/ */
public function getBlack(): ?Pairing public function getBlack(): ?Pairing
{ {
return $this->black; return $this->Black;
} }
/** /**
* Sets pairing for black player * Sets pairing for black player
* *
* @param Pairing | null $black * @param Pairing | null $Black
* @return Game * @return Game
*/ */
public function setBlack(?Pairing $black): Game public function setBlack(?Pairing $Black): Game
{ {
$this->black = $black; $this->Black = $Black;
return $this; return $this;
} }
/** /**
* Sets result for game * Sets result for game
* *
* @param Gameresult | null $result * @param Gameresult | null $Result
* @return Game * @return Game
*/ */
public function setResult(?Gameresult $result): Game public function setResult(?Gameresult $Result): Game
{ {
$this->result = $result; $this->Result = $Result;
return $this; return $this;
} }

View File

@ -33,7 +33,7 @@ abstract class IOFactory
* *
* @var array * @var array
*/ */
private static $readers = [ private static $Readers = [
'Swar-4' => Readers\Swar4::class, 'Swar-4' => Readers\Swar4::class,
'Pairtwo-6' => Readers\Pairtwo6::class, 'Pairtwo-6' => Readers\Pairtwo6::class,
'Pairtwo-5' => Readers\Pairtwo6::class // File structure identical 'Pairtwo-5' => Readers\Pairtwo6::class // File structure identical
@ -51,12 +51,12 @@ abstract class IOFactory
*/ */
public static function createReader(string $type): ReaderInterface public static function createReader(string $type): ReaderInterface
{ {
if (!isset(self::$readers[$type])) { if (!isset(self::$Readers[$type])) {
throw new LibpairtwoException("Cannot read type $type"); throw new LibpairtwoException("Cannot read type $type");
} }
// create reader class // create reader class
$readerClass = self::$readers[$type]; $readerClass = self::$Readers[$type];
$reader = new $readerClass; $reader = new $readerClass;
return $reader; return $reader;

View File

@ -703,15 +703,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->setColor(new Color($color)); $pairing->setColor(new Color($color));
@ -720,38 +720,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::DrawAdjourned;
break; break;
case 11: case 11:
$result = Result::won; $result = Result::Won;
break; break;
case 12: case 12:
$result = Result::wonforfait; $result = Result::WonForfait;
break; break;
case 13: case 13:
$result = Result::wonadjourned; $result = Result::WonAdjourned;
break; break;
case 14: case 14:
$result = Result::wonbye; $result = Result::WonBye;
break; break;
case 0: case 0:
default: default:
$result = Result::none; $result = Result::None;
break; break;
} }
$pairing->setResult(new Result($result)); $pairing->setResult(new Result($result));

View File

@ -37,10 +37,10 @@ class Swar4 implements ReaderInterface
private $tournament; private $tournament;
/** @var bool|int|DateTime|string[] */ /** @var bool|int|DateTime|string[] */
private $binaryData; private $BinaryData;
/** @var string */ /** @var string */
private $release; private $Release;
/** @var array */ /** @var array */
private const CompatibleVersions = ['v4.']; private const CompatibleVersions = ['v4.'];
@ -430,46 +430,46 @@ class Swar4 implements ReaderInterface
} }
switch ($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_result')) { switch ($this->getTournament()->getBinaryData('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::WonForfait;
break; break;
case '40': case '40':
$result = Result::wonbye; $result = Result::WonBye;
break; break;
case '00': case '00':
default: default:
$result = Result::none; $result = Result::None;
break; break;
} }
if (array_search($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_table'), [ 16384, 8192 ]) !== false) { if (array_search($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_table'), [ 16384, 8192 ]) !== false) {
$result = Result::absent; $result = Result::Absent;
} }
$pairing->setResult(new Result($result)); $pairing->setResult(new Result($result));
switch ($this->getTournament()->getBinaryData('Pairing_' . $ptn . '_color')) { switch ($this->getTournament()->getBinaryData('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->setColor(new Color($color)); $pairing->setColor(new Color($color));
@ -571,15 +571,15 @@ class Swar4 implements ReaderInterface
*/ */
public function getRelease(): string public function getRelease(): string
{ {
return $this->release; return $this->Release;
} }
/** /**
* @param string $release * @param string $Release
*/ */
public function setRelease(string $release): void public function setRelease(string $Release): void
{ {
$this->release = $release; $this->Release = $Release;
} }
/** /**

View File

@ -32,28 +32,28 @@ class Round
* *
* @var DateTime * @var DateTime
*/ */
private $date; private $Date;
/** /**
* Array of all games * Array of all games
* *
* @var Game[] * @var Game[]
*/ */
private $games = []; private $Games = [];
/** /**
* Number of the round * Number of the round
* *
* @var int * @var int
*/ */
private $roundNo; private $RoundNo;
/** /**
* Array of all pairings for this round * Array of all pairings for this round
* *
* @var Pairing[] * @var Pairing[]
*/ */
private $pairings = []; private $Pairings = [];
/** /**
* Adds a game to the round * Adds a game to the round
@ -94,7 +94,7 @@ class Round
$allPairings = $this->getPairings(); $allPairings = $this->getPairings();
$byePairings = []; $byePairings = [];
foreach ($allPairings as $pairing) { foreach ($allPairings as $pairing) {
if ($pairing->getResult() == Result::wonbye) { if ($pairing->getResult() == Result::WonBye) {
$byePairings[] = $pairing; $byePairings[] = $pairing;
} }
} }
@ -112,7 +112,7 @@ class Round
$allPairings = $this->getPairings(); $allPairings = $this->getPairings();
$absentPairings = []; $absentPairings = [];
foreach ($allPairings as $pairing) { foreach ($allPairings as $pairing) {
if ($pairing->getResult() == Result::absent) { if ($pairing->getResult() == Result::Absent) {
$absentPairings[] = $pairing; $absentPairings[] = $pairing;
} }
} }
@ -126,17 +126,17 @@ class Round
*/ */
public function getDate(): DateTime public function getDate(): DateTime
{ {
return $this->date; return $this->Date;
} }
/** /**
* Sets the date of the round * Sets the date of the round
* *
* @param DateTime $date * @param DateTime $Date
* @return Round * @return Round
*/ */
public function setDate(DateTime $date): Round public function setDate(DateTime $Date): Round
{ {
$this->date = $date; $this->Date = $Date;
return $this; return $this;
} }
/** /**
@ -146,17 +146,17 @@ class Round
*/ */
public function getGames(): array public function getGames(): array
{ {
return $this->games; return $this->Games;
} }
/** /**
* Sets an array of all games for the round * Sets an array of all games for the round
* *
* @param Game[] $games * @param Game[] $Games
* @return Round * @return Round
*/ */
public function setGames(array $games): Round public function setGames(array $Games): Round
{ {
$this->games = $games; $this->Games = $Games;
return $this; return $this;
} }
/** /**
@ -166,17 +166,17 @@ class Round
*/ */
public function getRoundNo(): int public function getRoundNo(): int
{ {
return $this->roundNo; return $this->RoundNo;
} }
/** /**
* Sets the round number of the round * Sets the round number of the round
* *
* @param int $roundNo * @param int $RoundNo
* @return Round * @return Round
*/ */
public function setRoundNo(int $roundNo): Round public function setRoundNo(int $RoundNo): Round
{ {
$this->roundNo = $roundNo; $this->RoundNo = $RoundNo;
return $this; return $this;
} }
/** /**
@ -186,17 +186,17 @@ class Round
*/ */
public function getPairings(): array public function getPairings(): array
{ {
return $this->pairings; return $this->Pairings;
} }
/** /**
* Sets an array of all pairings for the round * Sets an array of all pairings for the round
* *
* @param Pairing[] $pairings * @param Pairing[] $Pairings
* @return Round * @return Round
*/ */
public function setPairings(array $pairings): Round public function setPairings(array $Pairings): Round
{ {
$this->pairings = $pairings; $this->Pairings = $Pairings;
return $this; return $this;
} }
} }

View File

@ -103,7 +103,7 @@ class Tournament
private $PriorityId = 'Nation'; private $PriorityId = 'Nation';
/** @var bool|DateTime|int|string[] */ /** @var bool|DateTime|int|string[] */
private $binaryData = []; private $BinaryData = [];
/** /**
* Gets a player by its ID * Gets a player by its ID
@ -244,10 +244,10 @@ class Tournament
} }
} }
$game = new Game(); $game = new Game();
if ($color->getValue() == Color::white) { if ($color->getValue() == Color::White) {
$game->setWhite($pairing); $game->setWhite($pairing);
$game->setBlack($opponent); $game->setBlack($opponent);
} elseif ($color->getValue() == Color::black) { } elseif ($color->getValue() == Color::Black) {
$game->setWhite($opponent); $game->setWhite($opponent);
$game->setBlack($pairing); $game->setBlack($pairing);
} }