From 72de6363fe704ea8f3cd8e2f21241db40c092480 Mon Sep 17 00:00:00 2001 From: Jens True Date: Wed, 2 Aug 2023 10:59:15 +0000 Subject: [PATCH] More types --- src/ISupportPartialPlay.php | 2 +- src/ISupportPartialUpdate.php | 2 +- src/Numerics/BasicMath.php | 2 +- src/Numerics/Matrix.php | 2 +- src/SkillCalculator.php | 6 +++--- src/TrueSkill/FactorGraphTrueSkillCalculator.php | 11 +++++++++-- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/ISupportPartialPlay.php b/src/ISupportPartialPlay.php index a1de31a..af3f120 100644 --- a/src/ISupportPartialPlay.php +++ b/src/ISupportPartialPlay.php @@ -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; } diff --git a/src/ISupportPartialUpdate.php b/src/ISupportPartialUpdate.php index d6de3bf..1a08fea 100644 --- a/src/ISupportPartialUpdate.php +++ b/src/ISupportPartialUpdate.php @@ -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; } diff --git a/src/Numerics/BasicMath.php b/src/Numerics/BasicMath.php index f89bbfa..bfe0a1f 100644 --- a/src/Numerics/BasicMath.php +++ b/src/Numerics/BasicMath.php @@ -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 diff --git a/src/Numerics/Matrix.php b/src/Numerics/Matrix.php index 63edae5..11343f9 100644 --- a/src/Numerics/Matrix.php +++ b/src/Numerics/Matrix.php @@ -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; } diff --git a/src/SkillCalculator.php b/src/SkillCalculator.php index 43362a9..43e7dbe 100644 --- a/src/SkillCalculator.php +++ b/src/SkillCalculator.php @@ -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); } diff --git a/src/TrueSkill/FactorGraphTrueSkillCalculator.php b/src/TrueSkill/FactorGraphTrueSkillCalculator.php index 06ccead..2066e42 100644 --- a/src/TrueSkill/FactorGraphTrueSkillCalculator.php +++ b/src/TrueSkill/FactorGraphTrueSkillCalculator.php @@ -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]