Psalm analysis without warnings.

This commit is contained in:
Jens True 2023-08-04 06:56:47 +00:00
parent 0e1947ca3a
commit ed665e755c
4 changed files with 12 additions and 12 deletions

@ -1,9 +1,9 @@
{ {
"name": "dnw/php-trueskill", "name": "dnw/php-trueskill",
"description": "Trueskill implementation by Moserware updated for PHP 8.1", "description": "Trueskill implementation by Moserware updated for PHP 8.2",
"keywords": ["trueskill", "matchmaking", "ranking", "skill", "elo"], "keywords": ["trueskill", "matchmaking", "ranking", "skill", "elo"],
"require": { "require": {
"php": "^8.1" "php": "^8.2"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^10", "phpunit/phpunit": "^10",

@ -6,7 +6,7 @@
xmlns="https://getpsalm.org/schema/config" xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true" findUnusedBaselineEntry="true"
findUnusedCode="true" findUnusedCode="false"
> >
<projectFiles> <projectFiles>
<directory name="src" /> <directory name="src" />

@ -19,25 +19,25 @@ abstract class SkillCalculator
/** /**
* Calculates new ratings based on the prior ratings and team ranks. * Calculates new ratings based on the prior ratings and team ranks.
* *
* @param GameInfo $gameInfo Parameters for the game. * @param GameInfo $gameInfo Parameters for the game.
* @param Team[] $teamsOfPlayerToRatings A mapping of team players and their ratings. * @param Team[] $teams 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). * @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. * @return RatingContainer All the players and their new ratings.
*/ */
abstract public function calculateNewRatings( abstract public function calculateNewRatings(
GameInfo $gameInfo, GameInfo $gameInfo,
array $teamsOfPlayerToRatings, array $teams,
array $teamRanks array $teamRanks
): RatingContainer; ): RatingContainer;
/** /**
* Calculates the match quality as the likelihood of all teams drawing. * Calculates the match quality as the likelihood of all teams drawing.
* *
* @param GameInfo $gameInfo Parameters for the game. * @param GameInfo $gameInfo Parameters for the game.
* @param Team[] $teamsOfPlayerToRatings A mapping of team players and their ratings. * @param Team[] $teams 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). * @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; abstract public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float;
public function isSupported(int $option): bool public function isSupported(int $option): bool
{ {

@ -84,7 +84,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
$selfMeanSum = BasicMath::sum($selfTeam->getAllRatings(), $meanGetter); $selfMeanSum = BasicMath::sum($selfTeam->getAllRatings(), $meanGetter);
$otherTeamMeanSum = BasicMath::sum($otherTeam->getAllRatings(), $meanGetter); $otherTeamMeanSum = BasicMath::sum($otherTeam->getAllRatings(), $meanGetter);
$varianceGetter = fn ($currentRating) => BasicMath::square($currentRating->getStandardDeviation()); $varianceGetter = fn ($currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
$c = sqrt( $c = sqrt(
BasicMath::sum($selfTeam->getAllRatings(), $varianceGetter) BasicMath::sum($selfTeam->getAllRatings(), $varianceGetter)
@ -162,7 +162,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator
$meanGetter = fn ($currentRating) => $currentRating->getMean(); $meanGetter = fn ($currentRating) => $currentRating->getMean();
$varianceGetter = fn ($currentRating) => BasicMath::square($currentRating->getStandardDeviation()); $varianceGetter = fn ($currentRating): float => BasicMath::square($currentRating->getStandardDeviation());
$team1MeanSum = BasicMath::sum($team1Ratings, $meanGetter); $team1MeanSum = BasicMath::sum($team1Ratings, $meanGetter);
$team1StdDevSquared = BasicMath::sum($team1Ratings, $varianceGetter); $team1StdDevSquared = BasicMath::sum($team1Ratings, $varianceGetter);