Skip to content

Commit

Permalink
fix(nrofplaces): renamed from withpoule
Browse files Browse the repository at this point in the history
  • Loading branch information
thepercival committed Jul 30, 2024
1 parent 5acdf01 commit d4c87fc
Show file tree
Hide file tree
Showing 19 changed files with 444 additions and 445 deletions.
142 changes: 75 additions & 67 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion domain/PouleStructure.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function getTotalNrOfGames(array $sportVariants): int
$nrOfGames = 0;
foreach ($this->poules as $nrOfPlaces) {
foreach ($sportVariants as $sportVariant) {
$nrOfGames += (new VariantCreator())->createWithPoule($nrOfPlaces, $sportVariant)->getTotalNrOfGames();
$nrOfGames += (new VariantCreator())->createWithNrOfPlaces($nrOfPlaces, $sportVariant)->getTotalNrOfGames();
}
}
return $nrOfGames;
Expand Down
5 changes: 0 additions & 5 deletions domain/Sport/GamePlaceCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

namespace SportsHelpers\Sport;

use SportsHelpers\Sport\Variant\WithPoule\AllInOneGame as AllInOneGameWithPoule;
use SportsHelpers\Sport\Variant\WithPoule\Single as SingleWithPoule;
use SportsHelpers\Sport\Variant\WithPoule\Against\GamesPerPlace as AgainstGppWithPoule;
use SportsHelpers\Sport\Variant\WithPoule\Against\H2h as AgainstH2hWithPoule;

