Completed
Push — master ( a1b70a...dd69ef )
by Ezra
02:32
created

Player::convertToObjects()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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