More coding standards.

Diagrams in API documentation
This commit is contained in:
2025-05-13 12:46:11 +00:00
parent d729caac1f
commit adc587ac0d
15 changed files with 8707 additions and 44 deletions

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive"> <phive xmlns="https://phar.io/phive">
<phar name="phpmd" version="^2.15.0" installed="2.15.0" location="./tools/phpmd" copy="false"/> <phar name="phpmd" version="^2.15.0" installed="2.15.0" location="./tools/phpmd" copy="false"/>
<phar name="overtrue/phplint" version="^9.6.2" installed="9.6.2" location="./tools/phplint" copy="false"/>
<phar name="phpstan" version="^2.1.12" installed="2.1.14" location="./tools/phpstan" copy="false"/> <phar name="phpstan" version="^2.1.12" installed="2.1.14" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="^7.0.0-beta6" installed="7.0.0-beta7" location="./tools/psalm" copy="false"/> <phar name="psalm" version="^7.0.0-beta6" installed="7.0.0-beta7" location="./tools/psalm" copy="false"/>
<phar name="phpcs" version="^3.12.2" installed="3.13.0" location="./tools/phpcs" copy="false"/> <phar name="phpcs" version="^3.12.2" installed="3.13.0" location="./tools/phpcs" copy="false"/>

View File

@ -6,6 +6,11 @@
<file>tests/</file> <file>tests/</file>
<file>benchmark/</file> <file>benchmark/</file>
<arg name="basepath" value="."/>
<arg name="colors"/>
<arg name="parallel" value="8"/>
<arg name="report" value="emacs"/>
<arg value="p"/>
<rule ref="PSR1"> <rule ref="PSR1">
<exclude name="Generic.Files.LineLength"/> <exclude name="Generic.Files.LineLength"/>
@ -18,23 +23,19 @@
<exclude name="Generic.Files.LowercasedFilename.NotFound"/> <exclude name="Generic.Files.LowercasedFilename.NotFound"/>
<exclude name="Generic.PHP.ClosingPHPTag.NotFound"/> <exclude name="Generic.PHP.ClosingPHPTag.NotFound"/>
<exclude name="Generic.Files.EndFileNoNewline.Found"/> <exclude name="Generic.Files.EndFileNoNewline.Found"/>
<exclude name="Generic.Files.EndFileNoNewline.Found"/>
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found"/> <exclude name="Generic.Arrays.DisallowShortArraySyntax.Found"/>
<exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine"/> <exclude name="Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine"/>
<exclude name="Generic.Classes.OpeningBraceSameLine.BraceOnNewLine"/> <exclude name="Generic.Classes.OpeningBraceSameLine.BraceOnNewLine"/>
<exclude name="Generic.PHP.LowerCaseConstant.Found"/> <exclude name="Generic.PHP.LowerCaseConstant.Found"/>
<exclude name="Generic.Formatting.SpaceAfterCast"/>
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning"/> <exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning"/>
<exclude name="Generic.Commenting.DocComment.MissingShort"/> <exclude name="Generic.Commenting.DocComment.MissingShort"/>
<exclude name="Generic.NamingConventions.AbstractClassNamePrefix.Missing"/> <exclude name="Generic.NamingConventions.AbstractClassNamePrefix.Missing"/>
<exclude name="Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed"/> <exclude name="Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed"/>
<exclude name="Generic.NamingConventions.InterfaceNameSuffix.Missing"/> <exclude name="Generic.NamingConventions.InterfaceNameSuffix.Missing"/>
<exclude name="Generic.Commenting.Todo.TaskFound"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUse"/> <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUse"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed"/> <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed"/> <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed"/>
<exclude name="Generic.Formatting.SpaceBeforeCast.NoSpace"/>
<exclude name="Generic.CodeAnalysis.UselessOverridingMethod.Found"/>
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.NewlineBeforeOpenBrace"/> <exclude name="Squiz.Functions.MultiLineFunctionDeclaration.NewlineBeforeOpenBrace"/>
</rule> </rule>
@ -50,4 +51,25 @@
</property> </property>
</properties> </properties>
</rule> </rule>
<rule ref="Generic.Formatting.SpaceAfterCast">
<properties>
<property name="spacing" value="0"/>
</properties>
</rule>
<!-- Do not allow unreachable code. -->
<rule ref="Squiz.PHP.NonExecutableCode"/>
<!-- Do not allow ambiguous conditions. -->
<rule ref="Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence"/>
<!-- The testing bootstrap file uses string concats to stop IDEs seeing the class aliases -->
<rule ref="Generic.Strings.UnnecessaryStringConcat" />
<!-- This test file specifically *needs* Windows line endings for testing purposes. -->
<rule ref="Generic.Files.LineEndings.InvalidEOLChar" />
<!-- Avoid false positive with this sniff detecting itself -->
<rule ref="Generic.Commenting.Todo"/>
</ruleset> </ruleset>

