diff --git a/src/FactorGraphs/DefaultVariable.php b/src/FactorGraphs/DefaultVariable.php deleted file mode 100644 index 96cc5f0..0000000 --- a/src/FactorGraphs/DefaultVariable.php +++ /dev/null @@ -1,24 +0,0 @@ -_messageToVariableBinding->setValue($message, $variable); $this->_messages[] = $message; diff --git a/src/FactorGraphs/KeyedVariable.php b/src/FactorGraphs/KeyedVariable.php index 465e10b..f064f0c 100644 --- a/src/FactorGraphs/KeyedVariable.php +++ b/src/FactorGraphs/KeyedVariable.php @@ -4,12 +4,12 @@ namespace DNW\Skills\FactorGraphs; class KeyedVariable extends Variable { - public function __construct(private $_key, $name, $prior) + public function __construct(private mixed $_key, string $name, mixed $prior) { parent::__construct($name, $prior); } - public function getKey() + public function getKey(): mixed { return $this->_key; } diff --git a/src/FactorGraphs/Variable.php b/src/FactorGraphs/Variable.php index f3e8f42..81a2139 100644 --- a/src/FactorGraphs/Variable.php +++ b/src/FactorGraphs/Variable.php @@ -24,7 +24,7 @@ class Variable implements \Stringable $this->_value = $value; } - public function resetToPrior() + public function resetToPrior(): void { $this->_value = $this->_prior; } diff --git a/src/FactorGraphs/VariableFactory.php b/src/FactorGraphs/VariableFactory.php index c20c73f..d645c0b 100644 --- a/src/FactorGraphs/VariableFactory.php +++ b/src/FactorGraphs/VariableFactory.php @@ -8,14 +8,14 @@ class VariableFactory { } - public function createBasicVariable($name) + public function createBasicVariable(string $name): Variable { $initializer = $this->_variablePriorInitializer; return new Variable($name, $initializer()); } - public function createKeyedVariable($key, $name) + public function createKeyedVariable(mixed $key, string $name): KeyedVariable { $initializer = $this->_variablePriorInitializer; diff --git a/src/HashMap.php b/src/HashMap.php index b45056c..b951eb9 100644 --- a/src/HashMap.php +++ b/src/HashMap.php @@ -11,14 +11,14 @@ class HashMap private array $_hashToKey = []; - public function getValue($key) + public function getValue(string|object $key): mixed { $hash = self::getHash($key); return $this->_hashToValue[$hash]; } - public function setValue($key, $value) + public function setValue(string|object $key, mixed $value): self { $hash = self::getHash($key); $this->_hashToKey[$hash] = $key; @@ -27,22 +27,22 @@ class HashMap return $this; } - public function getAllKeys() + public function getAllKeys(): array { return array_values($this->_hashToKey); } - public function getAllValues() + public function getAllValues(): array { return array_values($this->_hashToValue); } - public function count() + public function count(): int { return count($this->_hashToKey); } - private static function getHash($key) + private static function getHash(string|Object $key): string { if (is_object($key)) { return spl_object_hash($key); diff --git a/src/RatingContainer.php b/src/RatingContainer.php index ec62d4c..98532a7 100644 --- a/src/RatingContainer.php +++ b/src/RatingContainer.php @@ -4,34 +4,34 @@ namespace DNW\Skills; class RatingContainer { - private $_playerToRating; + private HashMap $_playerToRating; public function __construct() { $this->_playerToRating = new HashMap(); } - public function getRating(Player $player) + public function getRating(Player $player): mixed { return $this->_playerToRating->getValue($player); } - public function setRating(Player $player, Rating $rating) + public function setRating(Player $player, Rating $rating): HashMap { return $this->_playerToRating->setValue($player, $rating); } - public function getAllPlayers() + public function getAllPlayers(): array { return $this->_playerToRating->getAllKeys(); } - public function getAllRatings() + public function getAllRatings(): array { return $this->_playerToRating->getAllValues(); } - public function count() + public function count(): int { return $this->_playerToRating->count(); } diff --git a/src/TrueSkill/DrawMargin.php b/src/TrueSkill/DrawMargin.php index 83d1353..9f09d2c 100644 --- a/src/TrueSkill/DrawMargin.php +++ b/src/TrueSkill/DrawMargin.php @@ -6,7 +6,7 @@ use DNW\Skills\Numerics\GaussianDistribution; final class DrawMargin { - public static function getDrawMarginFromDrawProbability($drawProbability, $beta) + public static function getDrawMarginFromDrawProbability(float $drawProbability, float $beta): float { // Derived from TrueSkill technical report (MSR-TR-2006-80), page 6 diff --git a/src/TrueSkill/Factors/GaussianFactor.php b/src/TrueSkill/Factors/GaussianFactor.php index 82dd312..98ed2a0 100644 --- a/src/TrueSkill/Factors/GaussianFactor.php +++ b/src/TrueSkill/Factors/GaussianFactor.php @@ -22,7 +22,7 @@ abstract class GaussianFactor extends Factor return $logZ; } - public function createVariableToMessageBinding(Variable $variable) + public function createVariableToMessageBinding(Variable $variable): Message { $newDistribution = GaussianDistribution::fromPrecisionMean(0, 0);