Completed
Push — master ( 030226...1ab247 )
by Ezra
02:41
created

Item::convertToObjects()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
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\Item as ItemContainer;
8
use Syntax\SteamApi\Exceptions\ApiCallFailedException;
9
use Syntax\SteamApi\Inventory;
10
11
class Item extends Client
12
{
13 1
    public function __construct()
14
    {
15 1
        parent::__construct();
16 1
        $this->url       = 'http://store.steampowered.com/';
17 1
        $this->isService = true;
18 1
        $this->interface = 'api';
19 1
    }
20
21 1
    public function GetPlayerItems($appId, $steamId)
22
    {
23
        // Set up the api details
24 1
        $this->url       = 'http://api.steampowered.com/';
25 1
        $this->interface = 'IEconItems_' . $appId;
26 1
        $this->method    = __FUNCTION__;
27 1
        $this->version   = 'v0001';
28
29 1
        $arguments = ['steamId' => $steamId];
30
31 1
        $client = $this->setUpClient($arguments);
32
33
        // Clean up the items
34 1
        $items = $this->convertToObjects($client->result->items);
35
36
        // Return a full inventory
37 1
        return new Inventory($client->result->num_backpack_slots, $items);
38
    }
39
40 1
    protected function convertToObjects($items)
41
    {
42 1
        return $this->convertItems($items);
43
    }
44
45
    /**
46
     * @param array $items
47
     *
48
     * @return Collection
49
     */
50 1
    protected function convertItems($items)
51
    {
52 1
        $convertedItems = new Collection();
53
54 1
        foreach ($items as $item) {
55 1
            $convertedItems->add(new ItemContainer($item));
56
        }
57
58 1
        return $convertedItems;
59
    }
60
}
61