Compare commits

...

2 Commits

Author SHA1 Message Date
d729caac1f Simplifying some casts 2025-05-12 09:40:44 +00:00
bd9fccb87b Regular updates and fixing static analysis findings 2025-05-12 09:19:17 +00:00
7 changed files with 38 additions and 37 deletions

View File

@ -2,10 +2,11 @@
<phive xmlns="https://phar.io/phive"> <phive xmlns="https://phar.io/phive">
<phar name="phpmd" version="^2.15.0" installed="2.15.0" location="./tools/phpmd" copy="false"/> <phar name="phpmd" version="^2.15.0" installed="2.15.0" location="./tools/phpmd" copy="false"/>
<phar name="overtrue/phplint" version="^9.6.2" installed="9.6.2" location="./tools/phplint" copy="false"/> <phar name="overtrue/phplint" version="^9.6.2" installed="9.6.2" location="./tools/phplint" copy="false"/>
<phar name="phpstan" version="^2.1.12" installed="2.1.12" location="./tools/phpstan" copy="false"/> <phar name="phpstan" version="^2.1.12" installed="2.1.14" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="^7.0.0-beta6" installed="7.0.0-beta6" location="./tools/psalm" copy="false"/> <phar name="psalm" version="^7.0.0-beta6" installed="7.0.0-beta7" location="./tools/psalm" copy="false"/>
<phar name="phpcs" version="^3.12.2" installed="3.12.2" location="./tools/phpcs" copy="false"/> <phar name="phpcs" version="^3.12.2" installed="3.13.0" location="./tools/phpcs" copy="false"/>
<phar name="phpcbf" version="^3.12.2" installed="3.12.2" location="./tools/phpcbf" copy="false"/> <phar name="phpcbf" version="^3.12.2" installed="3.13.0" location="./tools/phpcbf" copy="false"/>
<phar name="phpdocumentor" version="^3.7.1" installed="3.7.1" location="./tools/phpdocumentor" copy="false"/> <phar name="phpdocumentor" version="^3.7.1" installed="3.7.1" location="./tools/phpdocumentor" copy="false"/>
<phar name="phpbench" version="^1.4.1" installed="1.4.1" location="./tools/phpbench" copy="false"/> <phar name="phpbench" version="^1.4.1" installed="1.4.1" location="./tools/phpbench" copy="false"/>
<phar name="infection" version="^0.29.14" installed="0.29.14" location="./tools/infection" copy="false"/>
</phive> </phive>

14
composer.lock generated
View File

