Skip to content

Commit 7e09dc7

Browse files
Travis BlasingameTravis Blasingame
authored andcommitted
Minor code clean up for stats
1 parent f61bfcd commit 7e09dc7

File tree

1 file changed

+91
-80
lines changed

1 file changed

+91
-80
lines changed

src/Syntax/SteamApi/Steam/User/Stats.php

Lines changed: 91 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -3,84 +3,95 @@
33
use Syntax\SteamApi\Client;
44
use Syntax\SteamApi\Containers\Achievement;
55

6-
class Stats extends Client {
7-
8-
public function __construct($steamId) {
9-
parent::__construct();
10-
$this->interface = 'ISteamUserStats';
11-
$this->steamId = $steamId;
12-
}
13-
14-
public function GetPlayerAchievements($appId) {
15-
// Set up the api details
16-
$this->method = __FUNCTION__;
17-
$this->version = 'v0001';
18-
19-
// Set up the arguments
20-
$arguments = [
21-
'steamid' => $this->steamId,
22-
'appid' => $appId,
23-
'l' => 'english',
24-
];
25-
26-
// Get the client
27-
$client = $this->setUpClient($arguments)->playerstats;
28-
29-
// Clean up the games
30-
$achievements = $this->convertToObjects($client->achievements);
31-
32-
return $achievements;
33-
}
34-
35-
public function GetGlobalAchievementPercentagesForApp($gameId) {
36-
// Set up the api details
37-
$this->method = __FUNCTION__;
38-
$this->version = 'v0002';
39-
40-
// Set up the arguments
41-
$arguments = [
42-
'gameid' => $gameId,
43-
'l' => 'english',
44-
];
45-
46-
// Get the client
47-
$client = $this->setUpClient($arguments)->achievementpercentages;
48-
49-
return $client->achievements;
50-
}
51-
/*
52-
* @param boolean $all (return stats and not only achievements)
53-
*/
54-
55-
public function GetUserStatsForGame($appId, $all = false) {
56-
// Set up the api details
57-
$this->method = __FUNCTION__;
58-
$this->version = 'v0002';
59-
60-
// Set up the arguments
61-
$arguments = [
62-
'steamid' => $this->steamId,
63-
'appid' => $appId,
64-
'l' => 'english',
65-
];
66-
67-
// Get the client
68-
$client = $this->setUpClient($arguments)->playerstats;
69-
70-
// Do you want also stats and not only achievements? Like CSGO or Dota2 stats
71-
if ($all) {
72-
return $client;
73-
}
74-
return $client->achievements;
75-
}
76-
77-
protected function convertToObjects($achievements) {
78-
$cleanedAchievements = array();
79-
80-
foreach ($achievements as $achievement) {
81-
$cleanedAchievements[] = new Achievement($achievement);
82-
}
83-
84-
return $cleanedAchievements;
85-
}
6+
class Stats extends Client
7+
{
8+
9+
public function __construct($steamId)
10+
{
11+
parent::__construct();
12+
$this->interface = 'ISteamUserStats';
13+
$this->steamId = $steamId;
14+
}
15+
16+
public function GetPlayerAchievements($appId)
17+
{
18+
// Set up the api details
19+
$this->method = __FUNCTION__;
20+
$this->version = 'v0001';
21+
22+
// Set up the arguments
23+
$arguments = [
24+
'steamid' => $this->steamId,
25+
'appid' => $appId,
26+
'l' => 'english',
27+
];
28+
29+
// Get the client
30+
$client = $this->setUpClient($arguments)->playerstats;
31+
32+
// Clean up the games
33+
$achievements = $this->convertToObjects($client->achievements);
34+
35+
return $achievements;
36+
}
37+
38+
public function GetGlobalAchievementPercentagesForApp($gameId)
39+
{
40+
// Set up the api details
41+
$this->method = __FUNCTION__;
42+
$this->version = 'v0002';
43+
44+
// Set up the arguments
45+
$arguments = [
46+
'gameid' => $gameId,
47+
'l' => 'english',
48+
];
49+
50+
// Get the client
51+
$client = $this->setUpClient($arguments)->achievementpercentages;
52+
53+
return $client->achievements;
54+
}
55+
56+
/**
57+
* @param $appId int Steam 64 id
58+
* @param $all bool Return all stats when true and only achievements when false
59+
*
60+
* @return mixed
61+
*/
62+
63+
public function GetUserStatsForGame($appId, $all = false)
64+
{
65+
// Set up the api details
66+
$this->method = __FUNCTION__;
67+
$this->version = 'v0002';
68+
69+
// Set up the arguments
70+
$arguments = [
71+
'steamid' => $this->steamId,
72+
'appid' => $appId,
73+
'l' => 'english',
74+
];
75+
76+
// Get the client
77+
$client = $this->setUpClient($arguments)->playerstats;
78+
79+
// Games like DOTA and CS:GO have additional stats here. Return everything if they are wanted.
80+
if ($all === true) {
81+
return $client;
82+
}
83+
84+
return $client->achievements;
85+
}
86+
87+
protected function convertToObjects($achievements)
88+
{
89+
$cleanedAchievements = [];
90+
91+
foreach ($achievements as $achievement) {
92+
$cleanedAchievements[] = new Achievement($achievement);
93+
}
94+
95+
return $cleanedAchievements;
96+
}
8697
}

0 commit comments

Comments
 (0)