Completed
Push — master ( 32f0b1...030226 )
by Ezra
14s queued 12s
created

Item   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 50
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

4 Methods

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