Completed
Push — master ( 57abcf...bb1066 )
by Travis
12:58 queued 09:31
created

Player::GetRecentlyPlayedGames()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0067

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
ccs 10
cts 11
cp 0.9091
rs 9.0856
cc 3
eloc 10
nc 4
nop 1
crap 3.0067
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 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 2
        }
84 3
        if ($includePlayedFreeGames) {
85
            $arguments['include_played_free_games'] = $includePlayedFreeGames;
86
        }
87 3
        if (count($appIdsFilter) > 0) {
88 1
            $arguments['appids_filter'] = (array)$appIdsFilter;
89 1
        }
90
91
        // Get the client
92 3
        $client = $this->getServiceResponse($arguments);
93
94
        // Clean up the games
95 3
        $games = $this->convertToObjects(isset($client->games) ? $client->games : []);
96
97 3
        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 1
        }
110
111
        // Get the client
112 2
        $client = $this->getServiceResponse($arguments);
113
114 2
        if ($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 1
        ];
134
135
        // Get the client
136 1
        $client = $this->getServiceResponse($arguments);
137
138 1
        return $client->lender_steamid;
139
    }
140
141 5
    protected function convertToObjects($games)
142
    {
143 5
        $convertedGames = $this->convertGames($games);
144
145 5
        $games = $this->sortObjects($convertedGames);
0 ignored issues
show
Documentation introduced by
$convertedGames is of type object<NukaCode\Database\Collection>, but the function expects a object<Syntax\SteamApi\Collection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
146
147 5
        return $games;
148
    }
149
150 5
    private function convertGames($games)
151
    {
152 5
        $convertedGames = new Collection;
153
154 5
        foreach ($games as $game) {
155 5
            $convertedGames->add(new Game($game));
156 5
        }
157
158 5
        return $convertedGames;
159
    }
160
}
161