Skip to content

Commit 8feed62

Browse files
committed
Merge branch 'best-practice-updates'
# Conflicts: # composer.json
2 parents 6291aef + e6bee1b commit 8feed62

File tree

18 files changed

+122
-100
lines changed

18 files changed

+122
-100
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/.idea
12
/vendor
23
composer.phar
34
.DS_Store
45
ocular.phar
56
uploadTests.sh
67
.env
7-
.phpunit.*
8+
.phpunit.*

composer.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "syntax/steam-api",
33
"description": "A steam-api client for Laravel 5.8+",
4-
"version": "2.1.1",
4+
"version": "2.1.2",
55
"license": "MIT",
66
"authors": [
77
{
@@ -12,7 +12,12 @@
1212
"require": {
1313
"php": "^7.2.0",
1414
"laravel/framework": ">=5.8.0",
15-
"guzzlehttp/guzzle": "^6.0"
15+
"guzzlehttp/guzzle": "^6.0",
16+
"ext-bcmath": "*",
17+
"ext-simplexml": "*",
18+
"ext-libxml": "*",
19+
"ext-curl": "*",
20+
"ext-json": "*"
1621
},
1722
"require-dev": {
1823
"phpunit/phpunit": "^8.0",
@@ -24,12 +29,12 @@
2429
"Syntax\\SteamApi\\": "src/Syntax/SteamApi"
2530
}
2631
},
27-
"extra": {
28-
"laravel": {
29-
"providers": [
30-
"Syntax\\SteamApi\\SteamApiServiceProvider"
31-
]
32-
}
33-
},
32+
"extra": {
33+
"laravel": {
34+
"providers": [
35+
"Syntax\\SteamApi\\SteamApiServiceProvider"
36+
]
37+
}
38+
},
3439
"minimum-stability": "stable"
3540
}

src/Syntax/SteamApi/Client.php

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,36 @@
22

33
namespace Syntax\SteamApi;
44

5+
use GuzzleHttp\Exception\GuzzleException;
6+
use Illuminate\Support\Collection;
7+
use Illuminate\Support\Facades\Config;
58
use stdClass;
69
use GuzzleHttp\Client as GuzzleClient;
710
use GuzzleHttp\Psr7\Request;
811
use Exception;
9-
use GuzzleHttp\Exception\ClientErrorResponseException;
10-
use GuzzleHttp\Exception\ServerErrorResponseException;
12+
use GuzzleHttp\Exception\ClientException;
13+
use GuzzleHttp\Exception\ServerException;
14+
use Syntax\SteamApi\Exceptions\ApiArgumentRequired;
1115
use Syntax\SteamApi\Exceptions\ApiCallFailedException;
1216
use Syntax\SteamApi\Exceptions\ClassNotFoundException;
17+
use Syntax\SteamApi\Steam\App;
18+
use Syntax\SteamApi\Steam\Group;
19+
use Syntax\SteamApi\Steam\Item;
20+
use Syntax\SteamApi\Steam\News;
21+
use Syntax\Steamapi\Steam\Package;
22+
use Syntax\SteamApi\Steam\Player;
23+
use Syntax\SteamApi\Steam\User;
24+
use Syntax\SteamApi\Steam\User\Stats;
1325