View File

@ -1,12 +0,0 @@
path:
- src/
- tests/
- benchmark/
jobs: 10
extensions:
- php
exclude:
- vendor
warning: true
memory-limit: -1
log-junit: "output/lint.xml"

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"php.version": "8.4"
}

4317
CodeStandard.md Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,13 @@
{ {
"name": "dnw/php-trueskill", "name": "dnw/php-trueskill",
"description": "Trueskill implementation by Moserware updated for PHP 8.4", "description": "Trueskill implementation by Moserware updated for PHP 8.4",
"keywords": ["trueskill", "matchmaking", "ranking", "skill", "elo"], "keywords": [
"trueskill",
"matchmaking",
"ranking",
"skill",
"elo"
],
"require": { "require": {
"php": "^8.4" "php": "^8.4"
}, },
@ -22,34 +28,38 @@
} }
}, },
"scripts": { "scripts": {
"test": "phpunit", "test": "phpunit",
"document": "tools/phpDocumentor", "document": [
"benchmark": "tools/phpbench run --report=default --output=build-artifact", "tools/phpcs --generator=MarkDown > docs/CodeStandard.md",
"metrics": "vendor/bin/phpmetrics --config=phpmetrics.yml", "tools/phpdocumentor"
],
"benchmark": "tools/phpbench run --report=default --output=build-artifact",
"metrics": "vendor/bin/phpmetrics --config=phpmetrics.yml",
"lint": [ "lint": [
"tools/phplint", "tools/phpcs",
"tools/phpcs", "tools/phpcbf src/ tests/ benchmark/ examples/",
"tools/phpcbf src/ tests/ benchmark/ examples/", "tools/phpmd src/,tests/,benchmark/,examples/ text phpmd.ruleset.xml"
"tools/phpmd src/,tests/,benchmark/,examples/ text phpmd.ruleset.xml"
], ],
"analyze": [ "analyze": [
"@analyze-phpstan", "@analyze-phpstan",
"@analyze-psalm", "@analyze-psalm",
"@analyze-rector" "@analyze-rector"
], ],
"analyze-phpstan":"tools/phpstan analyze --error-format=raw", "analyze-phpstan": "tools/phpstan analyze --error-format=raw",
"analyze-psalm": "tools/psalm --no-cache --show-info=true", "analyze-psalm": "tools/psalm --no-cache --show-info=true",
"analyze-rector": "vendor/bin/rector --dry-run", "analyze-rector": "vendor/bin/rector --dry-run",
"html": [ "html": [
"pandoc -s README.md -o output/README.html", "pandoc -s README.md -o output/README.html",
"pandoc -s docs/index.rst -o output/index.html" "pandoc -s docs/index.rst -o output/index.html",
"pandoc -s docs/CodeStandard.md -o output/CodeStandard.html --metadata title=\"Code Standard\""
], ],
"all": [ "all": [
"@test", "@test",
"@lint", "@lint",
"@analyze", "@analyze",
"@document",
"@metrics", "@metrics",
"@html" "@html"
] ]
} }
} }

