Completed
Pull Request — master (#37)
by Mahmoud
08:04
created

App::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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