From b38a9656ebd4ea45bfc9d6a880a1495db711281b Mon Sep 17 00:00:00 2001 From: Jens True Date: Tue, 15 Apr 2025 08:14:08 +0000 Subject: [PATCH] Much stricter coding standards for phpstan, phpstan and psalm. --- benchmark/BasicBench.php | 2 +- composer.lock | 53 ++++++++++--------- src/FactorGraphs/FactorList.php | 6 +-- src/FactorGraphs/KeyedVariable.php | 2 +- src/FactorGraphs/Message.php | 2 +- src/FactorGraphs/ScheduleLoop.php | 2 +- src/FactorGraphs/ScheduleSequence.php | 2 +- src/FactorGraphs/ScheduleStep.php | 2 +- src/FactorGraphs/VariableFactory.php | 4 +- src/GameInfo.php | 12 ++--- src/Guard.php | 4 +- src/HashMap.php | 2 +- src/Numerics/BasicMath.php | 2 +- src/Numerics/GaussianDistribution.php | 14 ++--- src/Numerics/IdentityMatrix.php | 2 +- src/Numerics/Matrix.php | 24 ++++----- src/Numerics/SquareMatrix.php | 2 +- src/Numerics/Vector.php | 2 +- src/PartialPlay.php | 2 +- src/Player.php | 8 +-- src/PlayersRange.php | 2 +- src/RankSorter.php | 2 +- src/Rating.php | 6 +-- src/Team.php | 2 +- src/TeamsRange.php | 2 +- src/TrueSkill/DrawMargin.php | 2 +- .../FactorGraphTrueSkillCalculator.php | 2 +- .../Factors/GaussianGreaterThanFactor.php | 2 +- .../Factors/GaussianLikelihoodFactor.php | 2 +- src/TrueSkill/Factors/GaussianPriorFactor.php | 2 +- .../Factors/GaussianWeightedSumFactor.php | 2 +- .../Factors/GaussianWithinFactor.php | 2 +- .../IteratedTeamDifferencesInnerLayer.php | 2 +- ...yerPerformancesToTeamPerformancesLayer.php | 4 +- .../Layers/PlayerPriorValuesToSkillsLayer.php | 2 +- .../PlayerSkillsToPerformancesLayer.php | 2 +- .../Layers/TeamDifferencesComparisonLayer.php | 2 +- ...ancesToTeamPerformanceDifferencesLayer.php | 2 +- src/TrueSkill/TrueSkillFactorGraph.php | 2 +- .../TruncatedGaussianCorrectionFunctions.php | 2 +- .../TwoPlayerTrueSkillCalculator.php | 14 ++--- src/TrueSkill/TwoTeamTrueSkillCalculator.php | 10 ++-- tests/FactorGraphs/VariableTest.php | 2 +- tests/GameInfoTest.php | 2 +- tests/GuardTest.php | 2 +- tests/HashMapTest.php | 2 +- tests/Numerics/BasicMathTest.php | 4 +- tests/Numerics/GaussianDistributionTest.php | 8 +-- tests/Numerics/MatrixTest.php | 4 +- tests/Numerics/RangeTest.php | 2 +- tests/PartialPlayTest.php | 2 +- tests/PlayerTest.php | 2 +- tests/RankSorterTest.php | 2 +- tests/RatingContainerTest.php | 2 +- tests/RatingTest.php | 2 +- tests/SkillCalculatorTest.php | 2 +- tests/TeamTest.php | 2 +- tests/TrueSkill/DrawMarginTest.php | 2 +- .../FactorGraphTrueSkillCalculatorTest.php | 2 +- tests/TrueSkill/TrueSkillCalculatorTests.php | 2 +- ...uncatedGaussianCorrectionFunctionsTest.php | 2 +- .../TwoPlayerTrueSkillCalculatorTest.php | 2 +- .../TwoTeamTrueSkillCalculatorTest.php | 2 +- 63 files changed, 137 insertions(+), 134 deletions(-) diff --git a/benchmark/BasicBench.php b/benchmark/BasicBench.php index 76c7182..57904f4 100644 --- a/benchmark/BasicBench.php +++ b/benchmark/BasicBench.php @@ -14,7 +14,7 @@ use DNW\Skills\Team; /** * Basic Benchmarks. */ -class BasicBench +final class BasicBench { /** * To benchmark performance when using TwoPlayerTrueSkillCalculator diff --git a/composer.lock b/composer.lock index 751e993..54188fc 100644 --- a/composer.lock +++ b/composer.lock @@ -1249,26 +1249,29 @@ }, { "name": "doctrine/deprecations", - "version": "1.1.4", + "version": "1.1.5", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "31610dbb31faa98e6b5447b62340826f54fbc4e9" + "reference": "459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/31610dbb31faa98e6b5447b62340826f54fbc4e9", - "reference": "31610dbb31faa98e6b5447b62340826f54fbc4e9", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38", + "reference": "459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, + "conflict": { + "phpunit/phpunit": "<=7.5 || >=13" + }, "require-dev": { - "doctrine/coding-standard": "^9 || ^12", - "phpstan/phpstan": "1.4.10 || 2.0.3", + "doctrine/coding-standard": "^9 || ^12 || ^13", + "phpstan/phpstan": "1.4.10 || 2.1.11", "phpstan/phpstan-phpunit": "^1.0 || ^2", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6 || ^10.5 || ^11.5 || ^12", "psr/log": "^1 || ^2 || ^3" }, "suggest": { @@ -1288,9 +1291,9 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/1.1.4" + "source": "https://github.com/doctrine/deprecations/tree/1.1.5" }, - "time": "2024-12-07T21:18:45+00:00" + "time": "2025-04-07T20:06:18+00:00" }, { "name": "felixfbecker/language-server-protocol", @@ -2117,16 +2120,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.6.1", + "version": "5.6.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8" + "reference": "92dde6a5919e34835c506ac8c523ef095a95ed62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8", - "reference": "e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/92dde6a5919e34835c506ac8c523ef095a95ed62", + "reference": "92dde6a5919e34835c506ac8c523ef095a95ed62", "shasum": "" }, "require": { @@ -2175,9 +2178,9 @@ "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.1" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.2" }, - "time": "2024-12-07T09:39:29+00:00" + "time": "2025-04-13T19:20:35+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -2744,16 +2747,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.5.15", + "version": "11.5.17", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "4b6a4ee654e5e0c5e1f17e2f83c0f4c91dee1f9c" + "reference": "fd2e863a2995cdfd864fb514b5e0b28b09895b5c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4b6a4ee654e5e0c5e1f17e2f83c0f4c91dee1f9c", - "reference": "4b6a4ee654e5e0c5e1f17e2f83c0f4c91dee1f9c", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fd2e863a2995cdfd864fb514b5e0b28b09895b5c", + "reference": "fd2e863a2995cdfd864fb514b5e0b28b09895b5c", "shasum": "" }, "require": { @@ -2825,7 +2828,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.15" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.17" }, "funding": [ { @@ -2841,7 +2844,7 @@ "type": "tidelift" } ], - "time": "2025-03-23T16:02:11+00:00" + "time": "2025-04-08T07:59:11+00:00" }, { "name": "psalm/plugin-phpunit", @@ -5137,12 +5140,12 @@ "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "1288d7a06a0c142cfdeabee8e597aa38a3fe4661" + "reference": "c65b0f026cd7c5d26587d4a939f3a35be49bd267" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/1288d7a06a0c142cfdeabee8e597aa38a3fe4661", - "reference": "1288d7a06a0c142cfdeabee8e597aa38a3fe4661", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/c65b0f026cd7c5d26587d4a939f3a35be49bd267", + "reference": "c65b0f026cd7c5d26587d4a939f3a35be49bd267", "shasum": "" }, "require": { @@ -5247,7 +5250,7 @@ "issues": "https://github.com/vimeo/psalm/issues", "source": "https://github.com/vimeo/psalm" }, - "time": "2025-03-31T10:16:55+00:00" + "time": "2025-04-09T09:51:06+00:00" }, { "name": "webmozart/assert", diff --git a/src/FactorGraphs/FactorList.php b/src/FactorGraphs/FactorList.php index 363a3fb..a31e0b4 100644 --- a/src/FactorGraphs/FactorList.php +++ b/src/FactorGraphs/FactorList.php @@ -7,7 +7,7 @@ namespace DNW\Skills\FactorGraphs; /** * Helper class for computing the factor graph's normalization constant. */ -class FactorList +final class FactorList { /** * @var Factor[] $list @@ -31,11 +31,11 @@ class FactorList $numberOfMessages = $factor->getNumberOfMessages(); for ($j = 0; $j < $numberOfMessages; ++$j) { - $sumLogZ += $factor->sendMessageIndex($j); + $sumLogZ += (float)$factor->sendMessageIndex($j); } } - $sumLogS = 0; + $sumLogS = 0.0; foreach ($list as &$currentFactor) { $sumLogS += $currentFactor->getLogNormalization(); diff --git a/src/FactorGraphs/KeyedVariable.php b/src/FactorGraphs/KeyedVariable.php index e6094fe..6a514ef 100644 --- a/src/FactorGraphs/KeyedVariable.php +++ b/src/FactorGraphs/KeyedVariable.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace DNW\Skills\FactorGraphs; -class KeyedVariable extends Variable +final class KeyedVariable extends Variable { public function __construct(private readonly mixed $key, mixed $prior) { diff --git a/src/FactorGraphs/Message.php b/src/FactorGraphs/Message.php index 7d7d40d..2add69a 100644 --- a/src/FactorGraphs/Message.php +++ b/src/FactorGraphs/Message.php @@ -6,7 +6,7 @@ namespace DNW\Skills\FactorGraphs; use DNW\Skills\Numerics\GaussianDistribution; -class Message +final class Message { public function __construct(private GaussianDistribution $value) { diff --git a/src/FactorGraphs/ScheduleLoop.php b/src/FactorGraphs/ScheduleLoop.php index ea5cf86..774877d 100644 --- a/src/FactorGraphs/ScheduleLoop.php +++ b/src/FactorGraphs/ScheduleLoop.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace DNW\Skills\FactorGraphs; -class ScheduleLoop extends Schedule +final class ScheduleLoop extends Schedule { public function __construct(private readonly Schedule $scheduleToLoop, private readonly float $maxDelta) { diff --git a/src/FactorGraphs/ScheduleSequence.php b/src/FactorGraphs/ScheduleSequence.php index 8c0df14..bf45dc1 100644 --- a/src/FactorGraphs/ScheduleSequence.php +++ b/src/FactorGraphs/ScheduleSequence.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace DNW\Skills\FactorGraphs; -class ScheduleSequence extends Schedule +final class ScheduleSequence extends Schedule { /** * @param Schedule[] $schedules diff --git a/src/FactorGraphs/ScheduleStep.php b/src/FactorGraphs/ScheduleStep.php index 7f18c1d..63edf5b 100644 --- a/src/FactorGraphs/ScheduleStep.php +++ b/src/FactorGraphs/ScheduleStep.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace DNW\Skills\FactorGraphs; -class ScheduleStep extends Schedule +final class ScheduleStep extends Schedule { public function __construct(private readonly Factor $factor, private readonly int $index) { diff --git a/src/FactorGraphs/VariableFactory.php b/src/FactorGraphs/VariableFactory.php index 7b43992..db8ee4a 100644 --- a/src/FactorGraphs/VariableFactory.php +++ b/src/FactorGraphs/VariableFactory.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace DNW\Skills\FactorGraphs; -class VariableFactory +final readonly class VariableFactory { - public function __construct(private readonly \Closure $varPriorInitializer) + public function __construct(private \Closure $varPriorInitializer) { } diff --git a/src/GameInfo.php b/src/GameInfo.php index 4afcc94..5de83fb 100644 --- a/src/GameInfo.php +++ b/src/GameInfo.php @@ -7,7 +7,7 @@ namespace DNW\Skills; /** * Parameters about the game for calculating the TrueSkill. */ -class GameInfo +final readonly class GameInfo { /** * Default initial mean / 6 @@ -26,11 +26,11 @@ class GameInfo private const float DEFAULT_INITIAL_STANDARD_DEVIATION = 8.3333333333333333333333333333333; public function __construct( - private readonly float $initialMean = self::DEFAULT_INITIAL_MEAN, - private readonly float $initialStdDev = self::DEFAULT_INITIAL_STANDARD_DEVIATION, - private readonly float $beta = self::DEFAULT_BETA, - private readonly float $dynamicsFactor = self::DEFAULT_DYNAMICS_FACTOR, - private readonly float $drawProbability = self::DEFAULT_DRAW_PROBABILITY + private float $initialMean = self::DEFAULT_INITIAL_MEAN, + private float $initialStdDev = self::DEFAULT_INITIAL_STANDARD_DEVIATION, + private float $beta = self::DEFAULT_BETA, + private float $dynamicsFactor = self::DEFAULT_DYNAMICS_FACTOR, + private float $drawProbability = self::DEFAULT_DRAW_PROBABILITY ) { } diff --git a/src/Guard.php b/src/Guard.php index 01b748b..96a7d9e 100644 --- a/src/Guard.php +++ b/src/Guard.php @@ -11,7 +11,7 @@ use Exception; * * @see http://www.moserware.com/2008/01/borrowing-ideas-from-3-interesting.html */ -class Guard +final class Guard { public static function argumentIsValidIndex(int $index, int $count, string $parameterName): void { @@ -23,7 +23,7 @@ class Guard public static function argumentInRangeInclusive(float $value, float $min, float $max, string $parameterName): void { if (($value < $min) || ($value > $max)) { - throw new Exception($parameterName . ' is not in the valid range [' . $min . ', ' . $max . ']'); + throw new Exception($parameterName . ' is not in the valid range [' . (int)$min . ', ' . (int)$max . ']'); } } } diff --git a/src/HashMap.php b/src/HashMap.php index 56e3f1b..cde306a 100644 --- a/src/HashMap.php +++ b/src/HashMap.php @@ -7,7 +7,7 @@ namespace DNW\Skills; /** * Basic hashmap that supports object keys. */ -class HashMap +final class HashMap { /** * @var mixed[] $hashToValue diff --git a/src/Numerics/BasicMath.php b/src/Numerics/BasicMath.php index a9faf69..9af4882 100644 --- a/src/Numerics/BasicMath.php +++ b/src/Numerics/BasicMath.php @@ -10,7 +10,7 @@ namespace DNW\Skills\Numerics; * @author Jeff Moser * @copyright 2010 Jeff Moser */ -class BasicMath +final class BasicMath { /** * Squares the input (input^2 = input * input) diff --git a/src/Numerics/GaussianDistribution.php b/src/Numerics/GaussianDistribution.php index cff1d5f..dd4d6fe 100644 --- a/src/Numerics/GaussianDistribution.php +++ b/src/Numerics/GaussianDistribution.php @@ -10,7 +10,7 @@ namespace DNW\Skills\Numerics; * @author Jeff Moser * @copyright 2010 Jeff Moser */ -class GaussianDistribution +final class GaussianDistribution { private const float DEFAULT_STANDARD_DEVIATION = 1.0; @@ -171,7 +171,7 @@ class GaussianDistribution $meanDifference = $numerator->mean - $denominator->mean; return log($denominator->variance) + self::M_LOG_SQRT_2_PI - log($varianceDifference) / 2.0 + - BasicMath::square($meanDifference) / (2 * $varianceDifference); + BasicMath::square($meanDifference) / (2.0 * $varianceDifference); } public static function at(float $var, float $mean = 0.0, float $standardDeviation = 1.0): float @@ -182,7 +182,7 @@ class GaussianDistribution // stdDev * sqrt(2*pi) $multiplier = 1.0 / ($standardDeviation * self::M_SQRT_2_PI); - $expPart = exp((-1.0 * BasicMath::square($var - $mean)) / (2 * BasicMath::square($standardDeviation))); + $expPart = exp((-1.0 * BasicMath::square($var - $mean)) / (2.0 * BasicMath::square($standardDeviation))); return $multiplier * $expPart; } @@ -200,7 +200,7 @@ class GaussianDistribution $z = abs($var); $t = 2.0 / (2.0 + $z); - $ty = 4 * $t - 2; + $ty = 4.0 * $t - 2.0; $coefficients = [ -1.3026537197817094, @@ -259,8 +259,8 @@ class GaussianDistribution return 100; } - $pp = ($p < 1.0) ? $p : 2 - $p; - $t = sqrt(-2 * log($pp / 2.0)); // Initial guess + $pp = ($p < 1.0) ? $p : 2.0 - $p; + $t = sqrt(-2.0 * log($pp / 2.0)); // Initial guess $x = -M_SQRT1_2 * ((2.30753 + $t * 0.27061) / (1.0 + $t * (0.99229 + $t * 0.04481)) - $t); for ($j = 0; $j < 2; ++$j) { @@ -274,6 +274,6 @@ class GaussianDistribution public static function inverseCumulativeTo(float $var, float $mean = 0.0, float $standardDeviation = 1.0): float { // From numerical recipes, page 320 - return $mean - M_SQRT2 * $standardDeviation * GaussianDistribution::inverseErrorFunctionCumulativeTo(2 * $var); + return $mean - M_SQRT2 * $standardDeviation * GaussianDistribution::inverseErrorFunctionCumulativeTo(2.0 * $var); } } diff --git a/src/Numerics/IdentityMatrix.php b/src/Numerics/IdentityMatrix.php index 57c32a6..02ecf31 100644 --- a/src/Numerics/IdentityMatrix.php +++ b/src/Numerics/IdentityMatrix.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace DNW\Skills\Numerics; -class IdentityMatrix extends DiagonalMatrix +final class IdentityMatrix extends DiagonalMatrix { public function __construct(int $rows) { diff --git a/src/Numerics/Matrix.php b/src/Numerics/Matrix.php index 533227f..daaceca 100644 --- a/src/Numerics/Matrix.php +++ b/src/Numerics/Matrix.php @@ -130,10 +130,10 @@ class Matrix // | a b | // | c d | // The determinant is ad - bc - $a = $this->getValue(0, 0); - $b = $this->getValue(0, 1); - $c = $this->getValue(1, 0); - $d = $this->getValue(1, 1); + $a = (float)$this->getValue(0, 0); + $b = (float)$this->getValue(0, 1); + $c = (float)$this->getValue(1, 0); + $d = (float)$this->getValue(1, 1); return $a * $d - $b * $c; } @@ -148,7 +148,7 @@ class Matrix // I expand along the first row for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) { - $firstRowColValue = $this->getValue(0, $currentColumn); + $firstRowColValue = (float)$this->getValue(0, $currentColumn); $cofactor = $this->getCofactor(0, $currentColumn); $itemToAdd = $firstRowColValue * $cofactor; $result += $itemToAdd; @@ -201,7 +201,7 @@ class Matrix public function getInverse(): Matrix|SquareMatrix { if (($this->rowCount == 1) && ($this->columnCount == 1)) { - return new SquareMatrix(1.0 / $this->getValue(0, 0)); + return new SquareMatrix(1.0 / (float)$this->getValue(0, 0)); } // Take the simple approach: @@ -240,9 +240,9 @@ class Matrix for ($currentRow = 0; $currentRow < $left->getRowCount(); ++$currentRow) { for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); ++$currentColumn) { $resultMatrix[$currentRow][$currentColumn] = - $left->getValue($currentRow, $currentColumn) + (float)$left->getValue($currentRow, $currentColumn) + - $right->getValue($currentRow, $currentColumn); + (float)$right->getValue($currentRow, $currentColumn); } } @@ -268,8 +268,8 @@ class Matrix $productValue = 0; for ($vectorIndex = 0; $vectorIndex < $left->getColumnCount(); ++$vectorIndex) { - $leftValue = $left->getValue($currentRow, $vectorIndex); - $rightValue = $right->getValue($vectorIndex, $currentColumn); + $leftValue = (float)$left->getValue($currentRow, $vectorIndex); + $rightValue = (float)$right->getValue($vectorIndex, $currentColumn); $vectorIndexProduct = $leftValue * $rightValue; $productValue += $vectorIndexProduct; } @@ -339,8 +339,8 @@ class Matrix for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) { $delta = abs( - $this->getValue($currentRow, $currentColumn) - - $otherMatrix->getValue($currentRow, $currentColumn) + (float)$this->getValue($currentRow, $currentColumn) - + (float)$otherMatrix->getValue($currentRow, $currentColumn) ); if ($delta > self::ERROR_TOLERANCE) { diff --git a/src/Numerics/SquareMatrix.php b/src/Numerics/SquareMatrix.php index 1d68948..839984b 100644 --- a/src/Numerics/SquareMatrix.php +++ b/src/Numerics/SquareMatrix.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace DNW\Skills\Numerics; -class SquareMatrix extends Matrix +final class SquareMatrix extends Matrix { public function __construct(float|int ...$allValues) { diff --git a/src/Numerics/Vector.php b/src/Numerics/Vector.php index a6422ab..a7cf35a 100644 --- a/src/Numerics/Vector.php +++ b/src/Numerics/Vector.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace DNW\Skills\Numerics; -class Vector extends Matrix +final class Vector extends Matrix { /** * @param float[] $vectorValues diff --git a/src/PartialPlay.php b/src/PartialPlay.php index 1704f8d..70063b9 100644 --- a/src/PartialPlay.php +++ b/src/PartialPlay.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace DNW\Skills; -class PartialPlay +final class PartialPlay { public static function getPartialPlayPercentage(Player $player): float { diff --git a/src/Player.php b/src/Player.php index 9816f69..0c63861 100644 --- a/src/Player.php +++ b/src/Player.php @@ -7,15 +7,15 @@ namespace DNW\Skills; /** * Represents a player who has a Rating. */ -class Player implements ISupportPartialPlay, ISupportPartialUpdate +final readonly class Player implements ISupportPartialPlay, ISupportPartialUpdate { private const float DEFAULT_PARTIAL_PLAY_PERCENTAGE = 1.0; // = 100% play time private const float DEFAULT_PARTIAL_UPDATE_PERCENTAGE = 1.0; - private readonly float $PartialPlayPct; + private float $PartialPlayPct; - private readonly float $PartialUpdatePct; + private float $PartialUpdatePct; /** * Constructs a player. @@ -25,7 +25,7 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate * @param float $partialUpdatePct Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update. */ public function __construct( - private readonly mixed $Id, + private mixed $Id, float $partialPlayPct = self::DEFAULT_PARTIAL_PLAY_PERCENTAGE, float $partialUpdatePct = self::DEFAULT_PARTIAL_UPDATE_PERCENTAGE ) diff --git a/src/PlayersRange.php b/src/PlayersRange.php index a921603..44f53d3 100644 --- a/src/PlayersRange.php +++ b/src/PlayersRange.php @@ -6,6 +6,6 @@ namespace DNW\Skills; use DNW\Skills\Numerics\Range; -class PlayersRange extends Range +final class PlayersRange extends Range { } diff --git a/src/RankSorter.php b/src/RankSorter.php index 3f75a97..050fb08 100644 --- a/src/RankSorter.php +++ b/src/RankSorter.php @@ -7,7 +7,7 @@ namespace DNW\Skills; /** * Helper class to sort ranks in non-decreasing order. */ -class RankSorter +final class RankSorter { /** * Performs an in-place sort of the items in according to the ranks in non-decreasing order. diff --git a/src/Rating.php b/src/Rating.php index e1fe7bc..8ff049e 100644 --- a/src/Rating.php +++ b/src/Rating.php @@ -9,7 +9,7 @@ use DNW\Skills\Numerics\GaussianDistribution; /** * Container for a player's rating. */ -class Rating +final readonly class Rating { private const float CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER = 3; @@ -18,9 +18,9 @@ class 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 $conservativeStandardDeviationMultiplier optional The number of standardDeviations to subtract from the mean to achieve a conservative rating. */ - public function __construct(private readonly float $mean, private readonly float $standardDeviation, private readonly float|int $conservativeStandardDeviationMultiplier = self::CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER) + public function __construct(private float $mean, private float $standardDeviation, private float $conservativeStandardDeviationMultiplier = self::CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER) { } diff --git a/src/Team.php b/src/Team.php index b49f0fe..746a300 100644 --- a/src/Team.php +++ b/src/Team.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace DNW\Skills; -class Team extends RatingContainer +final class Team extends RatingContainer { public function __construct(?Player $player = NULL, ?Rating $rating = NULL) { diff --git a/src/TeamsRange.php b/src/TeamsRange.php index 79d5fb5..085113c 100644 --- a/src/TeamsRange.php +++ b/src/TeamsRange.php @@ -6,6 +6,6 @@ namespace DNW\Skills; use DNW\Skills\Numerics\Range; -class TeamsRange extends Range +final class TeamsRange extends Range { } diff --git a/src/TrueSkill/DrawMargin.php b/src/TrueSkill/DrawMargin.php index c3fdcc5..ddd1532 100644 --- a/src/TrueSkill/DrawMargin.php +++ b/src/TrueSkill/DrawMargin.php @@ -18,6 +18,6 @@ final class DrawMargin // // margin = inversecdf((draw probability + 1)/2) * sqrt(n1+n2) * beta // n1 and n2 are the number of players on each team - return GaussianDistribution::inverseCumulativeTo(.5 * ($drawProbability + 1), 0, 1) * M_SQRT2 * $beta; + return GaussianDistribution::inverseCumulativeTo(0.5 * ($drawProbability + 1.0), 0.0, 1.0) * M_SQRT2 * $beta; } } diff --git a/src/TrueSkill/FactorGraphTrueSkillCalculator.php b/src/TrueSkill/FactorGraphTrueSkillCalculator.php index 779f833..d7e9121 100644 --- a/src/TrueSkill/FactorGraphTrueSkillCalculator.php +++ b/src/TrueSkill/FactorGraphTrueSkillCalculator.php @@ -22,7 +22,7 @@ use DNW\Skills\Rating; /** * Calculates TrueSkill using a full factor graph. */ -class FactorGraphTrueSkillCalculator extends SkillCalculator +final class FactorGraphTrueSkillCalculator extends SkillCalculator { public function __construct() { diff --git a/src/TrueSkill/Factors/GaussianGreaterThanFactor.php b/src/TrueSkill/Factors/GaussianGreaterThanFactor.php index 6ec1ca7..c6e9c74 100644 --- a/src/TrueSkill/Factors/GaussianGreaterThanFactor.php +++ b/src/TrueSkill/Factors/GaussianGreaterThanFactor.php @@ -14,7 +14,7 @@ use DNW\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions; * * See the accompanying math paper for more details. */ -class GaussianGreaterThanFactor extends GaussianFactor +final class GaussianGreaterThanFactor extends GaussianFactor { public function __construct(private readonly float $epsilon, Variable $variable) { diff --git a/src/TrueSkill/Factors/GaussianLikelihoodFactor.php b/src/TrueSkill/Factors/GaussianLikelihoodFactor.php index eb08e54..16fac28 100644 --- a/src/TrueSkill/Factors/GaussianLikelihoodFactor.php +++ b/src/TrueSkill/Factors/GaussianLikelihoodFactor.php @@ -15,7 +15,7 @@ use Exception; * * See the accompanying math paper for more details. */ -class GaussianLikelihoodFactor extends GaussianFactor +final class GaussianLikelihoodFactor extends GaussianFactor { private readonly float $precision; diff --git a/src/TrueSkill/Factors/GaussianPriorFactor.php b/src/TrueSkill/Factors/GaussianPriorFactor.php index d88ef54..7327675 100644 --- a/src/TrueSkill/Factors/GaussianPriorFactor.php +++ b/src/TrueSkill/Factors/GaussianPriorFactor.php @@ -13,7 +13,7 @@ use DNW\Skills\Numerics\GaussianDistribution; * * See the accompanying math paper for more details. */ -class GaussianPriorFactor extends GaussianFactor +final class GaussianPriorFactor extends GaussianFactor { private readonly GaussianDistribution $newMessage; diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index 4125ce4..61a8ad8 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -16,7 +16,7 @@ use DNW\Skills\Numerics\GaussianDistribution; * * See the accompanying math paper for more details. */ -class GaussianWeightedSumFactor extends GaussianFactor +final class GaussianWeightedSumFactor extends GaussianFactor { /** * @var array $varIndexOrdersForWeights diff --git a/src/TrueSkill/Factors/GaussianWithinFactor.php b/src/TrueSkill/Factors/GaussianWithinFactor.php index 7142965..967253c 100644 --- a/src/TrueSkill/Factors/GaussianWithinFactor.php +++ b/src/TrueSkill/Factors/GaussianWithinFactor.php @@ -14,7 +14,7 @@ use DNW\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions; * * See the accompanying math paper for more details. */ -class GaussianWithinFactor extends GaussianFactor +final class GaussianWithinFactor extends GaussianFactor { public function __construct(private readonly float $epsilon, Variable $variable) { diff --git a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php index 36333f2..5b53d6c 100644 --- a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php +++ b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php @@ -11,7 +11,7 @@ use DNW\Skills\TrueSkill\TrueSkillFactorGraph; use Exception; // The whole purpose of this is to do a loop on the bottom -class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer +final class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer { public function __construct( TrueSkillFactorGraph $parentGraph, diff --git a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php index 318ed24..bda95ac 100644 --- a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php @@ -11,7 +11,7 @@ use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor; use DNW\Skills\FactorGraphs\Variable; use DNW\Skills\FactorGraphs\KeyedVariable; -class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer +final class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer { #[\Override] public function buildLayer(): void @@ -51,7 +51,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye /** * @param KeyedVariable[] $teamMembers */ - protected function createPlayerToTeamSumFactor(array $teamMembers, Variable $sumVariable): GaussianWeightedSumFactor + private function createPlayerToTeamSumFactor(array $teamMembers, Variable $sumVariable): GaussianWeightedSumFactor { $weights = array_map( static function ($v): float { diff --git a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php index 762dc92..6d9bfaf 100644 --- a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php +++ b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php @@ -17,7 +17,7 @@ use DNW\Skills\FactorGraphs\ScheduleSequence; // We intentionally have no Posterior schedule since the only purpose here is to // start the process. -class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer +final class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer { /** * @param Team[] $teams diff --git a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php index cf92a0f..acb0190 100644 --- a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php @@ -11,7 +11,7 @@ use DNW\Skills\Numerics\BasicMath; use DNW\Skills\TrueSkill\Factors\GaussianLikelihoodFactor; use DNW\Skills\FactorGraphs\ScheduleSequence; -class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer +final class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer { #[\Override] public function buildLayer(): void diff --git a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php index 163cf1a..851d8f5 100644 --- a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php +++ b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php @@ -9,7 +9,7 @@ use DNW\Skills\TrueSkill\Factors\GaussianGreaterThanFactor; use DNW\Skills\TrueSkill\Factors\GaussianWithinFactor; use DNW\Skills\TrueSkill\TrueSkillFactorGraph; -class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer +final class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer { private readonly float $epsilon; diff --git a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php index ba47505..d8d37fd 100644 --- a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php +++ b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php @@ -7,7 +7,7 @@ namespace DNW\Skills\TrueSkill\Layers; use DNW\Skills\FactorGraphs\Variable; use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor; -class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer +final class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorGraphLayer { #[\Override] public function buildLayer(): void diff --git a/src/TrueSkill/TrueSkillFactorGraph.php b/src/TrueSkill/TrueSkillFactorGraph.php index 7cfe6d4..db70b95 100644 --- a/src/TrueSkill/TrueSkillFactorGraph.php +++ b/src/TrueSkill/TrueSkillFactorGraph.php @@ -23,7 +23,7 @@ use DNW\Skills\TrueSkill\Layers\PlayerSkillsToPerformancesLayer; use DNW\Skills\TrueSkill\Layers\TeamDifferencesComparisonLayer; use DNW\Skills\TrueSkill\Layers\TeamPerformancesToTeamPerformanceDifferencesLayer; -class TrueSkillFactorGraph extends FactorGraph +final class TrueSkillFactorGraph extends FactorGraph { /** * @var FactorGraphLayer[] $layers diff --git a/src/TrueSkill/TruncatedGaussianCorrectionFunctions.php b/src/TrueSkill/TruncatedGaussianCorrectionFunctions.php index 6b0d4bd..74702cd 100644 --- a/src/TrueSkill/TruncatedGaussianCorrectionFunctions.php +++ b/src/TrueSkill/TruncatedGaussianCorrectionFunctions.php @@ -6,7 +6,7 @@ namespace DNW\Skills\TrueSkill; use DNW\Skills\Numerics\GaussianDistribution; -class TruncatedGaussianCorrectionFunctions +final class TruncatedGaussianCorrectionFunctions { // These functions from the bottom of page 4 of the TrueSkill paper. diff --git a/src/TrueSkill/TwoPlayerTrueSkillCalculator.php b/src/TrueSkill/TwoPlayerTrueSkillCalculator.php index f4e7819..0d03c65 100644 --- a/src/TrueSkill/TwoPlayerTrueSkillCalculator.php +++ b/src/TrueSkill/TwoPlayerTrueSkillCalculator.php @@ -21,7 +21,7 @@ use DNW\Skills\TeamsRange; * When you only have two players, a lot of the math simplifies. The main purpose of this class * is to show the bare minimum of what a TrueSkill implementation should have. */ -class TwoPlayerTrueSkillCalculator extends SkillCalculator +final class TwoPlayerTrueSkillCalculator extends SkillCalculator { public function __construct() { @@ -95,7 +95,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator + BasicMath::square($opponentRating->getStandardDeviation()) + - 2 * BasicMath::square($gameInfo->getBeta()) + 2.0 * BasicMath::square($gameInfo->getBeta()) ); $winningMean = $selfRating->getMean(); @@ -131,7 +131,7 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator $stdDevMultiplier = $varianceWithDynamics / BasicMath::square($c); $newMean = $selfRating->getMean() + ($rankMultiplier * $meanMultiplier * $v); - $newStdDev = sqrt($varianceWithDynamics * (1 - $w * $stdDevMultiplier)); + $newStdDev = sqrt($varianceWithDynamics * (1.0 - $w * $stdDevMultiplier)); return new Rating($newMean, $newStdDev); } @@ -160,16 +160,16 @@ class TwoPlayerTrueSkillCalculator extends SkillCalculator // This is the square root part of the equation: $sqrtPart = sqrt( - (2 * $betaSquared) + (2.0 * $betaSquared) / - (2 * $betaSquared + $player1SigmaSquared + $player2SigmaSquared) + (2.0 * $betaSquared + $player1SigmaSquared + $player2SigmaSquared) ); // This is the exponent part of the equation: $expPart = exp( - (-1 * BasicMath::square($player1Rating->getMean() - $player2Rating->getMean())) + (-1.0 * BasicMath::square($player1Rating->getMean() - $player2Rating->getMean())) / - (2 * (2 * $betaSquared + $player1SigmaSquared + $player2SigmaSquared)) + (2.0 * (2.0 * $betaSquared + $player1SigmaSquared + $player2SigmaSquared)) ); return $sqrtPart * $expPart; diff --git a/src/TrueSkill/TwoTeamTrueSkillCalculator.php b/src/TrueSkill/TwoTeamTrueSkillCalculator.php index 6c5d89c..a174918 100644 --- a/src/TrueSkill/TwoTeamTrueSkillCalculator.php +++ b/src/TrueSkill/TwoTeamTrueSkillCalculator.php @@ -21,7 +21,7 @@ use DNW\Skills\TeamsRange; * * When you only have two teams, the math is still simple: no factor graphs are used yet. */ -class TwoTeamTrueSkillCalculator extends SkillCalculator +final class TwoTeamTrueSkillCalculator extends SkillCalculator { public function __construct() { @@ -122,7 +122,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator // assume draw $v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wWithinMarginScaled($meanDelta, $drawMargin, $c); - $rankMultiplier = 1; + $rankMultiplier = 1.0; } $selfTeamAllPlayers = $selfTeam->getAllPlayers(); @@ -137,7 +137,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator $newMean = $previousPlayerRating->getMean() + $playerMeanDelta; $newStdDev = sqrt( - (BasicMath::square($previousPlayerRating->getStandardDeviation()) + $tauSquared) * (1 - $w * $stdDevMultiplier) + (BasicMath::square($previousPlayerRating->getStandardDeviation()) + $tauSquared) * (1.0 - $w * $stdDevMultiplier) ); $newPlayerRatings->setRating($localSelfTeamCurPlayer, new Rating($newMean, $newStdDev)); @@ -184,9 +184,9 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator ); $expPart = exp( - (-1 * BasicMath::square($team1MeanSum - $team2MeanSum)) + (-1.0 * BasicMath::square($team1MeanSum - $team2MeanSum)) / - (2 * ($totalPlayers * $betaSquared + $team1StdDevSquared + $team2StdDevSquared)) + (2.0 * ($totalPlayers * $betaSquared + $team1StdDevSquared + $team2StdDevSquared)) ); return $expPart * $sqrtPart; diff --git a/tests/FactorGraphs/VariableTest.php b/tests/FactorGraphs/VariableTest.php index 8fad3d6..30d5b29 100644 --- a/tests/FactorGraphs/VariableTest.php +++ b/tests/FactorGraphs/VariableTest.php @@ -12,7 +12,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[CoversClass(Variable::class)] #[UsesClass(GaussianDistribution::class)] -class VariableTest extends TestCase +final class VariableTest extends TestCase { public function testGetterSetter(): void { diff --git a/tests/GameInfoTest.php b/tests/GameInfoTest.php index 621af32..09f3998 100644 --- a/tests/GameInfoTest.php +++ b/tests/GameInfoTest.php @@ -12,7 +12,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[CoversClass(GameInfo::class)] #[UsesClass(Rating::class)] -class GameInfoTest extends TestCase +final class GameInfoTest extends TestCase { public function testMembers(): void { diff --git a/tests/GuardTest.php b/tests/GuardTest.php index df9f9d1..5d5a760 100644 --- a/tests/GuardTest.php +++ b/tests/GuardTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(Guard::class)] -class GuardTest extends TestCase +final class GuardTest extends TestCase { public function testargumentIsValidIndexArgumentAbove(): void { diff --git a/tests/HashMapTest.php b/tests/HashMapTest.php index 052d333..d242950 100644 --- a/tests/HashMapTest.php +++ b/tests/HashMapTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use stdClass; #[CoversClass(HashMap::class)] -class HashMapTest extends TestCase +final class HashMapTest extends TestCase { public function testHashmap(): void { diff --git a/tests/Numerics/BasicMathTest.php b/tests/Numerics/BasicMathTest.php index a79b6af..078b05b 100644 --- a/tests/Numerics/BasicMathTest.php +++ b/tests/Numerics/BasicMathTest.php @@ -9,7 +9,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(BasicMath::class)] -class BasicMathTest extends TestCase +final class BasicMathTest extends TestCase { public function testSquare(): void { @@ -23,7 +23,7 @@ class BasicMathTest extends TestCase $arr = [1, 1, 1, 1]; $func_return = static fn(float $f): float => $f; - $func_double = static fn(float $f): float => $f * 2; + $func_double = static fn(float $f): float => $f * 2.0; $this->assertEquals(4, BasicMath::sum($arr, $func_return)); $this->assertEquals(8, BasicMath::sum($arr, $func_double)); } diff --git a/tests/Numerics/GaussianDistributionTest.php b/tests/Numerics/GaussianDistributionTest.php index d2660e9..9614fb4 100644 --- a/tests/Numerics/GaussianDistributionTest.php +++ b/tests/Numerics/GaussianDistributionTest.php @@ -12,7 +12,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[CoversClass(GaussianDistribution::class)] #[UsesClass(BasicMath::class)] -class GaussianDistributionTest extends TestCase +final class GaussianDistributionTest extends TestCase { private const float ERROR_TOLERANCE = 0.000001; @@ -24,7 +24,7 @@ class GaussianDistributionTest extends TestCase $this->assertEquals(9, $gd->getVariance()); $this->assertEquals(3, $gd->getStandardDeviation()); $this->assertEquals(1 / 9, $gd->getPrecision()); - $this->assertEquals(1 / 9 * 10, $gd->getPrecisionMean()); + $this->assertEquals(1.0 / 9.0 * 10.0, $gd->getPrecisionMean()); $this->assertEqualsWithDelta(0.13298076013, $gd->getNormalizationConstant(), GaussianDistributionTest::ERROR_TOLERANCE); } @@ -57,7 +57,7 @@ class GaussianDistributionTest extends TestCase $product2 = GaussianDistribution::multiply($m4s5, $m6s7); - $expectedMean = (4 * BasicMath::square(7) + 6 * BasicMath::square(5)) / (BasicMath::square(5) + BasicMath::square(7)); + $expectedMean = (4.0 * BasicMath::square(7) + 6.0 * BasicMath::square(5)) / (BasicMath::square(5) + BasicMath::square(7)); $this->assertEqualsWithDelta($expectedMean, $product2->getMean(), GaussianDistributionTest::ERROR_TOLERANCE); $expectedSigma = sqrt(((BasicMath::square(5) * BasicMath::square(7)) / (BasicMath::square(5) + BasicMath::square(7)))); @@ -74,7 +74,7 @@ class GaussianDistributionTest extends TestCase $this->assertEqualsWithDelta(2.0, $productDividedByStandardNormal->getMean(), GaussianDistributionTest::ERROR_TOLERANCE); $this->assertEqualsWithDelta(3.0, $productDividedByStandardNormal->getStandardDeviation(), GaussianDistributionTest::ERROR_TOLERANCE); - $product2 = new GaussianDistribution((4 * BasicMath::square(7) + 6 * BasicMath::square(5)) / (BasicMath::square(5) + BasicMath::square(7)), sqrt(((BasicMath::square(5) * BasicMath::square(7)) / (BasicMath::square(5) + BasicMath::square(7))))); + $product2 = new GaussianDistribution((4.0 * BasicMath::square(7) + 6.0 * BasicMath::square(5)) / (BasicMath::square(5) + BasicMath::square(7)), sqrt(((BasicMath::square(5) * BasicMath::square(7)) / (BasicMath::square(5) + BasicMath::square(7))))); $m4s5 = new GaussianDistribution(4, 5); $product2DividedByM4S5 = GaussianDistribution::divide($product2, $m4s5); $this->assertEqualsWithDelta(6.0, $product2DividedByM4S5->getMean(), GaussianDistributionTest::ERROR_TOLERANCE); diff --git a/tests/Numerics/MatrixTest.php b/tests/Numerics/MatrixTest.php index d6c7541..2dc4d0e 100644 --- a/tests/Numerics/MatrixTest.php +++ b/tests/Numerics/MatrixTest.php @@ -20,7 +20,7 @@ use Exception; #[CoversClass(DiagonalMatrix::class)] #[CoversClass(Vector::class)] // phpcs:disable PSR2.Methods.FunctionCallSignature,Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma -class MatrixTest extends TestCase +final class MatrixTest extends TestCase { public function testEmptyMatrix(): void { @@ -295,7 +295,7 @@ class MatrixTest extends TestCase 1, 0, 6); $cInverse = $c->getInverse(); - $d = Matrix::scalarMultiply((1.0 / 22), new SquareMatrix(24, -12, -2, + $d = Matrix::scalarMultiply((1.0 / 22.0), new SquareMatrix(24, -12, -2, 5, 3, -5, -4, 2, 4)); diff --git a/tests/Numerics/RangeTest.php b/tests/Numerics/RangeTest.php index 5eec974..d9a1660 100644 --- a/tests/Numerics/RangeTest.php +++ b/tests/Numerics/RangeTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use Exception; #[CoversClass(Range::class)] -class RangeTest extends TestCase +final class RangeTest extends TestCase { public function testConstructInvalidParam(): void { diff --git a/tests/PartialPlayTest.php b/tests/PartialPlayTest.php index c5925cc..e0d560f 100644 --- a/tests/PartialPlayTest.php +++ b/tests/PartialPlayTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[CoversClass(PartialPlay::class)] #[UsesClass(Player::class)] #[UsesClass(Guard::class)] -class PartialPlayTest extends TestCase +final class PartialPlayTest extends TestCase { public function testgetPartialPlayPercentage(): void { diff --git a/tests/PlayerTest.php b/tests/PlayerTest.php index 82092be..56fc080 100644 --- a/tests/PlayerTest.php +++ b/tests/PlayerTest.php @@ -12,7 +12,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[CoversClass(Player::class)] #[UsesClass(Guard::class)] -class PlayerTest extends TestCase +final class PlayerTest extends TestCase { public function testPlayerObjectGetterSetter(): void { diff --git a/tests/RankSorterTest.php b/tests/RankSorterTest.php index 87db13a..42660ea 100644 --- a/tests/RankSorterTest.php +++ b/tests/RankSorterTest.php @@ -9,7 +9,7 @@ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\Attributes\CoversClass; #[CoversClass(RankSorter::class)] -class RankSorterTest extends TestCase +final class RankSorterTest extends TestCase { public function testSort(): void { diff --git a/tests/RatingContainerTest.php b/tests/RatingContainerTest.php index d93e564..45b73ba 100644 --- a/tests/RatingContainerTest.php +++ b/tests/RatingContainerTest.php @@ -18,7 +18,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[UsesClass(Player::class)] #[UsesClass(Rating::class)] #[UsesClass(Guard::class)] -class RatingContainerTest extends TestCase +final class RatingContainerTest extends TestCase { public function testRatingContainer(): void { diff --git a/tests/RatingTest.php b/tests/RatingTest.php index 1689edc..6d97198 100644 --- a/tests/RatingTest.php +++ b/tests/RatingTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[CoversClass(Rating::class)] #[UsesClass(BasicMath::class)] #[UsesClass(GaussianDistribution::class)] -class RatingTest extends TestCase +final class RatingTest extends TestCase { public function testGetRatingParameters(): void { diff --git a/tests/SkillCalculatorTest.php b/tests/SkillCalculatorTest.php index 8a79431..b2dc32f 100644 --- a/tests/SkillCalculatorTest.php +++ b/tests/SkillCalculatorTest.php @@ -17,7 +17,7 @@ use PHPUnit\Framework\Attributes\RequiresPhpunit; #[UsesClass(PlayersRange::class)] #[UsesClass(TeamsRange::class)] #[RequiresPhpunit('<12.0')] -class SkillCalculatorTest extends TestCase +final class SkillCalculatorTest extends TestCase { public function testisSupported(): void { diff --git a/tests/TeamTest.php b/tests/TeamTest.php index 62770cf..0436f9a 100644 --- a/tests/TeamTest.php +++ b/tests/TeamTest.php @@ -20,7 +20,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[UsesClass(Player::class)] #[UsesClass(Rating::class)] #[UsesClass(Guard::class)] -class TeamTest extends TestCase +final class TeamTest extends TestCase { public function testTeam(): void { diff --git a/tests/TrueSkill/DrawMarginTest.php b/tests/TrueSkill/DrawMarginTest.php index 228f7c7..a90c513 100644 --- a/tests/TrueSkill/DrawMarginTest.php +++ b/tests/TrueSkill/DrawMarginTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[CoversClass(DrawMargin::class)] #[UsesClass(BasicMath::class)] #[UsesClass(GaussianDistribution::class)] -class DrawMarginTest extends TestCase +final class DrawMarginTest extends TestCase { private const float ERROR_TOLERANCE = 0.000001; diff --git a/tests/TrueSkill/FactorGraphTrueSkillCalculatorTest.php b/tests/TrueSkill/FactorGraphTrueSkillCalculatorTest.php index 9c412ec..5058701 100644 --- a/tests/TrueSkill/FactorGraphTrueSkillCalculatorTest.php +++ b/tests/TrueSkill/FactorGraphTrueSkillCalculatorTest.php @@ -19,7 +19,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[UsesClass(\DNW\Skills\PlayersRange::class)] #[UsesClass(\DNW\Skills\SkillCalculator::class)] #[UsesClass(\DNW\Skills\TeamsRange::class)] -class FactorGraphTrueSkillCalculatorTest extends TestCase +final class FactorGraphTrueSkillCalculatorTest extends TestCase { #[CoversNothing] public function testMicrosoftResearchExample(): void diff --git a/tests/TrueSkill/TrueSkillCalculatorTests.php b/tests/TrueSkill/TrueSkillCalculatorTests.php index a8c00a3..ae6f2df 100644 --- a/tests/TrueSkill/TrueSkillCalculatorTests.php +++ b/tests/TrueSkill/TrueSkillCalculatorTests.php @@ -11,7 +11,7 @@ use DNW\Skills\SkillCalculator; use DNW\Skills\Team; use PHPUnit\Framework\TestCase; -class TrueSkillCalculatorTests +final class TrueSkillCalculatorTests { private const float ERROR_TOLERANCE_TRUESKILL = 0.085; diff --git a/tests/TrueSkill/TruncatedGaussianCorrectionFunctionsTest.php b/tests/TrueSkill/TruncatedGaussianCorrectionFunctionsTest.php index 292d4ba..5d22970 100644 --- a/tests/TrueSkill/TruncatedGaussianCorrectionFunctionsTest.php +++ b/tests/TrueSkill/TruncatedGaussianCorrectionFunctionsTest.php @@ -14,7 +14,7 @@ use PHPUnit\Framework\Attributes\UsesClass; #[CoversClass(TruncatedGaussianCorrectionFunctions::class)] #[UsesClass(BasicMath::class)] #[UsesClass(GaussianDistribution::class)] -class TruncatedGaussianCorrectionFunctionsTest extends TestCase +final class TruncatedGaussianCorrectionFunctionsTest extends TestCase { public function testvGreaterThan(): void { diff --git a/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php b/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php index 4ced858..8a3372d 100644 --- a/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php +++ b/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversNothing; #[CoversClass(TwoPlayerTrueSkillCalculator::class)] -class TwoPlayerTrueSkillCalculatorTest extends TestCase +final class TwoPlayerTrueSkillCalculatorTest extends TestCase { #[CoversNothing] public function testTwoPlayerTrueSkillCalculator(): void diff --git a/tests/TrueSkill/TwoTeamTrueSkillCalculatorTest.php b/tests/TrueSkill/TwoTeamTrueSkillCalculatorTest.php index 9442e47..8c9e5e0 100644 --- a/tests/TrueSkill/TwoTeamTrueSkillCalculatorTest.php +++ b/tests/TrueSkill/TwoTeamTrueSkillCalculatorTest.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversNothing; #[CoversClass(TwoTeamTrueSkillCalculator::class)] -class TwoTeamTrueSkillCalculatorTest extends TestCase +final class TwoTeamTrueSkillCalculatorTest extends TestCase { #[CoversNothing] public function testTwoTeamTrueSkillCalculator(): void