mirror of
				https://github.com/furyfire/trueskill.git
				synced 2025-11-04 02:02:29 +01:00 
			
		
		
		
	More code standards
This commit is contained in:
		@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\Guard;
 | 
			
		||||
@@ -94,6 +96,7 @@ abstract class Factor implements \Stringable
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sends the ith message to the marginal and returns the log-normalization constant
 | 
			
		||||
     *
 | 
			
		||||
     * @throws Exception
 | 
			
		||||
     */
 | 
			
		||||
    public function sendMessageIndex(int $messageIndex): float|int
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\FactorGraphs\ScheduleSequence;
 | 
			
		||||
@@ -42,6 +44,7 @@ abstract class FactorGraphLayer
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This reference is still needed
 | 
			
		||||
     *
 | 
			
		||||
     * @return array<int,array<int,object>>
 | 
			
		||||
     */
 | 
			
		||||
    public function &getOutputVariablesGroups(): array
 | 
			
		||||
@@ -82,11 +85,11 @@ abstract class FactorGraphLayer
 | 
			
		||||
 | 
			
		||||
    public function createPriorSchedule(): ?ScheduleSequence
 | 
			
		||||
    {
 | 
			
		||||
        return null;
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function createPosteriorSchedule(): ?ScheduleSequence
 | 
			
		||||
    {
 | 
			
		||||
        return null;
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
class ScheduleLoop extends Schedule
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
class ScheduleSequence extends Schedule
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
class ScheduleStep extends Schedule
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\Numerics\GaussianDistribution;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\FactorGraphs;
 | 
			
		||||
 | 
			
		||||
class VariableFactory
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -23,7 +25,8 @@ class GameInfo
 | 
			
		||||
        private float $beta = self::DEFAULT_BETA,
 | 
			
		||||
        private float $dynamicsFactor = self::DEFAULT_DYNAMICS_FACTOR,
 | 
			
		||||
        private float $drawProbability = self::DEFAULT_DRAW_PROBABILITY
 | 
			
		||||
    ) {
 | 
			
		||||
    )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getInitialMean(): float
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ class Guard
 | 
			
		||||
{
 | 
			
		||||
    public static function argumentNotNull(mixed $value, string $parameterName): void
 | 
			
		||||
    {
 | 
			
		||||
        if ($value == null) {
 | 
			
		||||
        if ($value == NULL) {
 | 
			
		||||
            throw new Exception($parameterName . ' can not be null');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\Numerics;
 | 
			
		||||
 | 
			
		||||
class DiagonalMatrix extends Matrix
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\Numerics;
 | 
			
		||||
 | 
			
		||||
use Exception;
 | 
			
		||||
@@ -11,7 +13,7 @@ class Matrix
 | 
			
		||||
    /**
 | 
			
		||||
     * @param array<int,array<int,float>> $matrixRowData
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(private int $rowCount = 0, private int $columnCount = 0, private array $matrixRowData = array())
 | 
			
		||||
    public function __construct(private int $rowCount = 0, private int $columnCount = 0, private array $matrixRowData = [])
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -307,7 +309,7 @@ class Matrix
 | 
			
		||||
    public function equals(Matrix $otherMatrix): bool
 | 
			
		||||
    {
 | 
			
		||||
        if (($this->rowCount != $otherMatrix->getRowCount()) || ($this->columnCount != $otherMatrix->getColumnCount())) {
 | 
			
		||||
            return false;
 | 
			
		||||
            return FALSE;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for ($currentRow = 0; $currentRow < $this->rowCount; $currentRow++) {
 | 
			
		||||
@@ -319,11 +321,11 @@ class Matrix
 | 
			
		||||
                    );
 | 
			
		||||
 | 
			
		||||
                if ($delta > self::ERROR_TOLERANCE) {
 | 
			
		||||
                    return false;
 | 
			
		||||
                    return FALSE;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
        return TRUE;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@@ -10,8 +12,9 @@ class RankSorter
 | 
			
		||||
    /**
 | 
			
		||||
     * Performs an in-place sort of the items in according to the ranks in non-decreasing order.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  array<mixed> $teams     The items to sort according to the order specified by ranks.
 | 
			
		||||
     * @param  array<int>   $teamRanks The ranks for each item where 1 is first place.
 | 
			
		||||
     * @param array<mixed> $teams     The items to sort according to the order specified by ranks.
 | 
			
		||||
     * @param array<int>   $teamRanks The ranks for each item where 1 is first place.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array<int>
 | 
			
		||||
     */
 | 
			
		||||
    public static function sort(array &$teams, array &$teamRanks): array
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills;
 | 
			
		||||
 | 
			
		||||
use Exception;
 | 
			
		||||
@@ -13,15 +15,17 @@ abstract class SkillCalculator
 | 
			
		||||
        private int $supportedOptions,
 | 
			
		||||
        private readonly TeamsRange $totalTeamsAllowed,
 | 
			
		||||
        private readonly PlayersRange $playersPerTeamAllowed
 | 
			
		||||
    ) {
 | 
			
		||||
    )
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Calculates new ratings based on the prior ratings and team ranks.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  GameInfo $gameInfo  Parameters for the game.
 | 
			
		||||
     * @param  Team[]   $teams     A mapping of team players and their ratings.
 | 
			
		||||
     * @param  int[]    $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2).
 | 
			
		||||
     * @param GameInfo $gameInfo  Parameters for the game.
 | 
			
		||||
     * @param Team[]   $teams     A mapping of team players and their ratings.
 | 
			
		||||
     * @param int[]    $teamRanks The ranks of the teams where 1 is first place. For a tie, repeat the number (e.g. 1, 2, 2).
 | 
			
		||||
     *
 | 
			
		||||
     * @return RatingContainer All the players and their new ratings.
 | 
			
		||||
     */
 | 
			
		||||
    abstract public function calculateNewRatings(
 | 
			
		||||
@@ -35,6 +39,7 @@ abstract class SkillCalculator
 | 
			
		||||
     *
 | 
			
		||||
     * @param  GameInfo $gameInfo Parameters for the game.
 | 
			
		||||
     * @param  Team[]   $teams    A mapping of team players and their ratings.
 | 
			
		||||
     *
 | 
			
		||||
     * @return float The quality of the match between the teams as a percentage (0% = bad, 100% = well matched).
 | 
			
		||||
     */
 | 
			
		||||
    abstract public function calculateMatchQuality(GameInfo $gameInfo, array $teams): float;
 | 
			
		||||
 
 | 
			
		||||
@@ -4,7 +4,7 @@ namespace DNW\Skills;
 | 
			
		||||
 | 
			
		||||
class Team extends RatingContainer
 | 
			
		||||
{
 | 
			
		||||
    public function __construct(Player $player = null, Rating $rating = null)
 | 
			
		||||
    public function __construct(Player $player = NULL, Rating $rating = NULL)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills;
 | 
			
		||||
 | 
			
		||||
class Teams
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\Numerics\Range;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\Numerics\GaussianDistribution;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill\Factors;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\FactorGraphs\Message;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill\Layers;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\FactorGraphs\ScheduleLoop;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill\Layers;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\FactorGraphs\ScheduleStep;
 | 
			
		||||
@@ -87,7 +89,7 @@ class PlayerPerformancesToTeamPerformancesLayer extends TrueSkillFactorGraphLaye
 | 
			
		||||
     */
 | 
			
		||||
    private function createOutputVariable(array $team): Variable
 | 
			
		||||
    {
 | 
			
		||||
        $memberNames = array_map(fn ($currentPlayer) => (string) ($currentPlayer->getKey()), $team);
 | 
			
		||||
        $memberNames = array_map(fn ($currentPlayer) => (string)($currentPlayer->getKey()), $team);
 | 
			
		||||
 | 
			
		||||
        $teamMemberNames = \implode(', ', $memberNames);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill\Layers;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\FactorGraphs\ScheduleStep;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill\Layers;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\FactorGraphs\KeyedVariable;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill\Layers;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\TrueSkill\DrawMargin;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill\Layers;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\FactorGraphs\Variable;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\FactorGraphs\FactorGraph;
 | 
			
		||||
@@ -60,11 +62,11 @@ class TrueSkillFactorGraph extends FactorGraph
 | 
			
		||||
 | 
			
		||||
    public function buildGraph(): void
 | 
			
		||||
    {
 | 
			
		||||
        $lastOutput = null;
 | 
			
		||||
        $lastOutput = NULL;
 | 
			
		||||
 | 
			
		||||
        $layers = $this->layers;
 | 
			
		||||
        foreach ($layers as $currentLayer) {
 | 
			
		||||
            if ($lastOutput != null) {
 | 
			
		||||
            if ($lastOutput != NULL) {
 | 
			
		||||
                $currentLayer->setInputVariablesGroups($lastOutput);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -105,7 +107,7 @@ class TrueSkillFactorGraph extends FactorGraph
 | 
			
		||||
        $layers = $this->layers;
 | 
			
		||||
        foreach ($layers as $currentLayer) {
 | 
			
		||||
            $currentPriorSchedule = $currentLayer->createPriorSchedule();
 | 
			
		||||
            if ($currentPriorSchedule != null) {
 | 
			
		||||
            if ($currentPriorSchedule != NULL) {
 | 
			
		||||
                $fullSchedule[] = $currentPriorSchedule;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -114,7 +116,7 @@ class TrueSkillFactorGraph extends FactorGraph
 | 
			
		||||
 | 
			
		||||
        foreach ($allLayersReverse as $currentLayer) {
 | 
			
		||||
            $currentPosteriorSchedule = $currentLayer->createPosteriorSchedule();
 | 
			
		||||
            if ($currentPosteriorSchedule != null) {
 | 
			
		||||
            if ($currentPosteriorSchedule != NULL) {
 | 
			
		||||
                $fullSchedule[] = $currentPosteriorSchedule;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\Numerics\GaussianDistribution;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\GameInfo;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
declare(strict_types=1);
 | 
			
		||||
 | 
			
		||||
namespace DNW\Skills\TrueSkill;
 | 
			
		||||
 | 
			
		||||
use DNW\Skills\GameInfo;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user