Completed
Push — master ( 82f5dc...c7652d )
by
unknown
03:22 queued 01:51
created

App::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\App as AppContainer;
8
9
class App extends Client
10
{
11 2
    public function __construct()
12
    {
13 2
        parent::__construct();
14 2
        $this->url       = 'http://store.steampowered.com/';
15 2
        $this->interface = 'api';
16 2
    }
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 1
    public function GetAppList()
39
    {
40
        // Set up the api details
41 1
        $this->url       = 'http://api.steampowered.com/';
42 1
        $this->interface = 'ISteamApps';
43 1
        $this->method    = __FUNCTION__;
44 1
        $this->version   = 'v0001';
45
46
        // Get the client
47 1
        $client = $this->setUpClient();
48
49 1
        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