From efd46704c7d4c6b7e98c57dd365141b37646f5ca Mon Sep 17 00:00:00 2001 From: yzPeedro Date: Sat, 25 Jun 2022 18:26:08 -0300 Subject: [PATCH] add: code documentation and code refactoring --- composer.json | 3 +- composer.lock | 198 ++++++++++++++++++++++++-- src/Auth/Authentication.php | 6 + src/Stats/Contracts/GameInterface.php | 7 +- src/Stats/Game.php | 16 ++- src/Stats/Player.php | 19 +++ src/Stats/StatsApi.php | 4 +- 7 files changed, 235 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index b1c442a..cdb7313 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "guzzlehttp/guzzle": "^7.0" }, "require-dev": { - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "symfony/var-dumper": "^6.1" }, "license": "MIT" } diff --git a/composer.lock b/composer.lock index a988336..26bb7af 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5fd2072fc31f1cabb5d8c01baeb4869f", + "content-hash": "12ef78312e049d2716584497aef28718", "packages": [ { "name": "guzzlehttp/guzzle", - "version": "7.4.2", + "version": "7.4.4", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4" + "reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ac1ec1cd9b5624694c3a40be801d94137afb12b4", - "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/e3ff079b22820c2029d4c2a87796b6a0b8716ad8", + "reference": "e3ff079b22820c2029d4c2a87796b6a0b8716ad8", "shasum": "" }, "require": { @@ -112,7 +112,7 @@ ], "support": { "issues": "https://github.com/guzzle/guzzle/issues", - "source": "https://github.com/guzzle/guzzle/tree/7.4.2" + "source": "https://github.com/guzzle/guzzle/tree/7.4.4" }, "funding": [ { @@ -128,7 +128,7 @@ "type": "tidelift" } ], - "time": "2022-03-20T14:16:28+00:00" + "time": "2022-06-09T21:39:15+00:00" }, { "name": "guzzlehttp/promises", @@ -1445,16 +1445,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.20", + "version": "9.5.21", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba" + "reference": "0e32b76be457de00e83213528f6bb37e2a38fcb1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba", - "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0e32b76be457de00e83213528f6bb37e2a38fcb1", + "reference": "0e32b76be457de00e83213528f6bb37e2a38fcb1", "shasum": "" }, "require": { @@ -1488,7 +1488,6 @@ "sebastian/version": "^3.0.2" }, "require-dev": { - "ext-pdo": "*", "phpspec/prophecy-phpunit": "^2.0.1" }, "suggest": { @@ -1532,7 +1531,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.21" }, "funding": [ { @@ -1544,7 +1543,7 @@ "type": "github" } ], - "time": "2022-04-01T12:37:26+00:00" + "time": "2022-06-19T12:14:25+00:00" }, { "name": "sebastian/cli-parser", @@ -2592,6 +2591,177 @@ ], "time": "2021-10-20T20:35:02+00:00" }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.26.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e", + "reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-mbstring": "*" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.26-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.26.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-05-24T11:49:31+00:00" + }, + { + "name": "symfony/var-dumper", + "version": "v6.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "98587d939cb783aa04e828e8fa857edaca24c212" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/98587d939cb783aa04e828e8fa857edaca24c212", + "reference": "98587d939cb783aa04e828e8fa857edaca24c212", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.3", + "symfony/console": "<5.4" + }, + "require-dev": { + "ext-iconv": "*", + "symfony/console": "^5.4|^6.0", + "symfony/process": "^5.4|^6.0", + "symfony/uid": "^5.4|^6.0", + "twig/twig": "^2.13|^3.0.4" + }, + "suggest": { + "ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", + "ext-intl": "To show region name in time zone dump", + "symfony/console": "To use the ServerDumpCommand and/or the bin/var-dump-server script" + }, + "bin": [ + "Resources/bin/var-dump-server" + ], + "type": "library", + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides mechanisms for walking through any arbitrary PHP variable", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "support": { + "source": "https://github.com/symfony/var-dumper/tree/v6.1.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-05-21T13:34:40+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.1", diff --git a/src/Auth/Authentication.php b/src/Auth/Authentication.php index e3e41e2..fbb15f4 100644 --- a/src/Auth/Authentication.php +++ b/src/Auth/Authentication.php @@ -14,6 +14,8 @@ class Authentication private string $api_key; /** + * Create an Authentication class instance. + * * @param string $api_key */ public function __construct(string $api_key = '') @@ -22,6 +24,8 @@ public function __construct(string $api_key = '') } /** + * Set yor api key in instance, you can get at R6Stats Discord (https://discord.gg/2Hz8wrKk3z). + * * @param string $api_key */ public function setApiKey(string $api_key): void @@ -30,6 +34,8 @@ public function setApiKey(string $api_key): void } /** + * Get yor api key in instance, if you don't have an api key, you can get at R6Stats Discord (https://discord.gg/2Hz8wrKk3z). + * * @return string */ public function getApiKey(): string diff --git a/src/Stats/Contracts/GameInterface.php b/src/Stats/Contracts/GameInterface.php index 564fe81..e44c43e 100644 --- a/src/Stats/Contracts/GameInterface.php +++ b/src/Stats/Contracts/GameInterface.php @@ -2,7 +2,12 @@ namespace RainbowStats\RainbowStats\Stats\Contracts; +use stdClass; + interface GameInterface { - public function leaderboard(): array|string|\stdClass; + /** + * @return array|string|stdClass + */ + public function leaderboard(): array|string|stdClass; } \ No newline at end of file diff --git a/src/Stats/Game.php b/src/Stats/Game.php index 8a235f0..2efd937 100644 --- a/src/Stats/Game.php +++ b/src/Stats/Game.php @@ -8,15 +8,29 @@ class Game implements GameInterface { + /** + * @var StatsApi + */ private StatsApi $api; + /** + * Create a Game class instance. + * + * @param Authentication $authentication + * @param array $data + */ public function __construct(Authentication $authentication, array $data) { $this->api = new StatsApi($authentication, $data); } + /** + * Get the game leaderboard. Returns an array with a maximum of 100 objects with information for each player. + * + * @return array|string|stdClass + */ public function leaderboard(): array|string|stdClass { - return $this->api->leaderboard('game'); + return $this->api->leaderboard(); } } \ No newline at end of file diff --git a/src/Stats/Player.php b/src/Stats/Player.php index ef34ff7..ca32021 100644 --- a/src/Stats/Player.php +++ b/src/Stats/Player.php @@ -15,6 +15,16 @@ class Player implements PlayerInterface protected StatsApi $player; /** + * To initialize the Player class it is necessary that you have some values. In the class constructor, you need to inform two parameters: Authentication (an instance of the Authentication class) and a data array. + * The data parameter is an array which has three functional keys, example: + * + * + * [ + * 'username' => 'Mumiia661', + * 'platform' => 'pc', + * 'statistic_type' => 'generic' // (not required) + * ] + * * @param Authentication $auth * @param array $data */ @@ -24,6 +34,9 @@ public function __construct(Authentication $auth, array $data) } /** + * This method is responsible for returning all possible information about a given player. This method is extremely useful if you are developing an SPA. + * Is not recommended if you want to use an application with multiple pages or if you want to return a specific value regarding player statistics. + * * @return array|string|stdClass */ public function all(): array|string|stdClass @@ -32,6 +45,8 @@ public function all(): array|string|stdClass } /** + * This method is responsible for returning all player progression (level, lootbox_probability and total_xp) + * * @return array|string|stdClass */ public function progression(): array|string|stdClass @@ -40,6 +55,8 @@ public function progression(): array|string|stdClass } /** + * This method is responsible for returning all information about the user's nick, such as their login username, username that appears in online matches and also information about the last moment the player was online. + * * @return array|string|stdClass */ public function aliases(): array|string|stdClass @@ -48,6 +65,8 @@ public function aliases(): array|string|stdClass } /** + * This method is responsible for returning all relevant player statistics regarding game modes played, queues frequented, ranked played, KD and others. + * * @return array|string|stdClass */ public function stats(): array|string|stdClass diff --git a/src/Stats/StatsApi.php b/src/Stats/StatsApi.php index 33061d5..10248d8 100644 --- a/src/Stats/StatsApi.php +++ b/src/Stats/StatsApi.php @@ -4,7 +4,6 @@ use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; -use PHPUnit\Util\Exception; use RainbowStats\RainbowStats\Auth\Authentication; use stdClass; @@ -76,6 +75,9 @@ public function get(string $parameter = ''): string|array|stdClass } } + /** + * @return string|array|stdClass + */ public function leaderboard(): string|array|stdClass { $gameClient = new Client([