diff --git a/phpstan.neon b/phpstan.neon index 94d7141..9aad0db 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,5 +3,3 @@ parameters: paths: - src # - tests - ignoreErrors: - - '#with no value type specified in iterable type array#' \ No newline at end of file diff --git a/src/SkillCalculator.php b/src/SkillCalculator.php index 759e8cf..b5b7bff 100644 --- a/src/SkillCalculator.php +++ b/src/SkillCalculator.php @@ -20,8 +20,8 @@ abstract class SkillCalculator * Calculates new ratings based on the prior ratings and team ranks. * * @param GameInfo $gameInfo Parameters for the game. - * @param array $teamsOfPlayerToRatings A mapping of team players and their ratings. - * @param array $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2). + * @param Team[] $teamsOfPlayerToRatings A mapping of team players and their ratings. + * @param int[] $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2). * @return RatingContainer All the players and their new ratings. */ abstract public function calculateNewRatings( @@ -34,7 +34,7 @@ abstract class SkillCalculator * Calculates the match quality as the likelihood of all teams drawing. * * @param GameInfo $gameInfo Parameters for the game. - * @param array $teamsOfPlayerToRatings A mapping of team players and their ratings. + * @param Team[] $teamsOfPlayerToRatings A mapping of team players and their ratings. * @return float The quality of the match between the teams as a percentage (0% = bad, 100% = well matched). */ abstract public function calculateMatchQuality(GameInfo $gameInfo, array $teamsOfPlayerToRatings): float; diff --git a/src/TrueSkill/FactorGraphTrueSkillCalculator.php b/src/TrueSkill/FactorGraphTrueSkillCalculator.php index 8c2c9fd..f76d7fe 100644 --- a/src/TrueSkill/FactorGraphTrueSkillCalculator.php +++ b/src/TrueSkill/FactorGraphTrueSkillCalculator.php @@ -26,7 +26,9 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator { parent::__construct(SkillCalculatorSupportedOptions::PARTIAL_PLAY | SkillCalculatorSupportedOptions::PARTIAL_UPDATE, TeamsRange::atLeast(2), PlayersRange::atLeast(1)); } - + /** + * {@inheritdoc} + */ public function calculateNewRatings( GameInfo $gameInfo, array $teams, @@ -45,7 +47,9 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator return $factorGraph->getUpdatedRatings(); } - + /** + * {@inheritdoc} + */ public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float { // We need to create the A matrix which is the player team assigments. diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index eff1e34..906cd20 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -217,7 +217,7 @@ class GaussianWeightedSumFactor extends GaussianFactor $result = (string) $sumVariable; $result .= ' = '; - $totalVars = is_countable($variablesToSum) ? count($variablesToSum) : 0; + $totalVars = count($variablesToSum); for ($i = 0; $i < $totalVars; $i++) { $isFirst = ($i == 0); diff --git a/src/TrueSkill/TrueSkillFactorGraph.php b/src/TrueSkill/TrueSkillFactorGraph.php index 888de4f..8bc4675 100644 --- a/src/TrueSkill/TrueSkillFactorGraph.php +++ b/src/TrueSkill/TrueSkillFactorGraph.php @@ -27,6 +27,11 @@ class TrueSkillFactorGraph extends FactorGraph private PlayerPriorValuesToSkillsLayer $priorLayer; + /** + * @param GameInfo $gameInfo Parameters for the game. + * @param Team[] $teamsOfPlayerToRatings A mapping of team players and their ratings. + * @param int[] $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2). + */ public function __construct(private readonly GameInfo $gameInfo, array $teams, array $teamRanks) { $this->priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams); diff --git a/src/TrueSkill/TwoPlayerTrueSkillCalculator.php b/src/TrueSkill/TwoPlayerTrueSkillCalculator.php index 40d223d..98adc33 100644 --- a/src/TrueSkill/TwoPlayerTrueSkillCalculator.php +++ b/src/TrueSkill/TwoPlayerTrueSkillCalculator.php @@ -13,6 +13,7 @@ use DNW\Skills\RatingContainer; use DNW\Skills\SkillCalculator; use DNW\Skills\SkillCalculatorSupportedOptions; use DNW\Skills\TeamsRange; +use DNW\Skills\Team; /** * Calculates the new ratings for only two players. @@ -27,6 +28,9 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::exactly(1)); } + /** + * {@inheritdoc} + */ public function calculateNewRatings( GameInfo $gameInfo, array $teams, diff --git a/src/TrueSkill/TwoTeamTrueSkillCalculator.php b/src/TrueSkill/TwoTeamTrueSkillCalculator.php index f52b99c..58f0867 100644 --- a/src/TrueSkill/TwoTeamTrueSkillCalculator.php +++ b/src/TrueSkill/TwoTeamTrueSkillCalculator.php @@ -26,7 +26,9 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator { parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::atLeast(1)); } - + /** + * {@inheritdoc} + */ public function calculateNewRatings(GameInfo $gameInfo, array $teams, array $teamRanks): RatingContainer { Guard::argumentNotNull($gameInfo, 'gameInfo'); @@ -149,10 +151,10 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator // We've verified that there's just two teams $team1Ratings = $teams[0]->getAllRatings(); - $team1Count = is_countable($team1Ratings) ? count($team1Ratings) : 0; + $team1Count = count($team1Ratings); $team2Ratings = $teams[1]->getAllRatings(); - $team2Count = is_countable($team2Ratings) ? count($team2Ratings) : 0; + $team2Count = count($team2Ratings); $totalPlayers = $team1Count + $team2Count;