diff --git a/composer.json b/composer.json index af7034a..66587c0 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,8 @@ "vimeo/psalm": "^5.21.1", "phpmetrics/phpmetrics": "^3.0-dev", "phpunit/phpunit": "^10.5", - "psalm/plugin-phpunit": "^0.18.4" + "psalm/plugin-phpunit": "^0.18.4", + "rector/rector": "^1.0" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index a281070..0ccf7d9 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ae420a83c061b5eb7f6ec5487f01643a", + "content-hash": "ba51339b2bd54ead227bc16656795670", "packages": [], "packages-dev": [ { @@ -1925,6 +1925,62 @@ }, "time": "2021-07-14T16:46:02+00:00" }, + { + "name": "rector/rector", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "258b775511e62a7188f8ce114d44acaf244d9a7d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/258b775511e62a7188f8ce114d44acaf244d9a7d", + "reference": "258b775511e62a7188f8ce114d44acaf244d9a7d", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0", + "phpstan/phpstan": "^1.10.57" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/1.0.1" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2024-02-16T07:53:23+00:00" + }, { "name": "sebastian/cli-parser", "version": "2.0.0", diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..00c5a54 --- /dev/null +++ b/rector.php @@ -0,0 +1,19 @@ +withPaths([ + __DIR__ . '/benchmark', + __DIR__ . '/examples', + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + ->withPhpSets() + ->withRules([ + AddVoidReturnTypeWhereNoReturnRector::class, + ]); diff --git a/src/FactorGraphs/Factor.php b/src/FactorGraphs/Factor.php index d1c5636..a17dca4 100644 --- a/src/FactorGraphs/Factor.php +++ b/src/FactorGraphs/Factor.php @@ -15,9 +15,9 @@ abstract class Factor implements \Stringable */ private array $messages = []; - private HashMap $messageToVariableBinding; + private readonly HashMap $messageToVariableBinding; - private string $name; + private readonly string $name; /** * @var Variable[] $variables diff --git a/src/FactorGraphs/KeyedVariable.php b/src/FactorGraphs/KeyedVariable.php index f1f29a3..006e160 100644 --- a/src/FactorGraphs/KeyedVariable.php +++ b/src/FactorGraphs/KeyedVariable.php @@ -6,7 +6,7 @@ namespace DNW\Skills\FactorGraphs; class KeyedVariable extends Variable { - public function __construct(private mixed $key, string $name, mixed $prior) + public function __construct(private readonly mixed $key, string $name, mixed $prior) { parent::__construct($name, $prior); } diff --git a/src/FactorGraphs/Message.php b/src/FactorGraphs/Message.php index 3bda804..fbdbc4f 100644 --- a/src/FactorGraphs/Message.php +++ b/src/FactorGraphs/Message.php @@ -8,7 +8,7 @@ use DNW\Skills\Numerics\GaussianDistribution; class Message implements \Stringable { - public function __construct(private GaussianDistribution $value, private string $name) + public function __construct(private GaussianDistribution $value, private readonly string $name) { } diff --git a/src/FactorGraphs/Schedule.php b/src/FactorGraphs/Schedule.php index f49ede6..f350278 100644 --- a/src/FactorGraphs/Schedule.php +++ b/src/FactorGraphs/Schedule.php @@ -6,7 +6,7 @@ namespace DNW\Skills\FactorGraphs; abstract class Schedule implements \Stringable { - protected function __construct(private string $name) + protected function __construct(private readonly string $name) { } diff --git a/src/FactorGraphs/ScheduleLoop.php b/src/FactorGraphs/ScheduleLoop.php index 3d3c2ab..f279528 100644 --- a/src/FactorGraphs/ScheduleLoop.php +++ b/src/FactorGraphs/ScheduleLoop.php @@ -6,7 +6,7 @@ namespace DNW\Skills\FactorGraphs; class ScheduleLoop extends Schedule { - public function __construct(string $name, private readonly Schedule $scheduleToLoop, private float $maxDelta) + public function __construct(string $name, private readonly Schedule $scheduleToLoop, private readonly float $maxDelta) { parent::__construct($name); } diff --git a/src/FactorGraphs/ScheduleStep.php b/src/FactorGraphs/ScheduleStep.php index 9737370..e54568c 100644 --- a/src/FactorGraphs/ScheduleStep.php +++ b/src/FactorGraphs/ScheduleStep.php @@ -6,7 +6,7 @@ namespace DNW\Skills\FactorGraphs; class ScheduleStep extends Schedule { - public function __construct(string $name, private readonly Factor $factor, private int $index) + public function __construct(string $name, private readonly Factor $factor, private readonly int $index) { parent::__construct($name); } diff --git a/src/FactorGraphs/Variable.php b/src/FactorGraphs/Variable.php index 67b0357..77cdfc0 100644 --- a/src/FactorGraphs/Variable.php +++ b/src/FactorGraphs/Variable.php @@ -8,7 +8,7 @@ use DNW\Skills\Numerics\GaussianDistribution; class Variable implements \Stringable { - private string $name; + private readonly string $name; private mixed $value; diff --git a/src/GameInfo.php b/src/GameInfo.php index 01e2afc..81d0c4d 100644 --- a/src/GameInfo.php +++ b/src/GameInfo.php @@ -20,11 +20,11 @@ class GameInfo private const DEFAULT_INITIAL_STANDARD_DEVIATION = 8.3333333333333333333333333333333; public function __construct( - private float $initialMean = self::DEFAULT_INITIAL_MEAN, - private float $initialStandardDeviation = self::DEFAULT_INITIAL_STANDARD_DEVIATION, - private float $beta = self::DEFAULT_BETA, - private float $dynamicsFactor = self::DEFAULT_DYNAMICS_FACTOR, - private float $drawProbability = self::DEFAULT_DRAW_PROBABILITY + private readonly float $initialMean = self::DEFAULT_INITIAL_MEAN, + private readonly float $initialStandardDeviation = self::DEFAULT_INITIAL_STANDARD_DEVIATION, + private readonly float $beta = self::DEFAULT_BETA, + private readonly float $dynamicsFactor = self::DEFAULT_DYNAMICS_FACTOR, + private readonly float $drawProbability = self::DEFAULT_DRAW_PROBABILITY ) { } diff --git a/src/Numerics/Matrix.php b/src/Numerics/Matrix.php index edc5d9b..948c918 100644 --- a/src/Numerics/Matrix.php +++ b/src/Numerics/Matrix.php @@ -13,7 +13,7 @@ class Matrix /** * @param array> $matrixRowData */ - public function __construct(private int $rowCount = 0, private int $columnCount = 0, private array $matrixRowData = []) + public function __construct(private readonly int $rowCount = 0, private readonly int $columnCount = 0, private array $matrixRowData = []) { } diff --git a/src/Numerics/Range.php b/src/Numerics/Range.php index 183f408..793427c 100644 --- a/src/Numerics/Range.php +++ b/src/Numerics/Range.php @@ -11,7 +11,7 @@ use Exception; class Range { - final public function __construct(private int $min, private int $max) + final public function __construct(private readonly int $min, private readonly int $max) { if ($min > $max) { throw new Exception('min > max'); diff --git a/src/Player.php b/src/Player.php index 7b5f07b..5eb2241 100644 --- a/src/Player.php +++ b/src/Player.php @@ -13,9 +13,9 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate, \Stringable private const DEFAULT_PARTIAL_UPDATE_PERCENTAGE = 1.0; - private float $PartialPlayPercentage; + private readonly float $PartialPlayPercentage; - private float $PartialUpdatePercentage; + private readonly float $PartialUpdatePercentage; /** * Constructs a player. @@ -25,7 +25,7 @@ class Player implements ISupportPartialPlay, ISupportPartialUpdate, \Stringable * @param float $partialUpdatePercentage Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update. */ public function __construct( - private mixed $Id, + private readonly mixed $Id, float $partialPlayPercentage = self::DEFAULT_PARTIAL_PLAY_PERCENTAGE, float $partialUpdatePercentage = self::DEFAULT_PARTIAL_UPDATE_PERCENTAGE ) diff --git a/src/Rating.php b/src/Rating.php index 2d63b47..b599b71 100644 --- a/src/Rating.php +++ b/src/Rating.php @@ -18,7 +18,7 @@ class Rating implements \Stringable * @param float $standardDeviation The standard deviation of the rating (also known as s). * @param float|int $conservativeStandardDeviationMultiplier optional The number of standardDeviations to subtract from the mean to achieve a conservative rating. */ - public function __construct(private float $mean, private float $standardDeviation, private float|int $conservativeStandardDeviationMultiplier = self::CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER) + public function __construct(private readonly float $mean, private readonly float $standardDeviation, private readonly float|int $conservativeStandardDeviationMultiplier = self::CONSERVATIVE_STANDARD_DEVIATION_MULTIPLIER) { } diff --git a/src/RatingContainer.php b/src/RatingContainer.php index 26aa576..0b05dfa 100644 --- a/src/RatingContainer.php +++ b/src/RatingContainer.php @@ -6,7 +6,7 @@ namespace DNW\Skills; class RatingContainer { - private HashMap $playerToRating; + private readonly HashMap $playerToRating; public function __construct() { diff --git a/src/SkillCalculator.php b/src/SkillCalculator.php index b09b5d5..6c99fb2 100644 --- a/src/SkillCalculator.php +++ b/src/SkillCalculator.php @@ -12,7 +12,7 @@ use Exception; abstract class SkillCalculator { protected function __construct( - private int $supportedOptions, + private readonly int $supportedOptions, private readonly TeamsRange $totalTeamsAllowed, private readonly PlayersRange $playersPerTeamAllowed ) diff --git a/src/TrueSkill/Factors/GaussianGreaterThanFactor.php b/src/TrueSkill/Factors/GaussianGreaterThanFactor.php index 53e3934..19e41c5 100644 --- a/src/TrueSkill/Factors/GaussianGreaterThanFactor.php +++ b/src/TrueSkill/Factors/GaussianGreaterThanFactor.php @@ -16,7 +16,7 @@ use DNW\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions; */ class GaussianGreaterThanFactor extends GaussianFactor { - private float $epsilon; + private readonly float $epsilon; public function __construct(float $epsilon, Variable $variable) { diff --git a/src/TrueSkill/Factors/GaussianLikelihoodFactor.php b/src/TrueSkill/Factors/GaussianLikelihoodFactor.php index a512eba..7e7f7f1 100644 --- a/src/TrueSkill/Factors/GaussianLikelihoodFactor.php +++ b/src/TrueSkill/Factors/GaussianLikelihoodFactor.php @@ -17,7 +17,7 @@ use Exception; */ class GaussianLikelihoodFactor extends GaussianFactor { - private float $precision; + private readonly float $precision; public function __construct(float $betaSquared, Variable $variable1, Variable $variable2) { diff --git a/src/TrueSkill/Factors/GaussianPriorFactor.php b/src/TrueSkill/Factors/GaussianPriorFactor.php index 774d5aa..60b2e4e 100644 --- a/src/TrueSkill/Factors/GaussianPriorFactor.php +++ b/src/TrueSkill/Factors/GaussianPriorFactor.php @@ -15,7 +15,7 @@ use DNW\Skills\Numerics\GaussianDistribution; */ class GaussianPriorFactor extends GaussianFactor { - private GaussianDistribution $newMessage; + private readonly GaussianDistribution $newMessage; public function __construct(float $mean, float $variance, Variable $variable) { diff --git a/src/TrueSkill/Factors/GaussianWithinFactor.php b/src/TrueSkill/Factors/GaussianWithinFactor.php index 73b927c..cf0970f 100644 --- a/src/TrueSkill/Factors/GaussianWithinFactor.php +++ b/src/TrueSkill/Factors/GaussianWithinFactor.php @@ -16,7 +16,7 @@ use DNW\Skills\TrueSkill\TruncatedGaussianCorrectionFunctions; */ class GaussianWithinFactor extends GaussianFactor { - private float $epsilon; + private readonly float $epsilon; public function __construct(float $epsilon, Variable $variable) { diff --git a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php index d0e1b0a..57bfba7 100644 --- a/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php +++ b/src/TrueSkill/Layers/TeamDifferencesComparisonLayer.php @@ -11,7 +11,7 @@ use DNW\Skills\TrueSkill\TrueSkillFactorGraph; class TeamDifferencesComparisonLayer extends TrueSkillFactorGraphLayer { - private float $epsilon; + private readonly float $epsilon; /** * @param int[] $teamRanks diff --git a/src/TrueSkill/TrueSkillFactorGraph.php b/src/TrueSkill/TrueSkillFactorGraph.php index 3750e23..2ddd63f 100644 --- a/src/TrueSkill/TrueSkillFactorGraph.php +++ b/src/TrueSkill/TrueSkillFactorGraph.php @@ -28,7 +28,7 @@ class TrueSkillFactorGraph extends FactorGraph */ private array $layers; - private PlayerPriorValuesToSkillsLayer $priorLayer; + private readonly PlayerPriorValuesToSkillsLayer $priorLayer; /** * @param GameInfo $gameInfo Parameters for the game. diff --git a/tests/Numerics/BasicMathTest.php b/tests/Numerics/BasicMathTest.php index 1750136..8a538cb 100644 --- a/tests/Numerics/BasicMathTest.php +++ b/tests/Numerics/BasicMathTest.php @@ -20,12 +20,8 @@ class BasicMathTest extends TestCase { $arr = [1, 1, 1, 1]; - $func_return = function (float $f): float { - return $f; - }; - $func_double = function (float $f): float { - return $f * 2; - }; + $func_return = fn(float $f): float => $f; + $func_double = fn(float $f): float => $f * 2; $this->assertEquals(4, BasicMath::sum($arr, $func_return)); $this->assertEquals(8, BasicMath::sum($arr, $func_double)); } diff --git a/tests/Numerics/MatrixTest.php b/tests/Numerics/MatrixTest.php index 5b3898e..1e0e684 100644 --- a/tests/Numerics/MatrixTest.php +++ b/tests/Numerics/MatrixTest.php @@ -165,7 +165,7 @@ class MatrixTest extends TestCase $b = new SquareMatrix(4, 3, 2, 1); - + $sum = Matrix::add($a, $b); $result = new SquareMatrix(5, 5, 5, 5);