More types

This commit is contained in:
Jens True 2023-08-02 10:59:15 +00:00
parent 5c7471963c
commit 72de6363fe
6 changed files with 16 additions and 9 deletions

@ -10,5 +10,5 @@ interface ISupportPartialPlay
/**
* Indicates the percent of the time the player should be weighted where 0.0 indicates the player didn't play and 1.0 indicates the player played 100% of the time.
*/
public function getPartialPlayPercentage();
public function getPartialPlayPercentage(): float;
}

@ -7,5 +7,5 @@ interface ISupportPartialUpdate
/**
* Indicated how much of a skill update a player should receive where 0.0 represents no update and 1.0 represents 100% of the update.
*/
public function getPartialUpdatePercentage();
public function getPartialUpdatePercentage(): float;
}

@ -25,7 +25,7 @@ class BasicMath
* Sums the items in $itemsToSum
*
* @param array $itemsToSum The items to sum,
* @param callable $callback The function to apply to each array element before summing.
* @param \Closure $callback The function to apply to each array element before summing.
* @return number The sum.
*/
public static function sum(array $itemsToSum, \Closure $callback): float|int

@ -57,7 +57,7 @@ class Matrix
return $this->matrixRowData[$row][$col];
}
public function setValue(int $row, int $col, float|int $value)
public function setValue(int $row, int $col, float|int $value): void
{
$this->matrixRowData[$row][$col] = $value;
}

@ -39,12 +39,12 @@ abstract class SkillCalculator
*/
abstract public function calculateMatchQuality(GameInfo $gameInfo, array $teamsOfPlayerToRatings): float;
public function isSupported($option): bool
public function isSupported(SkillCalculatorSupportedOptions $option): bool
{
return ($this->supportedOptions & $option) == $option;
return (bool)($this->supportedOptions & $option->value) == $option;
}
protected function validateTeamCountAndPlayersCountPerTeam(array $teamsOfPlayerToRatings)
protected function validateTeamCountAndPlayersCountPerTeam(array $teamsOfPlayerToRatings): void
{
self::validateTeamCountAndPlayersCountPerTeamWithRanges($teamsOfPlayerToRatings, $this->totalTeamsAllowed, $this->playersPerTeamAllowed);
}

@ -109,7 +109,11 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
);
}
// Helper function that gets a list of values for all player ratings
/**
* Helper function that gets a list of values for all player ratings
* @return int[]
*/
private static function getPlayerRatingValues(array $teamAssignmentsList, \Closure $playerRatingFunction): array
{
$playerRatingValues = [];
@ -123,7 +127,10 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator
return $playerRatingValues;
}
private static function createPlayerTeamAssignmentMatrix($teamAssignmentsList, $totalPlayers)
/**
* @param Team[] $teamAssignmentsList
*/
private static function createPlayerTeamAssignmentMatrix(array $teamAssignmentsList, int $totalPlayers): Matrix
{
// The team assignment matrix is often referred to as the "A" matrix. It's a matrix whose rows represent the players
// and the columns represent teams. At Matrix[row, column] represents that player[row] is on team[col]