From 98af434b68028c894526e07f8d197b07c402ee7e Mon Sep 17 00:00:00 2001 From: Ezra Sharp Date: Sun, 28 Apr 2024 01:32:08 +1200 Subject: [PATCH] [Laravel 10] Cleanup --- README.md | 39 ++++++----- composer.json | 2 +- .../SteamApi/Command/SteamAppGrabber.php | 66 ------------------- src/Syntax/SteamApi/Steam/Package.php | 16 ++--- .../SteamApi/SteamApiServiceProvider.php | 31 ++------- tests/PackageTest.php | 2 +- 6 files changed, 38 insertions(+), 118 deletions(-) delete mode 100644 src/Syntax/SteamApi/Command/SteamAppGrabber.php diff --git a/README.md b/README.md index 3d557ad..83beb74 100644 --- a/README.md +++ b/README.md @@ -41,10 +41,19 @@ Next, update composer from the terminal. Lastly, publish the config file. You can get your API key from [Steam](http://steamcommunity.com/dev/apikey). - php artisan vendor:publish + php artisan vendor:publish --provider="Syntax\SteamApi\SteamApiServiceProvider" ## Usage +```php +use SteamApi; + +/** Get Portal 2 */ +$apps = SteamApi::app()->appDetails([620]); + +echo $app->first()->name; +``` + Each service from the Steam API has its own methods you can use. - [Global](#global) @@ -75,7 +84,7 @@ format | string | The format you want back. | No | null ##### Example usage ```php -Steam::convertId($id, $format); +SteamApi::convertId($id, $format); ``` > Example Output: [convertId](./examples/global/convertId.txt) @@ -84,7 +93,7 @@ Steam::convertId($id, $format); The [Steam News](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetNewsForApp_.28v0002.29) web api is used to get articles for games. ```php -Steam::news() +SteamApi::news() ``` #### GetNewsForApp @@ -102,7 +111,7 @@ maxlength | int | The maximum number of characters to return | No | null ```php GetNewsForApp($appId, 5, 500)->newsitems; + $news = SteamApi::news()->GetNewsForApp($appId, 5, 500)->newsitems; ?> ``` @@ -114,7 +123,7 @@ The [Player Service](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetO When instantiating the player class, you are required to pass a steamId or Steam community ID. ```php -Steam::player($steamId) +SteamApi::player($steamId) ``` #### GetSteamLevel @@ -178,7 +187,7 @@ The [User](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetFriendList_ When instantiating the user class, you are required to pass at least one steamId or steam community ID. ```php -Steam::user($steamId) +SteamApi::user($steamId) ``` #### ResolveVanityURL @@ -191,7 +200,7 @@ Name | Type | Description | Required | Default displayName| string | The display name to get the steam ID for. In `http://steamcommunity.com/id/gabelogannewell` it would be `gabelogannewell`. | Yes | NULL ```php - $player = Steam::user($steamId)->ResolveVanityURL('gabelogannewell'); + $player = SteamApi::user($steamId)->ResolveVanityURL('gabelogannewell'); ``` > Example Output: [ResolveVanityURL](./examples/user/ResolveVanityURL.txt) @@ -208,11 +217,11 @@ steamId| int[] | An array of (or singular) steam ID(s) to get details for | No ```php // One user $steamId = 76561197960287930; - $player = Steam::user($steamId)->GetPlayerSummaries()[0]; + $player = SteamApi::user($steamId)->GetPlayerSummaries()[0]; // Several users $steamIds = [76561197960287930, 76561197968575517] - $players = Steam::user($steamIds)->GetPlayerSummaries(); + $players = SteamApi::user($steamIds)->GetPlayerSummaries(); ``` > Example Output: [GetPlayerSummaries](./examples/user/GetPlayerSummaries.txt) @@ -250,7 +259,7 @@ The [User Stats](https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlaye When instantiating the user stats class, you are required to pass a steamID or Steam community ID. ```php -Steam::userStats($steamId) +SteamApi::userStats($steamId) ``` #### GetPlayerAchievements @@ -306,7 +315,7 @@ appId| int | The ID of the game you want the details for. | Yes | This area will get details for games. ```php -Steam::app() +SteamApi::app() ``` #### appDetails @@ -332,7 +341,7 @@ This method will return an array of app objects directly from Steam. It include This method will get details for packages. ```php -Steam::package() +SteamApi::package() ``` #### packageDetails @@ -353,7 +362,7 @@ l | string | The l is the language parameter, you can get the appropriate langua This method will get user inventory for item. ```php -Steam::item() +SteamApi::item() ``` #### GetPlayerItems @@ -374,7 +383,7 @@ steamid | int | The steamid of the Steam user you want for | Yes | This service is used to get details on a Steam group. ```php -Steam::group() +SteamApi::group() ``` #### GetGroupSummary @@ -390,7 +399,7 @@ group| string or int | The ID or the name of the group. | Yes ```php GetGroupSummary('Valve'); + $news = SteamApi::group()->GetGroupSummary('Valve'); ?> ``` diff --git a/composer.json b/composer.json index 469f4de..7c24396 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^10.5", + "phpunit/phpunit": "^10.5|^11.0", "orchestra/testbench": "^8.0", "vlucas/phpdotenv": "^5.6", "rector/rector": "^1.0" diff --git a/src/Syntax/SteamApi/Command/SteamAppGrabber.php b/src/Syntax/SteamApi/Command/SteamAppGrabber.php deleted file mode 100644 index e9dc4ef..0000000 --- a/src/Syntax/SteamApi/Command/SteamAppGrabber.php +++ /dev/null @@ -1,66 +0,0 @@ -method = 'packagedetails'; $this->version = null; // Set up the arguments $arguments = [ - 'packageids' => $packIds, + 'packageids' => $packId, 'cc' => $cc, 'l' => $language, ]; // Get the client $client = $this->setUpClient($arguments); - return $this->convertToObjects($client, $packIds); + return $this->convertToObjects($client, $packId); } - protected function convertToObjects($package, $packIds): Collection + protected function convertToObjects($package, $packId): Collection { - $convertedPacks = $this->convertPacks($package, $packIds); + $convertedPacks = $this->convertPacks($package, $packId); return $this->sortObjects($convertedPacks); } /** * @param $packages - * @param $packIds + * @param $packId * @return Collection */ - protected function convertPacks($packages, $packIds): Collection + protected function convertPacks($packages, $packId): Collection { $convertedPacks = new Collection(); foreach ($packages as $package) { if (isset($package->data)) { - $convertedPacks->add(new PackageContainer($package->data, $packIds)); + $convertedPacks->add(new PackageContainer($package->data, $packId)); } } diff --git a/src/Syntax/SteamApi/SteamApiServiceProvider.php b/src/Syntax/SteamApi/SteamApiServiceProvider.php index 6c3f8af..ca0b102 100644 --- a/src/Syntax/SteamApi/SteamApiServiceProvider.php +++ b/src/Syntax/SteamApi/SteamApiServiceProvider.php @@ -2,24 +2,16 @@ namespace Syntax\SteamApi; -use Illuminate\Foundation\AliasLoader; use Illuminate\Support\ServiceProvider; class SteamApiServiceProvider extends ServiceProvider { - /** - * Indicates if loading of the provider is deferred. - * - * @var bool - */ - protected $defer = false; - /** * Bootstrap the application events. * * @return void */ - public function boot() + public function boot(): void { $this->publishes([__DIR__ . '/../../config/config.php' => config_path('steam-api.php')]); } @@ -29,24 +21,9 @@ public function boot() * * @return void */ - public function register() - { - $this->registerAlias(); - - $this->app->singleton('steam-api', fn() => new Client); - } - - /** - * Register the alias for package. - * - * @return void - */ - protected function registerAlias() + public function register(): void { - $this->app->booting(function () { - $loader = AliasLoader::getInstance(); - $loader->alias('Steam', \Syntax\SteamApi\Facades\SteamApi::class); - }); + $this->app->singleton('steam-api', fn () => new Client()); } /** @@ -54,7 +31,7 @@ protected function registerAlias() * * @return string[] */ - public function provides() + public function provides(): array { return ['steam-api']; } diff --git a/tests/PackageTest.php b/tests/PackageTest.php index d1335dc..fd9e30a 100644 --- a/tests/PackageTest.php +++ b/tests/PackageTest.php @@ -21,7 +21,7 @@ public function it_gets_details_for_an_package_by_id() /** * @param $detail */ - private function checkPackageClasses($detail) + private function checkPackageClasses($detail): void { $this->assertInstanceOf(\Syntax\SteamApi\Containers\Package::class, $detail); }