From bd9fccb87b1f95ecf2a29b038622acad76a6d4a8 Mon Sep 17 00:00:00 2001 From: Jens True Date: Mon, 12 May 2025 09:19:17 +0000 Subject: [PATCH] Regular updates and fixing static analysis findings --- .phive/phars.xml | 9 +++++---- composer.lock | 14 +++++++------- src/Numerics/Matrix.php | 6 +++--- src/TrueSkill/FactorGraphTrueSkillCalculator.php | 2 +- .../Factors/GaussianWeightedSumFactor.php | 10 +++++----- src/TrueSkill/TwoPlayerTrueSkillCalculator.php | 4 ++-- src/TrueSkill/TwoTeamTrueSkillCalculator.php | 4 ++-- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.phive/phars.xml b/.phive/phars.xml index ea0555e..728f4cc 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -2,10 +2,11 @@ - - - - + + + + + diff --git a/composer.lock b/composer.lock index eb87b97..462cc09 100644 --- a/composer.lock +++ b/composer.lock @@ -837,16 +837,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.5.18", + "version": "11.5.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "fc3e887c7f3f9917e1bf61e523413d753db00a17" + "reference": "e6bdea63ecb7a8287d2cdab25bdde3126e0cfe6f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fc3e887c7f3f9917e1bf61e523413d753db00a17", - "reference": "fc3e887c7f3f9917e1bf61e523413d753db00a17", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e6bdea63ecb7a8287d2cdab25bdde3126e0cfe6f", + "reference": "e6bdea63ecb7a8287d2cdab25bdde3126e0cfe6f", "shasum": "" }, "require": { @@ -856,7 +856,7 @@ "ext-mbstring": "*", "ext-xml": "*", "ext-xmlwriter": "*", - "myclabs/deep-copy": "^1.13.0", + "myclabs/deep-copy": "^1.13.1", "phar-io/manifest": "^2.0.4", "phar-io/version": "^3.2.1", "php": ">=8.2", @@ -918,7 +918,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.18" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.20" }, "funding": [ { @@ -942,7 +942,7 @@ "type": "tidelift" } ], - "time": "2025-04-22T06:09:49+00:00" + "time": "2025-05-11T06:39:52+00:00" }, { "name": "rector/rector", diff --git a/src/Numerics/Matrix.php b/src/Numerics/Matrix.php index daaceca..b70676a 100644 --- a/src/Numerics/Matrix.php +++ b/src/Numerics/Matrix.php @@ -79,7 +79,7 @@ class Matrix } } - public function getValue(int $row, int $col): float|int + public function getValue(int $row, int $col): float { $this->checkRowCol($row, $col); return $this->matrixRowData[$row][$col]; @@ -212,7 +212,7 @@ class Matrix return self::scalarMultiply($determinantInverse, $adjugate); } - public static function scalarMultiply(float|int $scalarValue, Matrix $matrix): Matrix + public static function scalarMultiply(float $scalarValue, Matrix $matrix): Matrix { $rows = $matrix->getRowCount(); $columns = $matrix->getColumnCount(); @@ -265,7 +265,7 @@ class Matrix for ($currentRow = 0; $currentRow < $resultRows; ++$currentRow) { for ($currentColumn = 0; $currentColumn < $resultColumns; ++$currentColumn) { - $productValue = 0; + $productValue = 0.0; for ($vectorIndex = 0; $vectorIndex < $left->getColumnCount(); ++$vectorIndex) { $leftValue = (float)$left->getValue($currentRow, $vectorIndex); diff --git a/src/TrueSkill/FactorGraphTrueSkillCalculator.php b/src/TrueSkill/FactorGraphTrueSkillCalculator.php index d7e9121..a67c2c7 100644 --- a/src/TrueSkill/FactorGraphTrueSkillCalculator.php +++ b/src/TrueSkill/FactorGraphTrueSkillCalculator.php @@ -192,7 +192,7 @@ final class FactorGraphTrueSkillCalculator extends SkillCalculator $nextTeam = $teamAssignmentsList[$i + 1]; foreach ($nextTeam->getAllPlayers() as $nextTeamPlayer) { // Add a -1 * playing time to represent the difference - $playerAssignments[$currentColumn][] = -1 * PartialPlay::getPartialPlayPercentage($nextTeamPlayer); + $playerAssignments[$currentColumn][] = -1.0 * PartialPlay::getPartialPlayPercentage($nextTeamPlayer); --$rowsRemaining; } diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index 61a8ad8..e7ea115 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -72,12 +72,12 @@ final class GaussianWeightedSumFactor extends GaussianFactor $weightsLength = $variableWeightsLength + 1; for ($weightsIndex = 1; $weightsIndex < $weightsLength; ++$weightsIndex) { - $currentWeights = \array_fill(0, $variableWeightsLength, 0); + $currentWeights = \array_fill(0, $variableWeightsLength, 0.0); - $variableIndices = \array_fill(0, $variableWeightsLength + 1, 0); + $variableIndices = \array_fill(0, $variableWeightsLength + 1, 0.0); $variableIndices[0] = $weightsIndex; - $currentWeightsSquared = \array_fill(0, $variableWeightsLength, 0); + $currentWeightsSquared = \array_fill(0, $variableWeightsLength, 0.0); // keep a single variable to keep track of where we are in the array. // This is helpful since we skip over one of the spots @@ -90,9 +90,9 @@ final class GaussianWeightedSumFactor extends GaussianFactor $currentWeight = (-$variableWeights[$currentWeightSourceIndex] / $variableWeights[$weightsIndex - 1]); - if ($variableWeights[$weightsIndex - 1] == 0) { + if ($variableWeights[$weightsIndex - 1] == 0.0) { // HACK: Getting around division by zero - $currentWeight = 0; + $currentWeight = 0.0; } $currentWeights[$currentDestinationWeightIndex] = $currentWeight; diff --git a/src/TrueSkill/TwoPlayerTrueSkillCalculator.php b/src/TrueSkill/TwoPlayerTrueSkillCalculator.php index 0d03c65..2461fa1 100644 --- a/src/TrueSkill/TwoPlayerTrueSkillCalculator.php +++ b/src/TrueSkill/TwoPlayerTrueSkillCalculator.php @@ -118,11 +118,11 @@ final class TwoPlayerTrueSkillCalculator extends SkillCalculator // non-draw case $v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c); - $rankMultiplier = $comparison->value; + $rankMultiplier = (float)$comparison->value; } else { $v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wWithinMarginScaled($meanDelta, $drawMargin, $c); - $rankMultiplier = 1; + $rankMultiplier = 1.0; } $meanMultiplier = (BasicMath::square($selfRating->getStandardDeviation()) + BasicMath::square($gameInfo->getDynamicsFactor())) / $c; diff --git a/src/TrueSkill/TwoTeamTrueSkillCalculator.php b/src/TrueSkill/TwoTeamTrueSkillCalculator.php index 475a3bd..2e97e36 100644 --- a/src/TrueSkill/TwoTeamTrueSkillCalculator.php +++ b/src/TrueSkill/TwoTeamTrueSkillCalculator.php @@ -94,7 +94,7 @@ final class TwoTeamTrueSkillCalculator extends SkillCalculator + BasicMath::sum($otherTeam->getAllRatings(), $varianceGetter) + - $totalPlayers * $betaSquared + (float)$totalPlayers * $betaSquared ); $winningMean = $selfMeanSum; @@ -117,7 +117,7 @@ final class TwoTeamTrueSkillCalculator extends SkillCalculator // non-draw case $v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c); - $rankMultiplier = $selfToOtherTeamComparison->value; + $rankMultiplier = (float)$selfToOtherTeamComparison->value; } else { // assume draw $v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c);