class GamePlaceCalculator
{
public function __construct()
Expand Down
28 changes: 14 additions & 14 deletions domain/Sport/Variant/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@

use SportsHelpers\Sport\Variant\Against\GamesPerPlace as AgainstGpp;
use SportsHelpers\Sport\Variant\Against\H2h as AgainstH2h;
use SportsHelpers\Sport\Variant\WithPoule\Against\GamesPerPlace as AgainstGppWithPoule;
use SportsHelpers\Sport\Variant\WithPoule\Against\H2h as AgainstH2hWithPoule;
use SportsHelpers\Sport\Variant\WithPoule\AllInOneGame as AllInOneGameWithPoule;
use SportsHelpers\Sport\Variant\WithPoule\Single as SingleWithPoule;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\Against\GamesPerPlace as AgainstGppWithNrOfPlaces;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\Against\H2h as AgainstH2hWithNrOfPlaces;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\AllInOneGame as AllInOneGameWithNrOfPlaces;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\Single as SingleWithNrOfPlaces;

class Creator
{
public function createWithPoule(
public function createWithNrOfPlaces(
int $nrOfPlaces,
AllInOneGame|Single|AgainstH2h|AgainstGpp $sportVariant): AllInOneGameWithPoule|SingleWithPoule|AgainstH2hWithPoule|AgainstGppWithPoule {
AllInOneGame|Single|AgainstH2h|AgainstGpp $sportVariant): AllInOneGameWithNrOfPlaces|SingleWithNrOfPlaces|AgainstH2hWithNrOfPlaces|AgainstGppWithNrOfPlaces {
if( $sportVariant instanceof AllInOneGame) {
return new AllInOneGameWithPoule($nrOfPlaces, $sportVariant);
return new AllInOneGameWithNrOfPlaces($nrOfPlaces, $sportVariant);
} else if( $sportVariant instanceof Single) {
return new SingleWithPoule($nrOfPlaces, $sportVariant);
return new SingleWithNrOfPlaces($nrOfPlaces, $sportVariant);
} else if( $sportVariant instanceof AgainstH2h) {
return new AgainstH2hWithPoule($nrOfPlaces, $sportVariant);
return new AgainstH2hWithNrOfPlaces($nrOfPlaces, $sportVariant);
}
return new AgainstGppWithPoule($nrOfPlaces, $sportVariant);
return new AgainstGppWithNrOfPlaces($nrOfPlaces, $sportVariant);
}

/**
* @param int $nrOfPlaces
* @param list<AgainstH2h|AgainstGpp|AllInOneGame|Single> $sportVariants
* @return list<AgainstH2hWithPoule|AgainstGppWithPoule|AllInOneGameWithPoule|SingleWithPoule>
* @return list<AgainstH2hWithNrOfPlaces|AgainstGppWithNrOfPlaces|AllInOneGameWithNrOfPlaces|SingleWithNrOfPlaces>
*/
public function createWithPoules(int $nrOfPlaces,array $sportVariants): array {
public function createListWithNrOfPlaces(int $nrOfPlaces,array $sportVariants): array {

return array_map(
function(AgainstH2h|AgainstGpp|AllInOneGame|Single $sportVariant)
use($nrOfPlaces) : AgainstH2hWithPoule|AgainstGppWithPoule|AllInOneGameWithPoule|SingleWithPoule {
return $this->createWithPoule($nrOfPlaces, $sportVariant);
use($nrOfPlaces) : AgainstH2hWithNrOfPlaces|AgainstGppWithNrOfPlaces|AllInOneGameWithNrOfPlaces|SingleWithNrOfPlaces {
return $this->createWithNrOfPlaces($nrOfPlaces, $sportVariant);
}, $sportVariants );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

declare(strict_types=1);

namespace SportsHelpers\Sport\Variant\WithPoule;
namespace SportsHelpers\Sport\Variant\WithNrOfPlaces;

use SportsHelpers\Against\Side;
use SportsHelpers\SelfReferee;
use SportsHelpers\SelfRefereeInfo;
use SportsHelpers\Sport\Variant\Against\GamesPerPlace as AgainstGpp;
use SportsHelpers\Sport\Variant\Against\H2h as AgainstH2h;
use SportsHelpers\Sport\WithPoule as SportVariantWithPoule;
use SportsHelpers\Sport\WithNrOfPlaces as SportVariantWithNrOfPlaces;
use SportsHelpers\SportMath;

/**
* @template-extends SportVariantWithPoule<AgainstGpp|AgainstH2h>
* @template-extends SportVariantWithNrOfPlaces<AgainstGpp|AgainstH2h>
*/
abstract class Against extends SportVariantWithPoule
abstract class Against extends SportVariantWithNrOfPlaces
{
public function __construct(int $nrOfPlaces, protected AgainstGpp|AgainstH2h $againstVariant ) {
if( $nrOfPlaces < $againstVariant->getNrOfGamePlaces() ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace SportsHelpers\Sport\Variant\WithPoule\Against;
namespace SportsHelpers\Sport\Variant\WithNrOfPlaces\Against;

use SportsHelpers\Sport\Variant\WithPoule\Against\GamesPerPlace as AgainstGppWithPoule;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\Against\GamesPerPlace as AgainstGppWithNrOfPlaces;
use SportsHelpers\Sport\Variant\Against\GamesPerPlace as AgainstGpp;


Expand All @@ -22,9 +22,9 @@ public function assignAgainstSportsEqually(int $nrOfPlaces, array $againstGppVar
$nrOfPossibleCombinations = null;
foreach( $againstGpps as $againstGpp) {
$uniqueNrOfCombinationsPerGame = $againstGpp->getNrOfAgainstCombinationsPerGame();
$againstGppWithPoule = new AgainstGppWithPoule($nrOfPlaces, $againstGpp);
$nrOfPossibleCombinations = $againstGppWithPoule->getNrOfPossibleAgainstCombinations();
$totalNrOfGames += $againstGppWithPoule->getTotalNrOfGames();
$againstGppWithNrOfPlaces = new AgainstGppWithNrOfPlaces($nrOfPlaces, $againstGpp);
$nrOfPossibleCombinations = $againstGppWithNrOfPlaces->getNrOfPossibleAgainstCombinations();
$totalNrOfGames += $againstGppWithNrOfPlaces->getTotalNrOfGames();
}
if( $uniqueNrOfCombinationsPerGame !== null && $totalNrOfGames > 0
&& $nrOfPossibleCombinations !== null &&
Expand Down Expand Up @@ -52,9 +52,9 @@ public function assignWithSportsEqually(int $nrOfPlaces, array $againstGppVarian
$nrOfPossibleCombinations = null;
foreach( $againstGpps as $againstGpp) {
$uniqueNrOfCombinationsPerGame = $againstGpp->getNrOfWithCombinationsPerGame();
$againstGppWithPoule = new AgainstGppWithPoule($nrOfPlaces, $againstGpp);
$nrOfPossibleCombinations = $againstGppWithPoule->getNrOfPossibleWithCombinations();
$totalNrOfGames += $againstGppWithPoule->getTotalNrOfGames();
$againstGppWithNrOfPlaces = new AgainstGppWithNrOfPlaces($nrOfPlaces, $againstGpp);
$nrOfPossibleCombinations = $againstGppWithNrOfPlaces->getNrOfPossibleWithCombinations();
$totalNrOfGames += $againstGppWithNrOfPlaces->getTotalNrOfGames();
}
if( $uniqueNrOfCombinationsPerGame !== null && $totalNrOfGames > 0
&& $nrOfPossibleCombinations !== null &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
declare(strict_types = 1);

namespace SportsHelpers\Sport\Variant\WithPoule\Against;
namespace SportsHelpers\Sport\Variant\WithNrOfPlaces\Against;

use SportsHelpers\Against\Side;
use SportsHelpers\Sport\Variant\Against\GamesPerPlace as AgainstGpp;
use SportsHelpers\Sport\Variant\Against\H2h as AgainstH2h;
use SportsHelpers\Sport\Variant\WithPoule\Against as AgainstWithPoule;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\Against as AgainstWithNrOfPlaces;
use SportsHelpers\SportMath;

class GamesPerPlace extends AgainstWithPoule
class GamesPerPlace extends AgainstWithNrOfPlaces
{
public function __construct(int $nrOfPlaces, protected AgainstGpp $sportVariant)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
declare(strict_types = 1);

namespace SportsHelpers\Sport\Variant\WithPoule\Against;
namespace SportsHelpers\Sport\Variant\WithNrOfPlaces\Against;

use SportsHelpers\Sport\Variant\Against\H2h as AgainstH2h;
use SportsHelpers\Sport\Variant\WithPoule\Against as AgainstWithPoule;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\Against as AgainstWithNrOfPlaces;

class H2h extends AgainstWithPoule
class H2h extends AgainstWithNrOfPlaces
{
public function __construct(int $nrOfPlaces, protected AgainstH2h $sportVariant)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

declare(strict_types=1);

namespace SportsHelpers\Sport\Variant\WithPoule;
namespace SportsHelpers\Sport\Variant\WithNrOfPlaces;

use SportsHelpers\SelfReferee;
use SportsHelpers\SelfRefereeInfo;
use SportsHelpers\Sport\Variant\AllInOneGame as AllInOneGameVariant;
use SportsHelpers\Sport\WithPoule as SportVariantWithPoule;
use SportsHelpers\Sport\WithNrOfPlaces as SportVariantWithNrOfPlaces;

/**
* @template-extends SportVariantWithPoule<AllInOneGameVariant>
* @template-extends SportVariantWithNrOfPlaces<AllInOneGameVariant>
*/
class AllInOneGame extends SportVariantWithPoule
class AllInOneGame extends SportVariantWithNrOfPlaces
{
public function __construct(int $nrOfPlaces, protected AllInOneGameVariant $sportVariant ) {
parent::__construct($nrOfPlaces);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

declare(strict_types=1);

namespace SportsHelpers\Sport\Variant\WithPoule;
namespace SportsHelpers\Sport\Variant\WithNrOfPlaces;

use SportsHelpers\SelfReferee;
use SportsHelpers\SelfRefereeInfo;
use SportsHelpers\Sport\Variant\Single as SingleVariant;
use SportsHelpers\Sport\WithPoule as SportVariantWithPoule;
use SportsHelpers\Sport\WithNrOfPlaces as SportVariantWithNrOfPlaces;

/**
* @template-extends SportVariantWithPoule<SingleVariant>
* @template-extends SportVariantWithNrOfPlaces<SingleVariant>
*/
class Single extends SportVariantWithPoule
class Single extends SportVariantWithNrOfPlaces
{
public function __construct(int $nrOfPlaces, protected SingleVariant $sportVariant ) {
parent::__construct($nrOfPlaces );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* @template T
*/
abstract class WithPoule
abstract class WithNrOfPlaces
{
/**
* @param int $nrOfPlaces
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/Sport/GamePlaceCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
use SportsHelpers\Sport\GamePlaceCalculator;
use SportsHelpers\Sport\Variant\Against\H2h as AgainstH2hSportVariant;
use SportsHelpers\Sport\Variant\Against\GamesPerPlace as AgainstGppSportVariant;
use SportsHelpers\Sport\Variant\WithPoule\Against\H2h as AgainstH2hWithPoule;
use SportsHelpers\Sport\Variant\WithPoule\Against\GamesPerPlace as AgainstGppWithPoule;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\Against\H2h as AgainstH2hWithNrOfPlaces;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\Against\GamesPerPlace as AgainstGppWithNrOfPlaces;

final class GamePlaceCalculatorTest extends TestCase
{
Expand Down
1 change: 0 additions & 1 deletion tests/cases/Sport/Variant/Against/GamesPerPlaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use SportsHelpers\GameMode;
use SportsHelpers\Sport\Variant\Against\GamesPerPlace as AgainstSportGppVariant;
use SportsHelpers\Sport\Variant\Against\GamesPerPlace as AgainstGppVariant;
use SportsHelpers\Sport\Variant\WithPoule\Against\GamesPerPlace as AgainstGppWithPoule;

class GamesPerPlaceTest extends TestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

declare(strict_types=1);

namespace SportsHelpers\Tests\Sport\Variant\WithPoule\Against;
namespace SportsHelpers\Tests\Sport\Variant\NrOfPlaces\Against;

use PHPUnit\Framework\TestCase;
use SportsHelpers\Against\Side;
use SportsHelpers\Sport\Variant\Against\GamesPerPlace as AgainstSportGppVariant;
use SportsHelpers\Sport\Variant\WithPoule\Against\EquallyAssignCalculator;
use SportsHelpers\Sport\Variant\WithPoule\Against\GamesPerPlace as AgainstGppWithPoule;
use SportsHelpers\Sport\Variant\WithNrOfPlaces\Against\EquallyAssignCalculator;

class EquallyAssignCalculatorTest extends TestCase
{
Expand Down
Loading

0 comments on commit d4c87fc

Please sign in to comment.