@ -837,16 +837,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "11.5.18", "version": "11.5.20",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "fc3e887c7f3f9917e1bf61e523413d753db00a17" "reference": "e6bdea63ecb7a8287d2cdab25bdde3126e0cfe6f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fc3e887c7f3f9917e1bf61e523413d753db00a17", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e6bdea63ecb7a8287d2cdab25bdde3126e0cfe6f",
"reference": "fc3e887c7f3f9917e1bf61e523413d753db00a17", "reference": "e6bdea63ecb7a8287d2cdab25bdde3126e0cfe6f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -856,7 +856,7 @@
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-xml": "*", "ext-xml": "*",
"ext-xmlwriter": "*", "ext-xmlwriter": "*",
"myclabs/deep-copy": "^1.13.0", "myclabs/deep-copy": "^1.13.1",
"phar-io/manifest": "^2.0.4", "phar-io/manifest": "^2.0.4",
"phar-io/version": "^3.2.1", "phar-io/version": "^3.2.1",
"php": ">=8.2", "php": ">=8.2",
@ -918,7 +918,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "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": [ "funding": [
{ {
@ -942,7 +942,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2025-04-22T06:09:49+00:00" "time": "2025-05-11T06:39:52+00:00"
}, },
{ {
"name": "rector/rector", "name": "rector/rector",

View File

@ -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); $this->checkRowCol($row, $col);
return $this->matrixRowData[$row][$col]; return $this->matrixRowData[$row][$col];
@ -130,10 +130,10 @@ class Matrix
// | a b | // | a b |
// | c d | // | c d |
// The determinant is ad - bc // The determinant is ad - bc
$a = (float)$this->getValue(0, 0); $a = $this->getValue(0, 0);
$b = (float)$this->getValue(0, 1); $b = $this->getValue(0, 1);
$c = (float)$this->getValue(1, 0); $c = $this->getValue(1, 0);
$d = (float)$this->getValue(1, 1); $d = $this->getValue(1, 1);
return $a * $d - $b * $c; return $a * $d - $b * $c;
} }
@ -148,7 +148,7 @@ class Matrix
// I expand along the first row // I expand along the first row
for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) { for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) {
$firstRowColValue = (float)$this->getValue(0, $currentColumn); $firstRowColValue = $this->getValue(0, $currentColumn);
$cofactor = $this->getCofactor(0, $currentColumn); $cofactor = $this->getCofactor(0, $currentColumn);
$itemToAdd = $firstRowColValue * $cofactor; $itemToAdd = $firstRowColValue * $cofactor;
$result += $itemToAdd; $result += $itemToAdd;
@ -201,7 +201,7 @@ class Matrix
public function getInverse(): Matrix|SquareMatrix public function getInverse(): Matrix|SquareMatrix
{ {
if (($this->rowCount == 1) && ($this->columnCount == 1)) { if (($this->rowCount == 1) && ($this->columnCount == 1)) {
return new SquareMatrix(1.0 / (float)$this->getValue(0, 0)); return new SquareMatrix(1.0 / $this->getValue(0, 0));
} }
// Take the simple approach: // Take the simple approach:
@ -212,7 +212,7 @@ class Matrix
return self::scalarMultiply($determinantInverse, $adjugate); 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(); $rows = $matrix->getRowCount();
$columns = $matrix->getColumnCount(); $columns = $matrix->getColumnCount();
@ -240,9 +240,9 @@ class Matrix
for ($currentRow = 0; $currentRow < $left->getRowCount(); ++$currentRow) { for ($currentRow = 0; $currentRow < $left->getRowCount(); ++$currentRow) {
for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); ++$currentColumn) { for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); ++$currentColumn) {
$resultMatrix[$currentRow][$currentColumn] = $resultMatrix[$currentRow][$currentColumn] =
(float)$left->getValue($currentRow, $currentColumn) $left->getValue($currentRow, $currentColumn)
+ +
(float)$right->getValue($currentRow, $currentColumn); $right->getValue($currentRow, $currentColumn);
} }
} }
@ -265,11 +265,11 @@ class Matrix
for ($currentRow = 0; $currentRow < $resultRows; ++$currentRow) { for ($currentRow = 0; $currentRow < $resultRows; ++$currentRow) {
for ($currentColumn = 0; $currentColumn < $resultColumns; ++$currentColumn) { for ($currentColumn = 0; $currentColumn < $resultColumns; ++$currentColumn) {
$productValue = 0; $productValue = 0.0;
for ($vectorIndex = 0; $vectorIndex < $left->getColumnCount(); ++$vectorIndex) { for ($vectorIndex = 0; $vectorIndex < $left->getColumnCount(); ++$vectorIndex) {
$leftValue = (float)$left->getValue($currentRow, $vectorIndex); $leftValue = $left->getValue($currentRow, $vectorIndex);
$rightValue = (float)$right->getValue($vectorIndex, $currentColumn); $rightValue = $right->getValue($vectorIndex, $currentColumn);
$vectorIndexProduct = $leftValue * $rightValue; $vectorIndexProduct = $leftValue * $rightValue;
$productValue += $vectorIndexProduct; $productValue += $vectorIndexProduct;
} }
@ -339,8 +339,8 @@ class Matrix
for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) { for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) {
$delta = $delta =
abs( abs(
(float)$this->getValue($currentRow, $currentColumn) - $this->getValue($currentRow, $currentColumn) -
(float)$otherMatrix->getValue($currentRow, $currentColumn) $otherMatrix->getValue($currentRow, $currentColumn)
); );
if ($delta > self::ERROR_TOLERANCE) { if ($delta > self::ERROR_TOLERANCE) {

View File

@ -192,7 +192,7 @@ final class FactorGraphTrueSkillCalculator extends SkillCalculator
$nextTeam = $teamAssignmentsList[$i + 1]; $nextTeam = $teamAssignmentsList[$i + 1];
foreach ($nextTeam->getAllPlayers() as $nextTeamPlayer) { foreach ($nextTeam->getAllPlayers() as $nextTeamPlayer) {
// Add a -1 * playing time to represent the difference // Add a -1 * playing time to represent the difference
$playerAssignments[$currentColumn][] = -1 * PartialPlay::getPartialPlayPercentage($nextTeamPlayer); $playerAssignments[$currentColumn][] = -1.0 * PartialPlay::getPartialPlayPercentage($nextTeamPlayer);
--$rowsRemaining; --$rowsRemaining;
} }

View File

@ -72,12 +72,12 @@ final class GaussianWeightedSumFactor extends GaussianFactor
$weightsLength = $variableWeightsLength + 1; $weightsLength = $variableWeightsLength + 1;
for ($weightsIndex = 1; $weightsIndex < $weightsLength; ++$weightsIndex) { 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; $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. // 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 // 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]); $currentWeight = (-$variableWeights[$currentWeightSourceIndex] / $variableWeights[$weightsIndex - 1]);
if ($variableWeights[$weightsIndex - 1] == 0) { if ($variableWeights[$weightsIndex - 1] == 0.0) {
// HACK: Getting around division by zero // HACK: Getting around division by zero
$currentWeight = 0; $currentWeight = 0.0;
} }
$currentWeights[$currentDestinationWeightIndex] = $currentWeight; $currentWeights[$currentDestinationWeightIndex] = $currentWeight;
@ -112,7 +112,7 @@ final class GaussianWeightedSumFactor extends GaussianFactor
$currentWeights[$currentDestinationWeightIndex] = $finalWeight; $currentWeights[$currentDestinationWeightIndex] = $finalWeight;
$currentWeightsSquared[$currentDestinationWeightIndex] = BasicMath::square($finalWeight); $currentWeightsSquared[$currentDestinationWeightIndex] = BasicMath::square($finalWeight);
$variableIndices[count($variableWeights)] = 0; $variableIndices[count($variableWeights)] = 0.0;
$this->varIndexOrdersForWeights[] = $variableIndices; $this->varIndexOrdersForWeights[] = $variableIndices;
$this->weights[$weightsIndex] = $currentWeights; $this->weights[$weightsIndex] = $currentWeights;

View File

@ -118,11 +118,11 @@ final class TwoPlayerTrueSkillCalculator extends SkillCalculator
// non-draw case // non-draw case
$v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c); $v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c);
$w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c);
$rankMultiplier = $comparison->value; $rankMultiplier = (float)$comparison->value;
} else { } else {
$v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c); $v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c);
$w = TruncatedGaussianCorrectionFunctions::wWithinMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wWithinMarginScaled($meanDelta, $drawMargin, $c);
$rankMultiplier = 1; $rankMultiplier = 1.0;
} }
$meanMultiplier = (BasicMath::square($selfRating->getStandardDeviation()) + BasicMath::square($gameInfo->getDynamicsFactor())) / $c; $meanMultiplier = (BasicMath::square($selfRating->getStandardDeviation()) + BasicMath::square($gameInfo->getDynamicsFactor())) / $c;

View File

@ -94,7 +94,7 @@ final class TwoTeamTrueSkillCalculator extends SkillCalculator
+ +
BasicMath::sum($otherTeam->getAllRatings(), $varianceGetter) BasicMath::sum($otherTeam->getAllRatings(), $varianceGetter)
+ +
$totalPlayers * $betaSquared (float)$totalPlayers * $betaSquared
); );
$winningMean = $selfMeanSum; $winningMean = $selfMeanSum;
@ -117,7 +117,7 @@ final class TwoTeamTrueSkillCalculator extends SkillCalculator
// non-draw case // non-draw case
$v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c); $v = TruncatedGaussianCorrectionFunctions::vExceedsMarginScaled($meanDelta, $drawMargin, $c);
$w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c); $w = TruncatedGaussianCorrectionFunctions::wExceedsMarginScaled($meanDelta, $drawMargin, $c);
$rankMultiplier = $selfToOtherTeamComparison->value; $rankMultiplier = (float)$selfToOtherTeamComparison->value;
} else { } else {
// assume draw // assume draw
$v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c); $v = TruncatedGaussianCorrectionFunctions::vWithinMarginScaled($meanDelta, $drawMargin, $c);