Completed
Push — master ( 61323d...82f5dc )
by
unknown
17s queued 10s
created

Player::GetCommunityBadgeProgress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 6
cts 7
cp 0.8571
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0116
1
<?php
2
3
namespace Syntax\SteamApi\Steam;
4
5
use Syntax\SteamApi\Client;
6
use NukaCode\Database\Collection;
7
use Syntax\SteamApi\Containers\Game;
8
use Syntax\SteamApi\Containers\Player\Level;
9
10
class Player extends Client
11
{
12 9
    public function __construct($steamId)
13
    {
14 9
        parent::__construct();
15 9
        $this->interface = 'IPlayerService';
16 9
        $this->isService = true;
17 9
        $this->steamId   = $steamId;
18 9
    }
19
20 1
    public function GetSteamLevel()
21
    {
22
        // Set up the api details
23 1
        $this->setApiDetails(__FUNCTION__, 'v0001');
24
25
        // Set up the arguments
26 1
        $arguments = ['steamId' => $this->steamId];
27
28
        // Get the client
29 1
        $client = $this->getServiceResponse($arguments);
30
31 1
        return $client->player_level;
32
    }
33
34 1
    public function GetPlayerLevelDetails()
35
    {
36 1
        $details = $this->GetBadges();
37
38 1
        $details = new Level($details);
39
40 1
        return $details;
41
    }
42
43 2
    public function GetBadges()
44
    {
45
        // Set up the api details
46 2
        $this->setApiDetails(__FUNCTION__, 'v0001');
47
48
        // Set up the arguments
49 2
        $arguments = ['steamId' => $this->steamId];
50
51
        // Get the client
52 2
        $client = $this->getServiceResponse($arguments);
53
54 2
        return $client;
55
    }
56
57 1
    public function GetCommunityBadgeProgress($badgeId = null)
58
    {
59
        // Set up the api details
60 1
        $this->setApiDetails(__FUNCTION__, 'v0001');
61
62
        // Set up the arguments
63 1
        $arguments = ['steamId' => $this->steamId];
64 1
        if ($badgeId != null) {
65
            $arguments['badgeid'] = $badgeId;
66
        }
67
68
        // Get the client
69 1
        $client = $this->getServiceResponse($arguments);
70
71 1
        return $client;
72
    }
73
74 2
    public function GetOwnedGames($includeAppInfo = true, $includePlayedFreeGames = false, $appIdsFilter = [])
75
    {
76
        // Set up the api details
77 2
        $this->setApiDetails(__FUNCTION__, 'v0001');
78
79
        // Set up the arguments
80 2
        $arguments = ['steamId' => $this->steamId];
81 2
        if ($includeAppInfo) {
82 1
            $arguments['include_appinfo'] = $includeAppInfo;
83
        }
84 2
        if ($includePlayedFreeGames) {
85
            $arguments['include_played_free_games'] = $includePlayedFreeGames;
86
        }
87 2
        if (count($appIdsFilter) > 0) {
88
            $arguments['appids_filter'] = (array)$appIdsFilter;
89
        }
90
91
        // Get the client
92 2
        $client = $this->getServiceResponse($arguments);
93
94
        // Clean up the games
95 2
        $games = $this->convertToObjects(isset($client->games) ? $client->games : []);
96
97 2
        return $games;
98
    }
99
100 2
    public function GetRecentlyPlayedGames($count = null)
101
    {
102
        // Set up the api details
103 2
        $this->setApiDetails(__FUNCTION__, 'v0001');
104
105
        // Set up the arguments
106 2
        $arguments = ['steamId' => $this->steamId];
107 2
        if (! is_null($count)) {
108 1
            $arguments['count'] = $count;
109
        }
110
111
        // Get the client
112 2
        $client = $this->getServiceResponse($arguments);
113
114 2
        if (isset($client->total_count) && $client->total_count > 0) {
115
            // Clean up the games
116 2
            $games = $this->convertToObjects($client->games);
117
118 2
            return $games;
119
        }
120
121
        return null;
122
    }
123
124 1
    public function IsPlayingSharedGame($appIdPlaying)
125
    {
126
        // Set up the api details
127 1
        $this->setApiDetails(__FUNCTION__, 'v0001');
128
129
        // Set up the arguments
130
        $arguments = [
131 1
            'steamId'       => $this->steamId,
132 1
            'appid_playing' => $appIdPlaying,
133
        ];
134
135
        // Get the client
136 1
        $client = $this->getServiceResponse($arguments);
137
138 1
        return $client->lender_steamid;
139
    }
140
141 4
    protected function convertToObjects($games)
142
    {
143 4
        $convertedGames = $this->convertGames($games);
144
145 4
        $games = $this->sortObjects($convertedGames);
146
147 4
        return $games;
148
    }
149
150 4
    private function convertGames($games)
151
    {
152 4
        $convertedGames = new Collection;
153
154 4
        foreach ($games as $game) {
155 4
            $convertedGames->add(new Game($game));
156
        }
157
158 4
        return $convertedGames;
159
    }
160
}
161