diff --git a/benchmark/BasicBench.php b/benchmark/BasicBench.php index fd42365..e585a60 100644 --- a/benchmark/BasicBench.php +++ b/benchmark/BasicBench.php @@ -30,7 +30,7 @@ class BasicBench $team1 = new Team($p1, $gameInfo->getDefaultRating()); $team2 = new Team($p2, $gameInfo->getDefaultRating()); - for ($i = 0; $i < 10; $i++) { + for ($i = 0; $i < 10; ++$i) { $teams = Teams::concat($team1, $team2); $calculator = new TwoPlayerTrueSkillCalculator(); @@ -61,7 +61,7 @@ class BasicBench $team1 = new Team($p1, $gameInfo->getDefaultRating()); $team2 = new Team($p2, $gameInfo->getDefaultRating()); - for ($i = 0; $i < 10; $i++) { + for ($i = 0; $i < 10; ++$i) { $teams = Teams::concat($team1, $team2); $calculator = new TwoTeamTrueSkillCalculator(); @@ -92,7 +92,7 @@ class BasicBench $team1 = new Team($p1, $gameInfo->getDefaultRating()); $team2 = new Team($p2, $gameInfo->getDefaultRating()); - for ($i = 0; $i < 10; $i++) { + for ($i = 0; $i < 10; ++$i) { $teams = Teams::concat($team1, $team2); $calculator = new FactorGraphTrueSkillCalculator(); @@ -125,7 +125,7 @@ class BasicBench $team2 = new Team($p2, $gameInfo->getDefaultRating()); $team3 = new Team($p3, $gameInfo->getDefaultRating()); - for ($i = 0; $i < 10; $i++) { + for ($i = 0; $i < 10; ++$i) { $teams = Teams::concat($team1, $team2, $team3); $calculator = new FactorGraphTrueSkillCalculator(); diff --git a/examples/3teams.php b/examples/3teams.php index f90aac5..da37ae9 100644 --- a/examples/3teams.php +++ b/examples/3teams.php @@ -20,8 +20,8 @@ $team2 = new Team($p2, $gameInfo->getDefaultRating()); $team3 = new Team($p3, $gameInfo->getDefaultRating()); -for($i = 0; $i < 5; $i++) { - echo "Iteration: $i\n"; +for($i = 0; $i < 5; ++$i) { + echo "Iteration: " . $i . PHP_EOL; $teams = Teams::concat($team1, $team2, $team3); $calculator = new FactorGraphTrueSkillCalculator(); diff --git a/examples/basic.php b/examples/basic.php index 8dc12f1..5efa0da 100644 --- a/examples/basic.php +++ b/examples/basic.php @@ -19,8 +19,8 @@ $team1 = new Team($p1, $gameInfo->getDefaultRating()); $team2 = new Team($p2, $gameInfo->getDefaultRating()); -for($i = 0; $i < 5; $i++) { - echo "Iteration: $i\n"; +for($i = 0; $i < 5; ++$i) { + echo "Iteration: " . $i . PHP_EOL; $teams = Teams::concat($team1, $team2); $calculator = new TwoPlayerTrueSkillCalculator(); diff --git a/rector.php b/rector.php index 6956680..7b2b846 100644 --- a/rector.php +++ b/rector.php @@ -14,7 +14,7 @@ return RectorConfig::configure() ]) // uncomment to reach your current PHP version ->withPhpSets() - ->withPreparedSets(deadCode: true, codeQuality: true, typeDeclarations : true) + ->withPreparedSets(deadCode: true, codeQuality: true, codingStyle: true, typeDeclarations : true) ->withSkip([ LocallyCalledStaticMethodToNonStaticRector::class, ]);; diff --git a/src/FactorGraphs/FactorGraphLayer.php b/src/FactorGraphs/FactorGraphLayer.php index 5601ede..3b16f40 100644 --- a/src/FactorGraphs/FactorGraphLayer.php +++ b/src/FactorGraphs/FactorGraphLayer.php @@ -18,6 +18,7 @@ abstract class FactorGraphLayer * @var array> */ private array $outputVariablesGroups = []; + /** * @var array> */ diff --git a/src/FactorGraphs/FactorList.php b/src/FactorGraphs/FactorList.php index 390a029..3d21d72 100644 --- a/src/FactorGraphs/FactorList.php +++ b/src/FactorGraphs/FactorList.php @@ -25,12 +25,12 @@ class FactorList $listCount = count($this->list); - for ($i = 0; $i < $listCount; $i++) { + for ($i = 0; $i < $listCount; ++$i) { $f = $this->list[$i]; $numberOfMessages = $f->getNumberOfMessages(); - for ($j = 0; $j < $numberOfMessages; $j++) { + for ($j = 0; $j < $numberOfMessages; ++$j) { $sumLogZ += $f->sendMessageIndex($j); } } diff --git a/src/Numerics/DiagonalMatrix.php b/src/Numerics/DiagonalMatrix.php index 05fad9d..cdd3fc7 100644 --- a/src/Numerics/DiagonalMatrix.php +++ b/src/Numerics/DiagonalMatrix.php @@ -15,8 +15,8 @@ class DiagonalMatrix extends Matrix parent::__construct($diagonalCount, $diagonalCount); - for ($currentRow = 0; $currentRow < $diagonalCount; $currentRow++) { - for ($currentCol = 0; $currentCol < $diagonalCount; $currentCol++) { + for ($currentRow = 0; $currentRow < $diagonalCount; ++$currentRow) { + for ($currentCol = 0; $currentCol < $diagonalCount; ++$currentCol) { if ($currentRow === $currentCol) { $this->setValue($currentRow, $currentCol, $diagonalValues[$currentRow]); } else { diff --git a/src/Numerics/GaussianDistribution.php b/src/Numerics/GaussianDistribution.php index 6d1b2cf..e0b012d 100644 --- a/src/Numerics/GaussianDistribution.php +++ b/src/Numerics/GaussianDistribution.php @@ -15,10 +15,11 @@ class GaussianDistribution implements \Stringable //sqrt(2*pi) //from https://www.wolframalpha.com/input?i=sqrt%282*pi%29 private const M_SQRT_2_PI = 2.5066282746310005024157652848110452530069867406099383166299235763; - + //log(sqrt(2*pi)) //From https://www.wolframalpha.com/input?i=log%28sqrt%282*pi%29%29 private const M_LOG_SQRT_2_PI = 0.9189385332046727417803297364056176398613974736377834128171515404; + // precision and precisionMean are used because they make multiplying and dividing simpler // (the the accompanying math paper for more details) private float $precision; @@ -209,7 +210,7 @@ class GaussianDistribution implements \Stringable $d = 0.0; $dd = 0.0; - for ($j = $ncof - 1; $j > 0; $j--) { + for ($j = $ncof - 1; $j > 0; --$j) { $tmp = $d; $d = $ty * $d - $dd + $coefficients[$j]; $dd = $tmp; @@ -227,6 +228,7 @@ class GaussianDistribution implements \Stringable if ($p >= 2.0) { return -100; } + if ($p <= 0.0) { return 100; } @@ -235,7 +237,7 @@ class GaussianDistribution implements \Stringable $t = sqrt(-2 * 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++) { + for ($j = 0; $j < 2; ++$j) { $err = GaussianDistribution::errorFunctionCumulativeTo($x) - $pp; $x += $err / (M_2_SQRTPI * exp(-BasicMath::square($x)) - $x * $err); // Halley } diff --git a/src/Numerics/Matrix.php b/src/Numerics/Matrix.php index 8c7aa1d..9bd18da 100644 --- a/src/Numerics/Matrix.php +++ b/src/Numerics/Matrix.php @@ -25,10 +25,10 @@ class Matrix $data = []; $result = new Matrix($rows, $columns, $data); - for ($currentColumn = 0; $currentColumn < $columns; $currentColumn++) { + for ($currentColumn = 0; $currentColumn < $columns; ++$currentColumn) { $currentColumnData = $columnValues[$currentColumn]; - for ($currentRow = 0; $currentRow < $rows; $currentRow++) { + for ($currentRow = 0; $currentRow < $rows; ++$currentRow) { $result->setValue($currentRow, $currentColumn, $currentColumnData[$currentRow]); } } @@ -41,8 +41,8 @@ class Matrix $result = new Matrix($rows, $cols); $currentIndex = 0; - for ($currentRow = 0; $currentRow < $rows; $currentRow++) { - for ($currentCol = 0; $currentCol < $cols; $currentCol++) { + for ($currentRow = 0; $currentRow < $rows; ++$currentRow) { + for ($currentCol = 0; $currentCol < $cols; ++$currentCol) { $result->setValue($currentRow, $currentCol, $args[$currentIndex++]); } } @@ -76,8 +76,8 @@ class Matrix $transposeMatrix = []; $rowMatrixData = $this->matrixRowData; - for ($currentRowTransposeMatrix = 0; $currentRowTransposeMatrix < $this->columnCount; $currentRowTransposeMatrix++) { - for ($currentColumnTransposeMatrix = 0; $currentColumnTransposeMatrix < $this->rowCount; $currentColumnTransposeMatrix++) { + for ($currentRowTransposeMatrix = 0; $currentRowTransposeMatrix < $this->columnCount; ++$currentRowTransposeMatrix) { + for ($currentColumnTransposeMatrix = 0; $currentColumnTransposeMatrix < $this->rowCount; ++$currentColumnTransposeMatrix) { $transposeMatrix[$currentRowTransposeMatrix][$currentColumnTransposeMatrix] = $rowMatrixData[$currentColumnTransposeMatrix][$currentRowTransposeMatrix]; } @@ -126,7 +126,7 @@ class Matrix $result = 0.0; // I expand along the first row - for ($currentColumn = 0; $currentColumn < $this->columnCount; $currentColumn++) { + for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) { $firstRowColValue = $this->matrixRowData[0][$currentColumn]; $cofactor = $this->getCofactor(0, $currentColumn); $itemToAdd = $firstRowColValue * $cofactor; @@ -168,8 +168,8 @@ class Matrix // The idea is that it's the transpose of the cofactors $result = []; - for ($currentColumn = 0; $currentColumn < $this->columnCount; $currentColumn++) { - for ($currentRow = 0; $currentRow < $this->rowCount; $currentRow++) { + for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) { + for ($currentRow = 0; $currentRow < $this->rowCount; ++$currentRow) { $result[$currentColumn][$currentRow] = $this->getCofactor($currentRow, $currentColumn); } } @@ -197,8 +197,8 @@ class Matrix $columns = $matrix->getColumnCount(); $newValues = []; - for ($currentRow = 0; $currentRow < $rows; $currentRow++) { - for ($currentColumn = 0; $currentColumn < $columns; $currentColumn++) { + for ($currentRow = 0; $currentRow < $rows; ++$currentRow) { + for ($currentColumn = 0; $currentColumn < $columns; ++$currentColumn) { $newValues[$currentRow][$currentColumn] = $scalarValue * $matrix->getValue($currentRow, $currentColumn); } } @@ -216,8 +216,8 @@ class Matrix $resultMatrix = []; - for ($currentRow = 0; $currentRow < $left->getRowCount(); $currentRow++) { - for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); $currentColumn++) { + for ($currentRow = 0; $currentRow < $left->getRowCount(); ++$currentRow) { + for ($currentColumn = 0; $currentColumn < $right->getColumnCount(); ++$currentColumn) { $resultMatrix[$currentRow][$currentColumn] = $left->getValue($currentRow, $currentColumn) + @@ -242,11 +242,11 @@ class Matrix $resultMatrix = []; - for ($currentRow = 0; $currentRow < $resultRows; $currentRow++) { - for ($currentColumn = 0; $currentColumn < $resultColumns; $currentColumn++) { + for ($currentRow = 0; $currentRow < $resultRows; ++$currentRow) { + for ($currentColumn = 0; $currentColumn < $resultColumns; ++$currentColumn) { $productValue = 0; - for ($vectorIndex = 0; $vectorIndex < $left->getColumnCount(); $vectorIndex++) { + for ($vectorIndex = 0; $vectorIndex < $left->getColumnCount(); ++$vectorIndex) { $leftValue = $left->getValue($currentRow, $vectorIndex); $rightValue = $right->getValue($vectorIndex, $currentColumn); $vectorIndexProduct = $leftValue * $rightValue; @@ -269,24 +269,24 @@ class Matrix $actualRow = 0; - for ($currentRow = 0; $currentRow < $this->rowCount; $currentRow++) { + for ($currentRow = 0; $currentRow < $this->rowCount; ++$currentRow) { if ($currentRow == $rowToRemove) { continue; } $actualCol = 0; - for ($currentColumn = 0; $currentColumn < $this->columnCount; $currentColumn++) { + for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) { if ($currentColumn == $columnToRemove) { continue; } $result[$actualRow][$actualCol] = $this->matrixRowData[$currentRow][$currentColumn]; - $actualCol++; + ++$actualCol; } - $actualRow++; + ++$actualRow; } return new Matrix($this->rowCount - 1, $this->columnCount - 1, $result); @@ -312,8 +312,8 @@ class Matrix return FALSE; } - for ($currentRow = 0; $currentRow < $this->rowCount; $currentRow++) { - for ($currentColumn = 0; $currentColumn < $this->columnCount; $currentColumn++) { + for ($currentRow = 0; $currentRow < $this->rowCount; ++$currentRow) { + for ($currentColumn = 0; $currentColumn < $this->columnCount; ++$currentColumn) { $delta = abs( $this->matrixRowData[$currentRow][$currentColumn] - diff --git a/src/Numerics/SquareMatrix.php b/src/Numerics/SquareMatrix.php index 8b9c4df..1d68948 100644 --- a/src/Numerics/SquareMatrix.php +++ b/src/Numerics/SquareMatrix.php @@ -13,8 +13,8 @@ class SquareMatrix extends Matrix $matrixData = []; $allValuesIndex = 0; - for ($currentRow = 0; $currentRow < $size; $currentRow++) { - for ($currentColumn = 0; $currentColumn < $size; $currentColumn++) { + for ($currentRow = 0; $currentRow < $size; ++$currentRow) { + for ($currentColumn = 0; $currentColumn < $size; ++$currentColumn) { $matrixData[$currentRow][$currentColumn] = $allValues[$allValuesIndex++]; } } diff --git a/src/Numerics/Vector.php b/src/Numerics/Vector.php index 54f0aa2..a6422ab 100644 --- a/src/Numerics/Vector.php +++ b/src/Numerics/Vector.php @@ -15,6 +15,7 @@ class Vector extends Matrix foreach ($vectorValues as $currentVectorValue) { $columnValues[] = [$currentVectorValue]; } + parent::__construct(count($vectorValues), 1, $columnValues); } } diff --git a/src/SkillCalculator.php b/src/SkillCalculator.php index 6c99fb2..9aedd73 100644 --- a/src/SkillCalculator.php +++ b/src/SkillCalculator.php @@ -70,7 +70,8 @@ abstract class SkillCalculator if (! $playersPerTeam->isInRange($currentTeam->count())) { throw new Exception('Player count is not in range'); } - $countOfTeams++; + + ++$countOfTeams; } if (! $totalTeams->isInRange($countOfTeams)) { diff --git a/src/TrueSkill/FactorGraphTrueSkillCalculator.php b/src/TrueSkill/FactorGraphTrueSkillCalculator.php index afd0c3e..1a2ec3e 100644 --- a/src/TrueSkill/FactorGraphTrueSkillCalculator.php +++ b/src/TrueSkill/FactorGraphTrueSkillCalculator.php @@ -29,6 +29,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator { parent::__construct(SkillCalculatorSupportedOptions::PARTIAL_PLAY | SkillCalculatorSupportedOptions::PARTIAL_UPDATE, TeamsRange::atLeast(2), PlayersRange::atLeast(1)); } + /** * {@inheritdoc} */ @@ -51,6 +52,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator return $factorGraph->getUpdatedRatings(); } + /** * {@inheritdoc} */ @@ -104,7 +106,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator return new Vector( self::getPlayerRatingValues( $teamAssignmentsList, - fn (Rating $rating): float => $rating->getMean() + static fn(Rating $rating): float => $rating->getMean() ) ); } @@ -119,7 +121,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator return new DiagonalMatrix( self::getPlayerRatingValues( $teamAssignmentsList, - fn (Rating $rating): float => BasicMath::square($rating->getStandardDeviation()) + static fn(Rating $rating): float => BasicMath::square($rating->getStandardDeviation()) ) ); } @@ -171,7 +173,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator $currentColumn = 0; - for ($i = 0; $i < count($teamAssignmentsList) - 1; $i++) { + for ($i = 0; $i < count($teamAssignmentsList) - 1; ++$i) { $currentTeam = $teamAssignmentsList[$i]; // Need to add in 0's for all the previous players, since they're not @@ -181,7 +183,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator foreach ($currentTeam->getAllPlayers() as $currentPlayer) { $playerAssignments[$currentColumn][] = PartialPlay::getPartialPlayPercentage($currentPlayer); // indicates the player is on the team - $totalPreviousPlayers++; + ++$totalPreviousPlayers; } $rowsRemaining = $totalPlayers - $totalPreviousPlayers; @@ -190,15 +192,15 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator foreach ($nextTeam->getAllPlayers() as $nextTeamPlayer) { // Add a -1 * playing time to represent the difference $playerAssignments[$currentColumn][] = -1 * PartialPlay::getPartialPlayPercentage($nextTeamPlayer); - $rowsRemaining--; + --$rowsRemaining; } - for ($ixAdditionalRow = 0; $ixAdditionalRow < $rowsRemaining; $ixAdditionalRow++) { + for ($ixAdditionalRow = 0; $ixAdditionalRow < $rowsRemaining; ++$ixAdditionalRow) { // Pad with zeros $playerAssignments[$currentColumn][] = 0; } - $currentColumn++; + ++$currentColumn; } return Matrix::fromColumnValues($totalPlayers, count($teamAssignmentsList) - 1, $playerAssignments); diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index 27ad12a..3622b14 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -30,6 +30,7 @@ class GaussianWeightedSumFactor extends GaussianFactor * @var array $weights */ private array $weights = []; + /** * @var array $weightsSquared */ @@ -48,7 +49,7 @@ class GaussianWeightedSumFactor extends GaussianFactor $variableWeightsLength = count($variableWeights); $this->weights[0] = array_fill(0, count($variableWeights), 0); - for ($i = 0; $i < $variableWeightsLength; $i++) { + for ($i = 0; $i < $variableWeightsLength; ++$i) { $weight = &$variableWeights[$i]; $this->weights[0][$i] = $weight; $this->weightsSquared[0][$i] = BasicMath::square($weight); @@ -58,7 +59,7 @@ class GaussianWeightedSumFactor extends GaussianFactor // 0..n-1 $this->variableIndexOrdersForWeights[0] = []; - for ($i = 0; $i < ($variablesToSumLength + 1); $i++) { + for ($i = 0; $i < ($variablesToSumLength + 1); ++$i) { $this->variableIndexOrdersForWeights[0][] = $i; } @@ -70,7 +71,7 @@ class GaussianWeightedSumFactor extends GaussianFactor // By convention, we'll put the v_0 term at the end $weightsLength = $variableWeightsLength + 1; - for ($weightsIndex = 1; $weightsIndex < $weightsLength; $weightsIndex++) { + for ($weightsIndex = 1; $weightsIndex < $weightsLength; ++$weightsIndex) { $currentWeights = \array_fill(0, $variableWeightsLength, 0); $variableIndices = \array_fill(0, $variableWeightsLength + 1, 0); @@ -82,7 +83,7 @@ class GaussianWeightedSumFactor extends GaussianFactor // This is helpful since we skip over one of the spots $currentDestinationWeightIndex = 0; - for ($currentWeightSourceIndex = 0; $currentWeightSourceIndex < $variableWeightsLength; $currentWeightSourceIndex++) { + for ($currentWeightSourceIndex = 0; $currentWeightSourceIndex < $variableWeightsLength; ++$currentWeightSourceIndex) { if ($currentWeightSourceIndex === $weightsIndex - 1) { continue; } @@ -98,7 +99,7 @@ class GaussianWeightedSumFactor extends GaussianFactor $currentWeightsSquared[$currentDestinationWeightIndex] = $currentWeight * $currentWeight; $variableIndices[$currentDestinationWeightIndex + 1] = $currentWeightSourceIndex + 1; - $currentDestinationWeightIndex++; + ++$currentDestinationWeightIndex; } // And the final one @@ -108,6 +109,7 @@ class GaussianWeightedSumFactor extends GaussianFactor // HACK: Getting around division by zero $finalWeight = 0; } + $currentWeights[$currentDestinationWeightIndex] = $finalWeight; $currentWeightsSquared[$currentDestinationWeightIndex] = BasicMath::square($finalWeight); $variableIndices[count($variableWeights)] = 0; @@ -135,7 +137,7 @@ class GaussianWeightedSumFactor extends GaussianFactor $counter = count($vars); // We start at 1 since offset 0 has the sum - for ($i = 1; $i < $counter; $i++) { + for ($i = 1; $i < $counter; ++$i) { $result += GaussianDistribution::logRatioNormalization($vars[$i]->getValue(), $messages[$i]->getValue()); } @@ -164,7 +166,7 @@ class GaussianWeightedSumFactor extends GaussianFactor $weightsSquaredLength = count($weightsSquared); - for ($i = 0; $i < $weightsSquaredLength; $i++) { + for ($i = 0; $i < $weightsSquaredLength; ++$i) { // These flow directly from the paper $inverseOfNewPrecisionSum += $weightsSquared[$i] / @@ -221,7 +223,7 @@ class GaussianWeightedSumFactor extends GaussianFactor // The tricky part here is that we have to put the messages and variables in the same // order as the weights. Thankfully, the weights and messages share the same index numbers, // so we just need to make sure they're consistent - for ($i = 0; $i < $counter; $i++) { + for ($i = 0; $i < $counter; ++$i) { $updatedMessages[] = $allMessages[$indicesToUse[$i]]; $updatedVariables[] = $allVariables[$indicesToUse[$i]]; } @@ -245,7 +247,7 @@ class GaussianWeightedSumFactor extends GaussianFactor $result .= ' = '; $totalVars = count($variablesToSum); - for ($i = 0; $i < $totalVars; $i++) { + for ($i = 0; $i < $totalVars; ++$i) { $isFirst = ($i == 0); if ($isFirst && ($weights[$i] < 0)) { diff --git a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php index 63a7464..906abff 100644 --- a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php +++ b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php @@ -113,7 +113,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer $forwardScheduleList = []; - for ($i = 0; $i < $totalTeamDifferences - 1; $i++) { + for ($i = 0; $i < $totalTeamDifferences - 1; ++$i) { $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors(); $teamDifferencesComparisonLayerLocalFactors = $this->TeamDifferencesComparisonLayer->getLocalFactors(); @@ -149,7 +149,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer $backwardScheduleList = []; - for ($i = 0; $i < $totalTeamDifferences - 1; $i++) { + for ($i = 0; $i < $totalTeamDifferences - 1; ++$i) { $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors(); $teamDifferencesComparisonLayerLocalFactors = $this->TeamDifferencesComparisonLayer->getLocalFactors(); diff --git a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php index 25887a2..8576477 100644 --- a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php @@ -37,7 +37,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye return $this->scheduleSequence( array_map( - fn ($weightedSumFactor): ScheduleStep => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0), + static fn($weightedSumFactor): ScheduleStep => new ScheduleStep('Perf to Team Perf Step', $weightedSumFactor, 0), $localFactors ), 'all player perf to team perf schedule' @@ -50,9 +50,8 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye protected function createPlayerToTeamSumFactor(array $teamMembers, Variable $sumVariable): GaussianWeightedSumFactor { $weights = array_map( - function ($v): float { + static function ($v): float { $player = $v->getKey(); - return PartialPlay::getPartialPlayPercentage($player); }, $teamMembers @@ -72,7 +71,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye foreach ($localFactors as $currentFactor) { $localCurrentFactor = $currentFactor; $numberOfMessages = $localCurrentFactor->getNumberOfMessages(); - for ($currentIteration = 1; $currentIteration < $numberOfMessages; $currentIteration++) { + for ($currentIteration = 1; $currentIteration < $numberOfMessages; ++$currentIteration) { $allFactors[] = new ScheduleStep( 'team sum perf @' . $currentIteration, $localCurrentFactor, @@ -89,7 +88,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye */ private function createOutputVariable(array $team): Variable { - $memberNames = array_map(fn ($currentPlayer): string => (string)($currentPlayer->getKey()), $team); + $memberNames = array_map(static fn($currentPlayer): string => (string)($currentPlayer->getKey()), $team); $teamMemberNames = \implode(', ', $memberNames); diff --git a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php index db72d43..68888a4 100644 --- a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php +++ b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php @@ -55,7 +55,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer return $this->scheduleSequence( array_map( - fn ($prior): ScheduleStep => new ScheduleStep('Prior to Skill Step', $prior, 0), + static fn($prior): ScheduleStep => 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 80d66a9..bca879a 100644 --- a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php @@ -53,7 +53,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer return $this->scheduleSequence( array_map( - fn ($likelihood): ScheduleStep => new ScheduleStep('Skill to Perf step', $likelihood, 0), + static fn($likelihood): ScheduleStep => new ScheduleStep('Skill to Perf step', $likelihood, 0), $localFactors ), 'All skill to performance sending' @@ -66,7 +66,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer return $this->scheduleSequence( array_map( - fn ($likelihood): ScheduleStep => new ScheduleStep('name', $likelihood, 1), + static fn($likelihood): ScheduleStep => new ScheduleStep('name', $likelihood, 1), $localFactors ), 'All skill to performance sending' diff --git a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php index 57bfba7..53fa675 100644 --- a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php +++ b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php @@ -28,7 +28,7 @@ class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer $inputVarGroups = $this->getInputVariablesGroups(); $inputVarGroupsCount = count($inputVarGroups); - for ($i = 0; $i < $inputVarGroupsCount; $i++) { + for ($i = 0; $i < $inputVarGroupsCount; ++$i) { $isDraw = ($this->teamRanks[$i] == $this->teamRanks[$i + 1]); $teamDifference = $inputVarGroups[$i][0]; diff --git a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php index f7c9bc3..dddb5b8 100644 --- a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php +++ b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php @@ -15,7 +15,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG $inputVariablesGroupsCount = count($inputVariablesGroups); $outputVariablesGroup = &$this->getOutputVariablesGroups(); - for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) { + for ($i = 0; $i < $inputVariablesGroupsCount - 1; ++$i) { $strongerTeam = $inputVariablesGroups[$i][0]; $weakerTeam = $inputVariablesGroups[$i + 1][0]; diff --git a/src/TrueSkill/TrueSkillFactorGraph.php b/src/TrueSkill/TrueSkillFactorGraph.php index 064303b..495c4ef 100644 --- a/src/TrueSkill/TrueSkillFactorGraph.php +++ b/src/TrueSkill/TrueSkillFactorGraph.php @@ -39,7 +39,7 @@ class TrueSkillFactorGraph extends FactorGraph { $this->priorLayer = new PlayerPriorValuesToSkillsLayer($this, $teams); $newFactory = new VariableFactory( - fn (): GaussianDistribution => GaussianDistribution::fromPrecisionMean(0, 0) + static fn(): GaussianDistribution => GaussianDistribution::fromPrecisionMean(0, 0) ); $this->setVariableFactory($newFactory); diff --git a/src/TrueSkill/TwoTeamTrueSkillCalculator.php b/src/TrueSkill/TwoTeamTrueSkillCalculator.php index 5b611fe..2a1fba1 100644 --- a/src/TrueSkill/TwoTeamTrueSkillCalculator.php +++ b/src/TrueSkill/TwoTeamTrueSkillCalculator.php @@ -28,6 +28,7 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator { parent::__construct(SkillCalculatorSupportedOptions::NONE, TeamsRange::exactly(2), PlayersRange::atLeast(1)); } + /** * {@inheritdoc} */ @@ -82,12 +83,12 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator $totalPlayers = $selfTeam->count() + $otherTeam->count(); - $meanGetter = fn (Rating $currentRating): float => $currentRating->getMean(); + $meanGetter = static fn(Rating $currentRating): float => $currentRating->getMean(); $selfMeanSum = BasicMath::sum($selfTeam->getAllRatings(), $meanGetter); $otherTeamMeanSum = BasicMath::sum($otherTeam->getAllRatings(), $meanGetter); - $varianceGetter = fn (Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation()); + $varianceGetter = static fn(Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation()); $c = sqrt( BasicMath::sum($selfTeam->getAllRatings(), $varianceGetter) @@ -163,9 +164,9 @@ class TwoTeamTrueSkillCalculator extends SkillCalculator $betaSquared = BasicMath::square($gameInfo->getBeta()); - $meanGetter = fn (Rating $currentRating): float => $currentRating->getMean(); + $meanGetter = static fn(Rating $currentRating): float => $currentRating->getMean(); - $varianceGetter = fn (Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation()); + $varianceGetter = static fn(Rating $currentRating): float => BasicMath::square($currentRating->getStandardDeviation()); $team1MeanSum = BasicMath::sum($team1Ratings, $meanGetter); $team1StdDevSquared = BasicMath::sum($team1Ratings, $varianceGetter); diff --git a/tests/Numerics/BasicMathTest.php b/tests/Numerics/BasicMathTest.php index 8a538cb..f17c635 100644 --- a/tests/Numerics/BasicMathTest.php +++ b/tests/Numerics/BasicMathTest.php @@ -20,8 +20,8 @@ class BasicMathTest extends TestCase { $arr = [1, 1, 1, 1]; - $func_return = fn(float $f): float => $f; - $func_double = fn(float $f): float => $f * 2; + $func_return = static fn(float $f): float => $f; + $func_double = static fn(float $f): float => $f * 2; $this->assertEquals(4, BasicMath::sum($arr, $func_return)); $this->assertEquals(8, BasicMath::sum($arr, $func_double)); } diff --git a/tests/Numerics/MatrixTest.php b/tests/Numerics/MatrixTest.php index 1e0e684..e1a9df3 100644 --- a/tests/Numerics/MatrixTest.php +++ b/tests/Numerics/MatrixTest.php @@ -265,4 +265,5 @@ class MatrixTest extends TestCase Matrix::multiply($m1, $m2); } } + // phpcs:enable