From 22cc0da96d60599df157b7d4359a4aa0307e50ed Mon Sep 17 00:00:00 2001 From: Jens True Date: Thu, 3 Aug 2023 13:08:04 +0000 Subject: [PATCH] Getting rid of more warnings. --- src/FactorGraphs/FactorGraphLayer.php | 20 +++++++++++++++++-- src/Numerics/DiagonalMatrix.php | 3 +++ src/Numerics/Matrix.php | 6 ++++++ src/RankSorter.php | 2 +- .../FactorGraphTrueSkillCalculator.php | 6 +++--- .../Factors/GaussianWeightedSumFactor.php | 4 ++++ .../IteratedTeamDifferencesInnerLayer.php | 2 +- ...yerPerformancesToTeamPerformancesLayer.php | 6 +++++- .../Layers/TeamDifferencesComparisonLayer.php | 2 +- ...ancesToTeamPerformanceDifferencesLayer.php | 2 +- 10 files changed, 43 insertions(+), 10 deletions(-) diff --git a/src/FactorGraphs/FactorGraphLayer.php b/src/FactorGraphs/FactorGraphLayer.php index 9a93145..baba1d0 100644 --- a/src/FactorGraphs/FactorGraphLayer.php +++ b/src/FactorGraphs/FactorGraphLayer.php @@ -1,6 +1,7 @@ > + */ private array $outputVariablesGroups = []; - + /** + * @var array> + */ private $inputVariablesGroups = []; protected function __construct(private readonly FactorGraph $parentFactorGraph) { } - protected function getInputVariablesGroups() + /** + * @return array> + */ + protected function getInputVariablesGroups(): array { return $this->inputVariablesGroups; } @@ -31,6 +40,7 @@ abstract class FactorGraphLayer /** * This reference is still needed + * @return array> */ public function &getOutputVariablesGroups(): array { @@ -45,11 +55,17 @@ abstract class FactorGraphLayer return $this->localFactors; } + /** + * @param array> $value + */ public function setInputVariablesGroups(array $value): void { $this->inputVariablesGroups = $value; } + /** + * @param Schedule[] $itemsToSequence + */ protected function scheduleSequence(array $itemsToSequence, string $name): ScheduleSequence { return new ScheduleSequence($name, $itemsToSequence); diff --git a/src/Numerics/DiagonalMatrix.php b/src/Numerics/DiagonalMatrix.php index 1af912d..c6882e1 100644 --- a/src/Numerics/DiagonalMatrix.php +++ b/src/Numerics/DiagonalMatrix.php @@ -4,6 +4,9 @@ namespace DNW\Skills\Numerics; class DiagonalMatrix extends Matrix { + /** + * @param float[] $diagonalValues + */ public function __construct(array $diagonalValues) { $diagonalCount = count($diagonalValues); diff --git a/src/Numerics/Matrix.php b/src/Numerics/Matrix.php index 11343f9..9081825 100644 --- a/src/Numerics/Matrix.php +++ b/src/Numerics/Matrix.php @@ -8,10 +8,16 @@ class Matrix { public const ERROR_TOLERANCE = 0.0000000001; + /** + * @param array> $matrixRowData + */ public function __construct(private int $rowCount = 0, private int $columnCount = 0, private array $matrixRowData = array()) { } + /** + * @param array> $columnValues + */ public static function fromColumnValues(int $rows, int $columns, array $columnValues): self { $data = []; diff --git a/src/RankSorter.php b/src/RankSorter.php index 8b9e344..7cd8cf6 100644 --- a/src/RankSorter.php +++ b/src/RankSorter.php @@ -12,7 +12,7 @@ class RankSorter * * @param array $teams The items to sort according to the order specified by ranks. * @param array $teamRanks The ranks for each item where 1 is first place. - * @return array + * @return array */ public static function sort(array &$teams, array &$teamRanks): array { diff --git a/src/TrueSkill/FactorGraphTrueSkillCalculator.php b/src/TrueSkill/FactorGraphTrueSkillCalculator.php index 28d25ef..fc9acfe 100644 --- a/src/TrueSkill/FactorGraphTrueSkillCalculator.php +++ b/src/TrueSkill/FactorGraphTrueSkillCalculator.php @@ -92,7 +92,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator } /** - * @var Team[] $teamAssignmentsList + * @param Team[] $teamAssignmentsList */ private static function getPlayerMeansVector(array $teamAssignmentsList): Vector { @@ -106,7 +106,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator } /** - * @var Team[] $teamAssignmentsList + * @param Team[] $teamAssignmentsList */ private static function getPlayerCovarianceMatrix(array $teamAssignmentsList): DiagonalMatrix { @@ -123,7 +123,7 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator /** * Helper function that gets a list of values for all player ratings - * @var Team[] $teamAssignmentsList + * @param Team[] $teamAssignmentsList * @return int[] */ private static function getPlayerRatingValues(array $teamAssignmentsList, \Closure $playerRatingFunction): array diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index 907f840..df84d8f 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -230,6 +230,10 @@ class GaussianWeightedSumFactor extends GaussianFactor ); } + /** + * @param Variable[] $variablesToSum + * @param float[] $weights + */ private static function createName(string $sumVariable, array $variablesToSum, array $weights): string { // TODO: Perf? Use PHP equivalent of StringBuilder? implode on arrays? diff --git a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php index e9a5036..76dc02f 100644 --- a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php +++ b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php @@ -40,7 +40,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer public function createPriorSchedule(): ?ScheduleSequence { - switch (is_countable($this->getInputVariablesGroups()) ? count($this->getInputVariablesGroups()) : 0) { + switch (count($this->getInputVariablesGroups())) { case 0: case 1: throw new Exception('InvalidOperation'); diff --git a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php index 1260ec3..47ba4d4 100644 --- a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php @@ -9,6 +9,7 @@ use DNW\Skills\Player; use DNW\Skills\Team; use DNW\Skills\TrueSkill\Factors\GaussianWeightedSumFactor; use DNW\Skills\FactorGraphs\Variable; +use DNW\Skills\FactorGraphs\KeyedVariable; class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLayer { @@ -42,7 +43,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye } /** - * @param Team[] $teamMembers + * @param KeyedVariable[] $teamMembers */ protected function createPlayerToTeamSumFactor(array $teamMembers, Variable $sumVariable): GaussianWeightedSumFactor { @@ -81,6 +82,9 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye return $this->scheduleSequence($allFactors, "all of the team's sum iterations"); } + /** + * @param KeyedVariable[] $team + */ private function createOutputVariable(array $team): Variable { $memberNames = array_map(fn ($currentPlayer) => (string) ($currentPlayer->getKey()), $team); diff --git a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php index 2c824e5..6b3b06e 100644 --- a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php +++ b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php @@ -24,7 +24,7 @@ class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer public function buildLayer(): void { $inputVarGroups = $this->getInputVariablesGroups(); - $inputVarGroupsCount = is_countable($inputVarGroups) ? count($inputVarGroups) : 0; + $inputVarGroupsCount = count($inputVarGroups); for ($i = 0; $i < $inputVarGroupsCount; $i++) { $isDraw = ($this->teamRanks[$i] == $this->teamRanks[$i + 1]); diff --git a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php index b63f8f3..00e5adc 100644 --- a/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php +++ b/src/TrueSkill/Layers/TeamPerformancesToTeamPerformanceDifferencesLayer.php @@ -10,7 +10,7 @@ class TeamPerformancesToTeamPerformanceDifferencesLayer extends TrueSkillFactorG public function buildLayer(): void { $inputVariablesGroups = $this->getInputVariablesGroups(); - $inputVariablesGroupsCount = is_countable($inputVariablesGroups) ? count($inputVariablesGroups) : 0; + $inputVariablesGroupsCount = count($inputVariablesGroups); $outputVariablesGroup = &$this->getOutputVariablesGroups(); for ($i = 0; $i < $inputVariablesGroupsCount - 1; $i++) {