4317
docs/CodeStandard.md Normal file

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,7 @@ Links
* `Test report <test/index.html>`_ * `Test report <test/index.html>`_
* `Mutation testing <mutation/infection.html>`_ * `Mutation testing <mutation/infection.html>`_
* `Code metrics <metrics/index.html>`_ * `Code metrics <metrics/index.html>`_
* `Code Standard <CodeStandard.html>`_
Standard Tools Standard Tools

View File

@ -16,5 +16,5 @@
</source> </source>
</api> </api>
</version> </version>
<!--setting name="graphs.enabled" value="true"/--> <setting name="graphs.enabled" value="true"/>
</phpdocumentor> </phpdocumentor>

View File

@ -24,7 +24,7 @@ abstract class FactorGraphLayer
*/ */
private array $inputVariablesGroups = []; private array $inputVariablesGroups = [];
protected function __construct(private readonly TrueSkillFactorGraph $parentFactorGraph) public function __construct(private readonly TrueSkillFactorGraph $parentFactorGraph)
{ {
} }

View File

@ -27,7 +27,7 @@ final class BasicMath
/** /**
* Sums the items in $itemsToSum * Sums the items in $itemsToSum
* *
* @param mixed[] $itemsToSum The items to sum, * @param mixed[] $itemsToSum The items to sum.
* @param \Closure $callback The function to apply to each array element before summing. * @param \Closure $callback The function to apply to each array element before summing.
* *
* @return float The sum. * @return float The sum.

View File

@ -34,8 +34,9 @@ final class GaussianDistribution
*/ */
private const float M_LOG_SQRT_2_PI = 0.9189385332046727417803297364056176398613974736377834128171515404; private const float M_LOG_SQRT_2_PI = 0.9189385332046727417803297364056176398613974736377834128171515404;
// precision and precisionMean are used because they make multiplying and dividing simpler /**
// (see the accompanying math paper for more details) * Precision and precisionMean are used because they make multiplying and dividing simpler.
*/
private float $precision = 1.0; private float $precision = 1.0;
private float $precisionMean = 0.0; private float $precisionMean = 0.0;

View File

@ -13,14 +13,20 @@ final readonly class Player implements ISupportPartialPlay, ISupportPartialUpdat
private const float DEFAULT_PARTIAL_UPDATE_PERCENTAGE = 1.0; private const float DEFAULT_PARTIAL_UPDATE_PERCENTAGE = 1.0;
/**
* @var float The weight percentage to give this player when calculating a new rank.
*/
private float $PartialPlayPct; private float $PartialPlayPct;
/**
* @var float Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update.
*/
private float $PartialUpdatePct; private float $PartialUpdatePct;
/** /**
* Constructs a player. * Constructs a player.
* *
* @param string|int $Id The identifier for the player, such as a name. * @param string|int $Id The identifier for the player, such as a name.
* @param float $partialPlayPct The weight percentage to give this player when calculating a new rank. * @param float $partialPlayPct The weight percentage to give this player when calculating a new rank.
* @param float $partialUpdatePct Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update. * @param float $partialUpdatePct Indicated how much of a skill update a player should receive where 0 represents no update and 1.0 represents 100% of the update.
*/ */

View File

@ -6,6 +6,9 @@ namespace DNW\Skills;
class RatingContainer class RatingContainer
{ {
/**
* Link Player to a Rating using a hash map.
*/
private readonly HashMap $playerToRating; private readonly HashMap $playerToRating;
public function __construct() public function __construct()

View File

@ -9,8 +9,4 @@ use DNW\Skills\TrueSkill\TrueSkillFactorGraph;
abstract class TrueSkillFactorGraphLayer extends FactorGraphLayer abstract class TrueSkillFactorGraphLayer extends FactorGraphLayer
{ {
public function __construct(TrueSkillFactorGraph $parentGraph)
{
parent::__construct($parentGraph);
}
} }