diff --git a/src/FactorGraphs/Factor.php b/src/FactorGraphs/Factor.php index b0fbce6..2f1b1cf 100644 --- a/src/FactorGraphs/Factor.php +++ b/src/FactorGraphs/Factor.php @@ -8,12 +8,18 @@ use Exception; abstract class Factor implements \Stringable { + /** + * @var Message[] $messages + */ private array $messages = []; private HashMap $messageToVariableBinding; private string $name; + /** + * @var Variable[] $variables + */ private array $variables = []; protected function __construct(string $name) @@ -64,7 +70,7 @@ abstract class Factor implements \Stringable return $this->updateMessageVariable($message, $variable); } - protected function updateMessageVariable(Message $message, Variable $variable) + protected function updateMessageVariable(Message $message, Variable $variable): float { throw new Exception(); } @@ -82,13 +88,9 @@ abstract class Factor implements \Stringable /** * Sends the ith message to the marginal and returns the log-normalization constant - * - * @param $messageIndex - * @return - * * @throws Exception */ - public function sendMessageIndex($messageIndex) + public function sendMessageIndex(int $messageIndex): float|int { Guard::argumentIsValidIndex($messageIndex, count($this->messages), 'messageIndex'); @@ -98,7 +100,7 @@ abstract class Factor implements \Stringable return $this->sendMessageVariable($message, $variable); } - abstract protected function sendMessageVariable(Message $message, Variable $variable); + abstract protected function sendMessageVariable(Message $message, Variable $variable): float|int; abstract public function createVariableToMessageBinding(Variable $variable); diff --git a/src/FactorGraphs/FactorGraphLayer.php b/src/FactorGraphs/FactorGraphLayer.php index cf2561c..168dc98 100644 --- a/src/FactorGraphs/FactorGraphLayer.php +++ b/src/FactorGraphs/FactorGraphLayer.php @@ -4,6 +4,9 @@ namespace DNW\Skills\FactorGraphs; abstract class FactorGraphLayer { + /** + * @var Factor[] $localFactors + */ private array $localFactors = []; private array $outputVariablesGroups = []; @@ -34,6 +37,9 @@ abstract class FactorGraphLayer return $this->outputVariablesGroups; } + /** + * @return Factor[] + */ public function getLocalFactors(): array { return $this->localFactors; diff --git a/src/PartialPlay.php b/src/PartialPlay.php index 8f5d474..ad21385 100644 --- a/src/PartialPlay.php +++ b/src/PartialPlay.php @@ -4,7 +4,7 @@ namespace DNW\Skills; class PartialPlay { - public static function getPartialPlayPercentage($player) + public static function getPartialPlayPercentage(Player $player): float { // If the player doesn't support the interface, assume 1.0 == 100% $supportsPartialPlay = $player instanceof ISupportPartialPlay; diff --git a/src/TrueSkill/FactorGraphTrueSkillCalculator.php b/src/TrueSkill/FactorGraphTrueSkillCalculator.php index 2066e42..8c2c9fd 100644 --- a/src/TrueSkill/FactorGraphTrueSkillCalculator.php +++ b/src/TrueSkill/FactorGraphTrueSkillCalculator.php @@ -13,6 +13,7 @@ use DNW\Skills\PlayersRange; use DNW\Skills\RankSorter; use DNW\Skills\SkillCalculator; use DNW\Skills\SkillCalculatorSupportedOptions; +use DNW\Skills\Team; use DNW\Skills\TeamsRange; use DNW\Skills\RatingContainer; @@ -151,11 +152,9 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator $playerAssignments = []; $totalPreviousPlayers = 0; - $teamAssignmentsListCount = is_countable($teamAssignmentsList) ? count($teamAssignmentsList) : 0; - $currentColumn = 0; - for ($i = 0; $i < $teamAssignmentsListCount - 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 @@ -185,6 +184,6 @@ class FactorGraphTrueSkillCalculator extends SkillCalculator $currentColumn++; } - return Matrix::fromColumnValues($totalPlayers, $teamAssignmentsListCount - 1, $playerAssignments); + return Matrix::fromColumnValues($totalPlayers, count($teamAssignmentsList) - 1, $playerAssignments); } } diff --git a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php index d8070e9..9db37b2 100644 --- a/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php +++ b/src/TrueSkill/Layers/IteratedTeamDifferencesInnerLayer.php @@ -27,7 +27,7 @@ class IteratedTeamDifferencesInnerLayer extends TrueSkillFactorGraphLayer ); } - public function buildLayer() + public function buildLayer(): void { $inputVariablesGroups = $this->getInputVariablesGroups(); $this->TeamPerformancesToTeamPerformanceDifferencesLayer->setInputVariablesGroups($inputVariablesGroups);