Completed
Push — master ( c7652d...e90b5e )
by
unknown
02:21 queued 10s
created

App::convertGames()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace Syntax\SteamApi\Steam;
4
5
use Syntax\SteamApi\Client;
6
use Illuminate\Support\Collection;
7
use Syntax\SteamApi\Containers\App as AppContainer;
8
9
class App extends Client
10
{
11 1
    public function __construct()
12
    {
13 1
        parent::__construct();
14 1
        $this->url       = 'http://store.steampowered.com/';
15 1
        $this->interface = 'api';
16 1
    }
17
18 1
    public function appDetails($appIds, $country = null, $language = null)
19
    {
20
        // Set up the api details
21 1
        $this->method  = 'appdetails';
22 1
        $this->version = null;
23
24
        // Set up the arguments
25
        $arguments = [
26 1
            'appids' => $appIds,
27 1
            'cc' => $country,
28 1
            'l' => $language,
29
        ];
30
31
        // Get the client
32 1
        $client = $this->setUpClient($arguments);
33 1
        $apps   = $this->convertToObjects($client);
34
35 1
        return $apps;
36
    }
37
38
    public function GetAppList()
39
    {
40
        // Set up the api details
41
        $this->url       = 'http://api.steampowered.com/';
42
        $this->interface = 'ISteamApps';
43
        $this->method    = __FUNCTION__;
44
        $this->version   = 'v0001';
45
46
        // Get the client
47
        $client = $this->setUpClient();
48
49
        return $client->applist->apps->app;
50
    }
51
52 1
    protected function convertToObjects($apps)
53
    {
54 1
        $convertedApps = $this->convertGames($apps);
55
56 1
        $apps = $this->sortObjects($convertedApps);
57
58 1
        return $apps;
59
    }
60
61
    /**
62
     * @param $apps
63
     *
64
     * @return Collection
65
     */
66 1
    protected function convertGames($apps)
67
    {
68 1
        $convertedApps = new Collection();
69
70 1
        foreach ($apps as $app) {
71 1
            if (isset($app->data)) {
72 1
                $convertedApps->add(new AppContainer($app->data));
73
            }
74
        }
75
76 1
        return $convertedApps;
77
    }
78
}
79