1426
/**
15-
* @method \Syntax\SteamApi\Steam\News news()
16-
* @method \Syntax\SteamApi\Steam\Player player($steamId)
17-
* @method \Syntax\SteamApi\Steam\User user($steamId)
18-
* @method \Syntax\SteamApi\Steam\User\Stats userStats($steamId)
19-
* @method \Syntax\SteamApi\Steam\App app()
20-
* @method \Syntax\Steamapi\Steam\Package package()
21-
* @method \Syntax\SteamApi\Steam\Group group()
22-
* @method \Syntax\SteamApi\Steam\Item item($appId)
27+
* @method News news()
28+
* @method Player player($steamId)
29+
* @method User user($steamId)
30+
* @method Stats userStats($steamId)
31+
* @method App app()
32+
* @method Package package()
33+
* @method Group group()
34+
* @method Item item($appId)
2335
*/
2436
class Client
2537
{
@@ -73,6 +85,7 @@ public function getSteamId()
7385
*
7486
* @throws ApiArgumentRequired
7587
* @throws ApiCallFailedException
88+
* @throws GuzzleException
7689
*/
7790
protected function setUpService($arguments = null)
7891
{
@@ -140,7 +153,6 @@ protected function setUpXml(array $arguments = [])
140153
$parameters = http_build_query($arguments);
141154

142155
// Pass the results back
143-
return simplexml_load_file($steamUrl . '?' . $parameters);
144156
libxml_use_internal_errors(true);
145157
$result = simplexml_load_file($steamUrl . '?' . $parameters);
146158

@@ -165,10 +177,11 @@ public function getRedirectUrl()
165177
}
166178

167179
/**
168-
* @param \GuzzleHttp\Psr7\Request $request
180+
* @param Request $request
169181
*
170-
* @return \stdClass
171-
* @throws \Syntax\SteamApi\Exceptions\ApiCallFailedException
182+
* @return stdClass
183+
* @throws ApiCallFailedException
184+
* @throws GuzzleException
172185
*/
173186
protected function sendRequest(Request $request)
174187
{
@@ -179,9 +192,9 @@ protected function sendRequest(Request $request)
179192
$result = new stdClass();
180193
$result->code = $response->getStatusCode();
181194
$result->body = json_decode($response->getBody(true));
182-
} catch (ClientErrorResponseException $e) {
195+
} catch (ClientException $e) {
183196
throw new ApiCallFailedException($e->getMessage(), $e->getResponse()->getStatusCode(), $e);
184-
} catch (ServerErrorResponseException $e) {
197+
} catch (ServerException $e) {
185198
throw new ApiCallFailedException('Api call failed to complete due to a server error.', $e->getResponse()->getStatusCode(), $e);
186199
} catch (Exception $e) {
187200
throw new ApiCallFailedException($e->getMessage(), $e->getCode(), $e);
@@ -236,7 +249,7 @@ public function __call($name, $arguments)
236249
/**
237250
* @param Collection $objects
238251
*
239-
* @return $this
252+
* @return Collection
240253
*/
241254
protected function sortObjects($objects)
242255
{
@@ -260,9 +273,7 @@ protected function getServiceResponse($arguments)
260273
$arguments = json_encode($arguments);
261274

262275
// Get the client
263-
$client = $this->setUpService($arguments)->response;
264-
265-
return $client;
276+
return $this->setUpService($arguments)->response;
266277
}
267278

268279
/**
@@ -271,7 +282,7 @@ protected function getServiceResponse($arguments)
271282
*/
272283
protected function getApiKey()
273284
{
274-
$apiKey = \Config::get('steam-api.steamApiKey');
285+
$apiKey = Config::get('steam-api.steamApiKey');
275286

276287
if ($apiKey == 'YOUR-API-KEY') {
277288
throw new Exceptions\InvalidApiKeyException();

src/Syntax/SteamApi/Containers/App.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Syntax\SteamApi\Containers;
44

55
use Illuminate\Support\Collection;
6+
use stdClass;
67

78
class App extends BaseContainer
89
{
@@ -95,37 +96,37 @@ public function __construct($app)
9596

9697
protected function getFakeMetacriticObject()
9798
{
98-
$object = new \stdClass();
99+
$object = new stdClass();
99100
$object->url = null;
100101
$object->score = 'No Score';
101102
return $object;
102103
}
103104

104105
protected function getFakePriceObject()
105106
{
106-
$object = new \stdClass();
107+
$object = new stdClass();
107108
$object->final = 'No price found';
108109
return $object;
109110
}
110111

111112
protected function getFakeFullgameObject()
112113
{
113-
$object = new \stdClass();
114+
$object = new stdClass();
114115
$object->appid = null;
115116
$object->name = 'No parent game found';
116117
return $object;
117118
}
118119

119120
protected function getFakeRecommendationsObject()
120121
{
121-
$object = new \stdClass();
122+
$object = new stdClass();
122123
$object->total = 0;
123124
return $object;
124125
}
125126

126127
protected function getFakeAchievementsObject()
127128
{
128-
$object = new \stdClass();
129+
$object = new stdClass();
129130
$object->total = 0;
130131
return $object;
131132
}

src/Syntax/SteamApi/Containers/Group.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Syntax\SteamApi\Containers;
44

5+
use SimpleXMLElement;
56
use Syntax\SteamApi\Client;
67
use Illuminate\Support\Collection;
78
use Syntax\SteamApi\Containers\Group\Details;
@@ -20,7 +21,7 @@ class Group
2021
public $members;
2122

2223
/**
23-
* @param \SimpleXMLElement $group
24+
* @param SimpleXMLElement $group
2425
*/
2526
function __construct($group)
2627
{

src/Syntax/SteamApi/Containers/Package.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Package extends BaseContainer
1414
public $price;
1515
public $platforms;
1616
public $release;
17+
private $controller;
1718

1819
public function __construct($package, $id)
1920
{

src/Syntax/SteamApi/Containers/Player.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,30 @@ protected function convertPersonaState($personaState)
120120
{
121121
switch ($personaState) {
122122
case 0:
123-
return '<span class="text-error">Offline</span>';
123+
$state = '<span class="text-error">Offline</span>';
124+
break;
124125
case 1:
125-
return '<span class="text-success">Online</span>';
126+
$state = '<span class="text-success">Online</span>';
127+
break;
126128
case 2:
127-
return '<span class="text-warning">Busy</span>';
129+
$state = '<span class="text-warning">Busy</span>';
130+
break;
128131
case 3:
129-
return '<span class="text-warning">Away</span>';
132+
$state = '<span class="text-warning">Away</span>';
133+
break;
130134
case 4:
131-
return '<span class="text-warning">Snooze</span>';
135+
$state = '<span class="text-warning">Snooze</span>';
136+
break;
132137
case 5:
133-
return 'Looking to Trade';
138+
$state = 'Looking to Trade';
139+
break;
134140
case 6:
135-
return 'Looking to Play';
141+
$state = 'Looking to Play';
142+
break;
143+
default:
144+
$state = 'Unknown';
136145
}
146+
147+
return $state;
137148
}
138149
}

src/Syntax/SteamApi/Exceptions/ApiCallFailedException.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
class ApiCallFailedException extends \Exception
66
{
77
/**
8-
* @param string $message
8+
* @param string $message
9+
* @param $code
910
* @param \Exception $previous
1011
*/
1112
public function __construct($message, $code, $previous = null)

src/Syntax/SteamApi/Exceptions/UnrecognizedId.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class UnrecognizedId extends \Exception
66
{
77
/**
88
* @param string $message
9+
* @param int $code
10+
* @param null $previous
911
*/
1012
public function __construct($message, $code = 0, $previous = null)
1113
{

src/Syntax/SteamApi/Steam/App.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,23 @@
88

99
class App extends Client
1010
{
11+
/**
12+
* @var bool
13+
*/
14+
1115
public function __construct()
1216
{
1317
parent::__construct();
1418
$this->url = 'http://store.steampowered.com/';
1519
$this->interface = 'api';
1620
}
1721

22+
/**
23+
* @param $appIds
24+
* @param null $country
25+
* @param null $language
26+
* @return Collection
27+
*/
1828
public function appDetails($appIds, $country = null, $language = null)
1929
{
2030
// Set up the api details
@@ -30,9 +40,8 @@ public function appDetails($appIds, $country = null, $language = null)
3040

3141
// Get the client
3242
$client = $this->setUpClient($arguments);
33-
$apps = $this->convertToObjects($client);
3443

35-
return $apps;
44+
return $this->convertToObjects($client);
3645
}
3746

3847
public function GetAppList()

0 commit comments

Comments
 (0)