From 5dd4acf57d323c45f296ac976eb84a2370b17753 Mon Sep 17 00:00:00 2001 From: Alex Wulf Date: Tue, 5 Jul 2022 16:32:18 +0200 Subject: [PATCH] Pint applied --- composer.json | 6 +- composer.lock | 137 +++++++++--------- rector.php | 12 +- src/Player.php | 2 +- src/Rating.php | 6 +- src/SkillCalculator.php | 1 + .../FactorGraphTrueSkillCalculator.php | 4 +- src/TrueSkill/Factors/GaussianPriorFactor.php | 1 - ...yerPerformancesToTeamPerformancesLayer.php | 5 +- .../Layers/PlayerPriorValuesToSkillsLayer.php | 2 +- .../PlayerSkillsToPerformancesLayer.php | 5 +- ...ancesToTeamPerformanceDifferencesLayer.php | 1 - src/TrueSkill/TrueSkillFactorGraph.php | 2 +- src/TrueSkill/TwoTeamTrueSkillCalculator.php | 8 +- tests/TrueSkill/TrueSkillCalculatorTests.php | 2 +- 15 files changed, 95 insertions(+), 99 deletions(-) diff --git a/composer.json b/composer.json index f03c741..7c79cd2 100644 --- a/composer.json +++ b/composer.json @@ -3,13 +3,13 @@ "description": "Trueskill implementation by Moserware updated for PHP 8.1", "keywords": ["trueskill", "matchmaking", "ranking", "skill", "elo"], "require": { - "php": "^8.1", - "laravel/pint": "^0.2.3" + "php": "^8.1" }, "require-dev": { "phpunit/phpunit": "^9.0", "rector/rector": "^0.13.7", - "phpstan/phpstan": "^1.8" + "phpstan/phpstan": "^1.8", + "laravel/pint": "^0.2.3" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 59986a3..7ce668a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,75 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6b092682644fef66d759ad40475e1f2e", - "packages": [ - { - "name": "laravel/pint", - "version": "v0.2.3", - "source": { - "type": "git", - "url": "https://github.com/laravel/pint.git", - "reference": "d0829631687c1238abdd660daac3d7218254b65c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/laravel/pint/zipball/d0829631687c1238abdd660daac3d7218254b65c", - "reference": "d0829631687c1238abdd660daac3d7218254b65c", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ext-mbstring": "*", - "ext-tokenizer": "*", - "ext-xml": "*", - "php": "^8.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.8.0", - "illuminate/view": "^9.17.0", - "laravel-zero/framework": "^9.1.1", - "mockery/mockery": "^1.5.0", - "nunomaduro/larastan": "^2.1.11", - "nunomaduro/termwind": "^1.10.1", - "pestphp/pest": "^1.21.3" - }, - "bin": [ - "builds/pint" - ], - "type": "project", - "autoload": { - "psr-4": { - "App\\": "app/", - "Database\\Seeders\\": "database/seeders/", - "Database\\Factories\\": "database/factories/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nuno Maduro", - "email": "enunomaduro@gmail.com" - } - ], - "description": "An opinionated code formatter for PHP.", - "homepage": "https://laravel.com", - "keywords": [ - "format", - "formatter", - "lint", - "linter", - "php" - ], - "support": { - "issues": "https://github.com/laravel/pint/issues", - "source": "https://github.com/laravel/pint" - }, - "time": "2022-07-04T16:04:06+00:00" - } - ], + "content-hash": "ac8b97bff674024ae19ad228626b465d", + "packages": [], "packages-dev": [ { "name": "doctrine/instantiator", @@ -144,6 +77,72 @@ ], "time": "2022-03-03T08:28:38+00:00" }, + { + "name": "laravel/pint", + "version": "v0.2.3", + "source": { + "type": "git", + "url": "https://github.com/laravel/pint.git", + "reference": "d0829631687c1238abdd660daac3d7218254b65c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/pint/zipball/d0829631687c1238abdd660daac3d7218254b65c", + "reference": "d0829631687c1238abdd660daac3d7218254b65c", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "ext-tokenizer": "*", + "ext-xml": "*", + "php": "^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.8.0", + "illuminate/view": "^9.17.0", + "laravel-zero/framework": "^9.1.1", + "mockery/mockery": "^1.5.0", + "nunomaduro/larastan": "^2.1.11", + "nunomaduro/termwind": "^1.10.1", + "pestphp/pest": "^1.21.3" + }, + "bin": [ + "builds/pint" + ], + "type": "project", + "autoload": { + "psr-4": { + "App\\": "app/", + "Database\\Seeders\\": "database/seeders/", + "Database\\Factories\\": "database/factories/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "An opinionated code formatter for PHP.", + "homepage": "https://laravel.com", + "keywords": [ + "format", + "formatter", + "lint", + "linter", + "php" + ], + "support": { + "issues": "https://github.com/laravel/pint/issues", + "source": "https://github.com/laravel/pint" + }, + "time": "2022-07-04T16:04:06+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.11.0", diff --git a/rector.php b/rector.php index 90ad5e4..4947657 100644 --- a/rector.php +++ b/rector.php @@ -9,16 +9,16 @@ use Rector\Set\ValueObject\SetList; return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ - __DIR__ . '/src' + __DIR__.'/src', ]); // register a single rule $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); // define sets of rules - $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_81, - SetList::CODE_QUALITY, - SetList::DEAD_CODE, - ]); + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_81, + SetList::CODE_QUALITY, + SetList::DEAD_CODE, + ]); }; diff --git a/src/Player.php b/src/Player.php index 809f3b5..e20211e 100644 --- a/src/Player.php +++ b/src/Player.php @@ -18,7 +18,7 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate, \Stringable /** * Constructs a player. * - * @param mixed $_Id The identifier for the player, such as a name. + * @param mixed $_Id The identifier for the player, such as a name. * @param number $partialPlayPercentage The weight percentage to give this player when calculating a new rank. * @param number $partialUpdatePercentage Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update. */ diff --git a/src/Rating.php b/src/Rating.php index e7d79f8..1051063 100644 --- a/src/Rating.php +++ b/src/Rating.php @@ -12,9 +12,9 @@ class Rating implements \Stringable /** * Constructs a rating. * - * @param float $_mean The statistical mean value of the rating (also known as mu). - * @param float $_standardDeviation The standard deviation of the rating (also known as s). - * @param float|int $_conservativeStandardDeviationMultiplier optional The number of standardDeviations to subtract from the mean to achieve a conservative rating. + * @param float $_mean The statistical mean value of the rating (also known as mu). + * @param float $_standardDeviation The standard deviation of the rating (also known as s). + * @param float|int $_conservativeStandardDeviationMultiplier optional The number of standardDeviations to subtract from the mean to achieve a conservative rating. */ public function __construct(private $_mean, private $_standardDeviation, private $_conservativeStandardDeviationMultiplier = self::CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER) { diff --git a/src/SkillCalculator.php b/src/SkillCalculator.php index 4f07716..3f46ed4 100644 --- a/src/SkillCalculator.php +++ b/src/SkillCalculator.php @@ -47,6 +47,7 @@ abstract class SkillCalculator /** * @param array<\DNW\Skills\Team> $teams * @return void + * * @throws \Exception */ private static function validateTeamCountAndPlayersCountPerTeamWithRanges(array $teams, TeamsRange $totalTeams, PlayersRange $playersPerTeam) diff --git a/src/TrueSkill/FactorGraphTrueSkillCalculator.php b/src/TrueSkill/FactorGraphTrueSkillCalculator.php index 60fc999..076641d 100644 --- a/src/TrueSkill/FactorGraphTrueSkillCalculator.php +++ b/src/TrueSkill/FactorGraphTrueSkillCalculator.php @@ -88,7 +88,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator { // A simple vector of all the player means. return new Vector(self::getPlayerRatingValues($teamAssignmentsList, - fn($rating) => $rating->getMean())); + fn ($rating) => $rating->getMean())); } private static function getPlayerCovarianceMatrix(array $teamAssignmentsList) @@ -97,7 +97,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator // players. return new DiagonalMatrix( self::getPlayerRatingValues($teamAssignmentsList, - fn($rating) => BasicMath::square($rating->getStandardDeviation()))); + fn ($rating) => BasicMath::square($rating->getStandardDeviation()))); } // Helper function that gets a list of values for all player ratings diff --git a/src/TrueSkill/Factors/GaussianPriorFactor.php b/src/TrueSkill/Factors/GaussianPriorFactor.php index e3b34fd..c026041 100644 --- a/src/TrueSkill/Factors/GaussianPriorFactor.php +++ b/src/TrueSkill/Factors/GaussianPriorFactor.php @@ -38,6 +38,5 @@ class GaussianPriorFactor extends GaussianFactor $message->setValue($this->_newMessage); return GaussianDistribution::subtract($oldMarginal, $newMarginal); - } } diff --git a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php index fe859d3..db08fe0 100644 --- a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php @@ -5,7 +5,6 @@ namespace DNW\Skills\TrueSkill\Layers; use DNW\Skills\FactorGraphs\ScheduleStep; use DNW\Skills\PartialPlay; use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor; -use DNW\Skills\TrueSkill\TrueSkillFactorGraph; class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer { @@ -31,7 +30,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye return $this->scheduleSequence( array_map( - fn($weightedSumFactor) => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0), + fn ($weightedSumFactor) => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0), $localFactors), 'all player perf to team perf schedule'); } @@ -70,7 +69,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye private function createOutputVariable($team) { - $memberNames = array_map(fn($currentPlayer) => (string) ($currentPlayer->getKey()), $team); + $memberNames = array_map(fn ($currentPlayer) => (string) ($currentPlayer->getKey()), $team); $teamMemberNames = \implode(', ', $memberNames); diff --git a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php index 8144b98..56d64d2 100644 --- a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php +++ b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php @@ -46,7 +46,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer return $this->scheduleSequence( array_map( - fn($prior) => new ScheduleStep('Prior to Skill Step', $prior, 0), + fn ($prior) => new ScheduleStep('Prior to Skill Step', $prior, 0), $localFactors), 'All priors'); } diff --git a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php index 33d1332..b7190c2 100644 --- a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php @@ -6,7 +6,6 @@ use DNW\Skills\FactorGraphs\KeyedVariable; use DNW\Skills\FactorGraphs\ScheduleStep; use DNW\Skills\Numerics\BasicMath; use DNW\Skills\TrueSkill\Factors\GaussianLikelihoodFactor; -use DNW\Skills\TrueSkill\TrueSkillFactorGraph; class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer { @@ -51,7 +50,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer return $this->scheduleSequence( array_map( - fn($likelihood) => new ScheduleStep('Skill to Perf step', $likelihood, 0), + fn ($likelihood) => new ScheduleStep('Skill to Perf step', $likelihood, 0), $localFactors), 'All skill to performance sending'); } @@ -62,7 +61,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer return $this->scheduleSequence( array_map( - fn($likelihood) => new ScheduleStep('name', $likelihood, 1), + fn ($likelihood) => new ScheduleStep('name', $likelihood, 1), $localFactors), 'All skill to performance sending'); } diff --git a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php index f762ee0..60760cb 100644 --- a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php +++ b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php @@ -4,7 +4,6 @@ namespace DNW\Skills\TrueSkill\Layers; use DNW\Skills\FactorGraphs\Variable; use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor; -use DNW\Skills\TrueSkill\TrueSkillFactorGraph; class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer { diff --git a/src/TrueSkill/TrueSkillFactorGraph.php b/src/TrueSkill/TrueSkillFactorGraph.php index 6c1aff6..8ba0ade 100644 --- a/src/TrueSkill/TrueSkillFactorGraph.php +++ b/src/TrueSkill/TrueSkillFactorGraph.php @@ -27,7 +27,7 @@ class TrueSkillFactorGraph extends FactorGraph { $this->_priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams); $newFactory = new VariableFactory( - fn() => GaussianDistribution::fromPrecisionMean(0, 0)); + fn () => GaussianDistribution::fromPrecisionMean(0, 0)); $this->setVariableFactory($newFactory); $this->_layers = [ diff --git a/src/TrueSkill/TwoTeamTrueSkillCalculator.php b/src/TrueSkill/TwoTeamTrueSkillCalculator.php index 2695778..1af676b 100644 --- a/src/TrueSkill/TwoTeamTrueSkillCalculator.php +++ b/src/TrueSkill/TwoTeamTrueSkillCalculator.php @@ -72,12 +72,12 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator $totalPlayers = $selfTeam->count() + $otherTeam->count(); - $meanGetter = fn($currentRating) => $currentRating->getMean(); + $meanGetter = fn ($currentRating) => $currentRating->getMean(); $selfMeanSum = BasicMath::sum($selfTeam->getAllRatings(), $meanGetter); $otherTeamMeanSum = BasicMath::sum($otherTeam->getAllRatings(), $meanGetter); - $varianceGetter = fn($currentRating) => BasicMath::square($currentRating->getStandardDeviation()); + $varianceGetter = fn ($currentRating) => BasicMath::square($currentRating->getStandardDeviation()); $c = sqrt( BasicMath::sum($selfTeam->getAllRatings(), $varianceGetter) @@ -153,9 +153,9 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator $betaSquared = BasicMath::square($gameInfo->getBeta()); - $meanGetter = fn($currentRating) => $currentRating->getMean(); + $meanGetter = fn ($currentRating) => $currentRating->getMean(); - $varianceGetter = fn($currentRating) => BasicMath::square($currentRating->getStandardDeviation()); + $varianceGetter = fn ($currentRating) => BasicMath::square($currentRating->getStandardDeviation()); $team1MeanSum = BasicMath::sum($team1Ratings, $meanGetter); $team1StdDevSquared = BasicMath::sum($team1Ratings, $varianceGetter); diff --git a/tests/TrueSkill/TrueSkillCalculatorTests.php b/tests/TrueSkill/TrueSkillCalculatorTests.php index 6070049..d51ff8e 100644 --- a/tests/TrueSkill/TrueSkillCalculatorTests.php +++ b/tests/TrueSkill/TrueSkillCalculatorTests.php @@ -989,7 +989,7 @@ class TrueSkillCalculatorTests private static function assertRating(TestCase $testClass, $expectedMean, $expectedStandardDeviation, $actual) { $testClass->assertEqualsWithDelta($expectedMean, $actual->getMean(), self::ERROR_TOLERANCE_TRUESKILL); - $testClass->assertEqualsWithDelta($expectedStandardDeviation, $actual->getStandardDeviation(),self::ERROR_TOLERANCE_TRUESKILL); + $testClass->assertEqualsWithDelta($expectedStandardDeviation, $actual->getStandardDeviation(), self::ERROR_TOLERANCE_TRUESKILL); } private static function assertMatchQuality(TestCase $testClass, $expectedMatchQuality, $actualMatchQuality)