Player::GetOwnedGames()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.0187

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 10
cts 11
cp 0.9091
rs 9.1928
c 0
b 0
f 0
cc 5
nc 8
nop 3
crap 5.0187
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
        if(count((array)$details) == 0){
39
            return NULL;
40 1
        }
41
42
        $details = new Level($details);
43 2
44
        return $details;
45
    }
46 2
47
    public function GetBadges()
48
    {
49 2
        // Set up the api details
50
        $this->setApiDetails(__FUNCTION__, 'v0001');
51
52 2
        // Set up the arguments
53
        $arguments = ['steamId' => $this->steamId];
54
55 1
        // Get the client
56
        return $this->getServiceResponse($arguments);
57
    }
58 1
59
    public function GetCommunityBadgeProgress($badgeId = null)
60
    {
61 1
        // Set up the api details
62 1
        $this->setApiDetails(__FUNCTION__, 'v0001');
63
64
        // Set up the arguments
65
        $arguments = ['steamId' => $this->steamId];
66
        if ($badgeId != null) {
67 1
            $arguments['badgeid'] = $badgeId;
68
        }
69
70 3
        // Get the client
71
        return $this->getServiceResponse($arguments);
72
    }
73 3
74
    public function GetOwnedGames($includeAppInfo = true, $includePlayedFreeGames = false, $appIdsFilter = [])
75
    {
76 3
        // Set up the api details
77 3
        $this->setApiDetails(__FUNCTION__, 'v0001');
78 2
79
        // Set up the arguments
80 3
        $arguments = ['steamId' => $this->steamId];
81
        if ($includeAppInfo) {
82
            $arguments['include_appinfo'] = $includeAppInfo;
83
        }
84 3
        if ($includePlayedFreeGames) {
85
            $arguments['include_played_free_games'] = $includePlayedFreeGames;
86 3
        }
87 1
88
        $appIdsFilter = (array) $appIdsFilter;
89
90
        if (count($appIdsFilter) > 0) {
91 3
            $arguments['appids_filter'] = $appIdsFilter;
92
        }
93
94 3
        // Get the client
95
        $client = $this->getServiceResponse($arguments);
96
97 2
        // Clean up the games
98
        return $this->convertToObjects(isset($client->games) ? $client->games : []);
99
    }
100 2
101
    public function GetRecentlyPlayedGames($count = null)
102
    {
103 2
        // Set up the api details
104 2
        $this->setApiDetails(__FUNCTION__, 'v0001');
105 1
106
        // Set up the arguments
107
        $arguments = ['steamId' => $this->steamId];
108
        if (! is_null($count)) {
109 2
            $arguments['count'] = $count;
110
        }
111 2
112
        // Get the client
113 2
        $client = $this->getServiceResponse($arguments);
114
115
        if (isset($client->total_count) && $client->total_count > 0) {
116
            // Clean up the games
117
            return $this->convertToObjects($client->games);
118
        }
119 1
120
        return null;
121
    }
122 1
123
    public function IsPlayingSharedGame($appIdPlaying)
124
    {
125
        // Set up the api details
126 1
        $this->setApiDetails(__FUNCTION__, 'v0001');
127 1
128
        // Set up the arguments
129
        $arguments = [
130
            'steamId'       => $this->steamId,
131 1
            'appid_playing' => $appIdPlaying,
132
        ];
133 1
134
        // Get the client
135
        $client = $this->getServiceResponse($arguments);
136 5
137
        return $client->lender_steamid;
138 5
    }
139
140 5
    protected function convertToObjects($games)
141
    {
142 5
        $convertedGames = $this->convertGames($games);
143
144
        $games = $this->sortObjects($convertedGames);
145 5
146
        return $games;
147 5
    }
148
149 5
    private function convertGames($games)
150 5
    {
151
        $convertedGames = new Collection;
152
153 5
        foreach ($games as $game) {
154
            $convertedGames->add(new Game($game));
155
        }
156 1
157
        return $convertedGames;
158
    }
159
}
160