mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-21 22:17:41 +01:00
moving constant arrays to a separate class
This commit is contained in:
parent
0ddc62c0b7
commit
374e339353
17
src/Constants.php
Normal file
17
src/Constants.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace JeroenED\Libpairtwo;
|
||||
|
||||
use JeroenED\Libpairtwo\Enums\Color;
|
||||
use JeroenED\Libpairtwo\Enums\Result;
|
||||
|
||||
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 Black = [ Color::black ];
|
||||
const White = [ Color::white ];
|
||||
}
|
@ -9,13 +9,6 @@ use JeroenED\Libpairtwo\Enums\Result;
|
||||
|
||||
abstract class Tiebreaks extends Tournament
|
||||
{
|
||||
private const Won = [ Result::won, Result::wonforfait, Result::wonbye, Result::wonadjourned ];
|
||||
private const Draw = [ Result::draw, Result::drawadjourned];
|
||||
private const Lost = [ Result::absent, Result::bye, Result::lost, Result::adjourned ];
|
||||
private const NotPlayed = [ Result::bye, Result::wonbye, Result::absent ];
|
||||
private const Black = [ Color::black ];
|
||||
private const White = [ Color::white ];
|
||||
|
||||
|
||||
/**
|
||||
* @param Player $player
|
||||
@ -45,9 +38,9 @@ abstract class Tiebreaks extends Tournament
|
||||
{
|
||||
$points = 0;
|
||||
foreach ($player->getPairings() as $pairing) {
|
||||
if (array_search($pairing->getResult(), self::Won) !== false) {
|
||||
if (array_search($pairing->getResult(), Constants::Won) !== false) {
|
||||
$points = $points + 1;
|
||||
} elseif (array_search($pairing->getResult(), self::Draw) !== false) {
|
||||
} elseif (array_search($pairing->getResult(), Constants::Draw) !== false) {
|
||||
$points = $points + 0.5;
|
||||
}
|
||||
}
|
||||
@ -63,7 +56,7 @@ abstract class Tiebreaks extends Tournament
|
||||
{
|
||||
$totalwins = 0;
|
||||
foreach ($player->getPairings() as $pairing) {
|
||||
if (array_search($pairing->getResult(), self::Won) !== false) {
|
||||
if (array_search($pairing->getResult(), Constants::Won) !== false) {
|
||||
$totalwins++;
|
||||
}
|
||||
}
|
||||
@ -79,7 +72,7 @@ abstract class Tiebreaks extends Tournament
|
||||
{
|
||||
$totalwins = 0;
|
||||
foreach ($player->getPairings() as $pairing) {
|
||||
if (array_search($pairing->getColor(), self::Black) !== false) {
|
||||
if (array_search($pairing->getColor(), Constants::Black) !== false) {
|
||||
$totalwins++;
|
||||
}
|
||||
}
|
||||
@ -94,7 +87,7 @@ abstract class Tiebreaks extends Tournament
|
||||
{
|
||||
$totalwins = 0;
|
||||
foreach ($player->getPairings() as $pairing) {
|
||||
if (array_search($pairing->getColor(), self::Black) !== false && array_search($pairing->getResult(), Self::Won) !== false) {
|
||||
if (array_search($pairing->getColor(), Constants::Black) !== false && array_search($pairing->getResult(), Constants::Won) !== false) {
|
||||
$totalwins++;
|
||||
}
|
||||
}
|
||||
@ -123,9 +116,9 @@ abstract class Tiebreaks extends Tournament
|
||||
$totalmatches = 0;
|
||||
foreach ($player->getPairings() as $pairing) {
|
||||
if (array_search($pairing->getOpponent(), $interestingplayers) !== false) {
|
||||
if (array_search($pairing->getResult(), self::Won) !== false) {
|
||||
if (array_search($pairing->getResult(), Constants::Won) !== false) {
|
||||
$points = $points + 1;
|
||||
} elseif (array_search($pairing->getResult(), self::Draw) !== false) {
|
||||
} elseif (array_search($pairing->getResult(), Constants::Draw) !== false) {
|
||||
$points = $points + 0.5;
|
||||
}
|
||||
$totalmatches++;
|
||||
@ -148,7 +141,7 @@ abstract class Tiebreaks extends Tournament
|
||||
$totalopponents = 0;
|
||||
$allratings = [];
|
||||
foreach ($pairings as $pairing) {
|
||||
if (array_search($pairing->getResult(), self::NotPlayed) === false) {
|
||||
if (array_search($pairing->getResult(), Constants::NotPlayed) === false) {
|
||||
$toadd = $pairing->getOpponent()->getElos()['home'];
|
||||
if ($toadd != 0) {
|
||||
$allratings[] = $toadd;
|
||||
|
Loading…
Reference in New Issue
Block a user