Completed
Push — master ( 99fa2d...6291ae )
by Ezra
02:24
created

Player   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 95.38%

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 4
dl 0
loc 154
ccs 62
cts 65
cp 0.9538
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A GetSteamLevel() 0 13 1
A GetPlayerLevelDetails() 0 8 1
A GetBadges() 0 13 1
A GetCommunityBadgeProgress() 0 16 2
A GetOwnedGames() 0 28 5
A GetRecentlyPlayedGames() 0 23 4
A convertToObjects() 0 8 1
A convertGames() 0 10 2
A IsPlayingSharedGame() 0 16 1
1
<?php
2
3
namespace Syntax\SteamApi\Steam;
4
5
use Syntax\SteamApi\Client;
6
use Illuminate\Support\Collection;
7
use Syntax\SteamApi\Containers\Game;
8
use Syntax\SteamApi\Containers\Player\Level;
9
10
class Player extends Client
11
{
12 10
    public function __construct($steamId)
13
    {
14 10
        parent::__construct();
15 10
        $this->interface = 'IPlayerService';
16 10
        $this->isService = true;
17 10
        $this->steamId   = $steamId;
18 10
    }
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 3
    public function GetOwnedGames($includeAppInfo = true, $includePlayedFreeGames = false, $appIdsFilter = [])
75
    {
76
        // Set up the api details
77 3
        $this->setApiDetails(__FUNCTION__, 'v0001');
78
79
        // Set up the arguments
80 3
        $arguments = ['steamId' => $this->steamId];
81 3
        if ($includeAppInfo) {
82 2
            $arguments['include_appinfo'] = $includeAppInfo;
83
        }
84 3
        if ($includePlayedFreeGames) {
85
            $arguments['include_played_free_games'] = $includePlayedFreeGames;
86
        }
87
88 3
        $appIdsFilter = (array) $appIdsFilter;
89
90 3
        if (count($appIdsFilter) > 0) {
91 1
            $arguments['appids_filter'] = $appIdsFilter;
92
        }
93
94
        // Get the client
95 3
        $client = $this->getServiceResponse($arguments);
96
97
        // Clean up the games
98 3
        $games = $this->convertToObjects(isset($client->games) ? $client->games : []);
99
100 3
        return $games;
101
    }
102
103 2
    public function GetRecentlyPlayedGames($count = null)
104
    {
105
        // Set up the api details
106 2
        $this->setApiDetails(__FUNCTION__, 'v0001');
107
108
        // Set up the arguments
109 2
        $arguments = ['steamId' => $this->steamId];
110 2
        if (! is_null($count)) {
111 1
            $arguments['count'] = $count;
112
        }
113
114
        // Get the client
115 2
        $client = $this->getServiceResponse($arguments);
116
117 2
        if (isset($client->total_count) && $client->total_count > 0) {
118
            // Clean up the games
119 2
            $games = $this->convertToObjects($client->games);
120
121 2
            return $games;
122
        }
123
124
        return null;
125
    }
126
127 1
    public function IsPlayingSharedGame($appIdPlaying)
128
    {
129
        // Set up the api details
130 1
        $this->setApiDetails(__FUNCTION__, 'v0001');
131
132
        // Set up the arguments
133
        $arguments = [
134 1
            'steamId'       => $this->steamId,
135 1
            'appid_playing' => $appIdPlaying,
136
        ];
137
138
        // Get the client
139 1
        $client = $this->getServiceResponse($arguments);
140
141 1
        return $client->lender_steamid;
142
    }
143
144 5
    protected function convertToObjects($games)
145
    {
146 5
        $convertedGames = $this->convertGames($games);
147
148 5
        $games = $this->sortObjects($convertedGames);
149
150 5
        return $games;
151
    }
152
153 5
    private function convertGames($games)
154
    {
155 5
        $convertedGames = new Collection;
156
157 5
        foreach ($games as $game) {
158 5
            $convertedGames->add(new Game($game));
159
        }
160
161 5
        return $convertedGames;
162
    }
163
}
164