From 4ddde1e277a2c587e47d6d3e24deaba7b03f47fe Mon Sep 17 00:00:00 2001 From: Jens True Date: Wed, 2 Aug 2023 14:14:10 +0000 Subject: [PATCH] More types for static analysis --- src/FactorGraphs/FactorGraphLayer.php | 6 +++--- src/RankSorter.php | 6 +++--- src/TrueSkill/Factors/GaussianWeightedSumFactor.php | 3 +-- .../Layers/IteratedTeamDifferencesInnerLayer.php | 8 ++++---- .../Layers/PlayerPerformancesToTeamPerformancesLayer.php | 4 ++-- src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php | 2 +- src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php | 4 ++-- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/FactorGraphs/FactorGraphLayer.php b/src/FactorGraphs/FactorGraphLayer.php index 168dc98..9a93145 100644 --- a/src/FactorGraphs/FactorGraphLayer.php +++ b/src/FactorGraphs/FactorGraphLayer.php @@ -60,14 +60,14 @@ abstract class FactorGraphLayer $this->localFactors[] = $factor; } - abstract public function buildLayer(); + abstract public function buildLayer(): void; - public function createPriorSchedule() + public function createPriorSchedule(): ?ScheduleSequence { return null; } - public function createPosteriorSchedule() + public function createPosteriorSchedule(): ?ScheduleSequence { return null; } diff --git a/src/RankSorter.php b/src/RankSorter.php index d75537b..011a09b 100644 --- a/src/RankSorter.php +++ b/src/RankSorter.php @@ -10,9 +10,9 @@ class RankSorter /** * Performs an in-place sort of the items in according to the ranks in non-decreasing order. * - * @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 + * @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 */ public static function sort(array &$teams, array &$teamRanks): array { diff --git a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php index 1bb3ce3..eff1e34 100644 --- a/src/TrueSkill/Factors/GaussianWeightedSumFactor.php +++ b/src/TrueSkill/Factors/GaussianWeightedSumFactor.php @@ -198,8 +198,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 - $allMessagesCount = is_countable($allMessages) ? count($allMessages) : 0; - for ($i = 0; $i < $allMessagesCount; $i++) { + for ($i = 0; $i < count($allMessages); $i++) { $updatedMessages[] = $allMessages[$indicesToUse[$i]]; $updatedVariables[] = $allVariables[$indicesToUse[$i]]; } diff --git a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php index 4e687da..e9a5036 100644 --- a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php +++ b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php @@ -38,7 +38,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer $this->TeamDifferencesComparisonLayer->buildLayer(); } - public function createPriorSchedule(): ScheduleSequence + public function createPriorSchedule(): ?ScheduleSequence { switch (is_countable($this->getInputVariablesGroups()) ? count($this->getInputVariablesGroups()) : 0) { case 0: @@ -78,7 +78,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer ); } - private function createTwoTeamInnerPriorLoopSchedule() + private function createTwoTeamInnerPriorLoopSchedule(): ScheduleSequence { $teamPerformancesToTeamPerformanceDifferencesLayerLocalFactors = $this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors(); $teamDifferencesComparisonLayerLocalFactors = $this->TeamDifferencesComparisonLayer->getLocalFactors(); @@ -104,9 +104,9 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer ); } - private function createMultipleTeamInnerPriorLoopSchedule() + private function createMultipleTeamInnerPriorLoopSchedule(): ScheduleLoop { - $totalTeamDifferences = is_countable($this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors()) ? count($this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors()) : 0; + $totalTeamDifferences = count($this->TeamPerformancesToTeamPerformanceDifferencesLayer->getLocalFactors()); $forwardScheduleList = []; diff --git a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php index 6ea086f..0a968b5 100644 --- a/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerPerformancesToTeamPerformancesLayer.php @@ -26,7 +26,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye } } - public function createPriorSchedule(): ScheduleSequence + public function createPriorSchedule(): ?ScheduleSequence { $localFactors = $this->getLocalFactors(); @@ -57,7 +57,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye ); } - public function createPosteriorSchedule(): ScheduleSequence + public function createPosteriorSchedule(): ?ScheduleSequence { $allFactors = []; $localFactors = $this->getLocalFactors(); diff --git a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php index f98aa62..bb8e781 100644 --- a/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php +++ b/src/TrueSkill/Layers/PlayerPriorValuesToSkillsLayer.php @@ -42,7 +42,7 @@ class PlayerPriorValuesToSkillsLayer extends TrueSkillFactorGraphLayer } } - public function createPriorSchedule(): ScheduleSequence + public function createPriorSchedule(): ?ScheduleSequence { $localFactors = $this->getLocalFactors(); diff --git a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php index d6e7717..4870e17 100644 --- a/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php +++ b/src/TrueSkill/Layers/PlayerSkillsToPerformancesLayer.php @@ -45,7 +45,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer return $this->getParentFactorGraph()->getVariableFactory()->createKeyedVariable($key, $key . "'s performance"); } - public function createPriorSchedule(): ScheduleSequence + public function createPriorSchedule(): ?ScheduleSequence { $localFactors = $this->getLocalFactors(); @@ -58,7 +58,7 @@ class PlayerSkillsToPerformancesLayer extends TrueSkillFactorGraphLayer ); } - public function createPosteriorSchedule(): ScheduleSequence + public function createPosteriorSchedule(): ?ScheduleSequence { $localFactors = $this->getLocalFactors();