Completed
Push — master ( 6dc6fd...57abcf )
by Travis
13:02
created

Item::convertItems()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
1
<?php
2
3
namespace Syntax\SteamApi\Steam;
4
5
use Syntax\SteamApi\Client;
6
use NukaCode\Database\Collection;
7
use Syntax\SteamApi\Containers\Item as ItemContainer;
8
9
class Item extends Client
10
{
11
    public function __construct()
12
    {
13
        parent::__construct();
14
        $this->url       = 'http://store.steampowered.com/';
15
        $this->isService = true;
16
        $this->interface = 'api';
17
    }
18
19
    public function GetPlayerItems($appId, $steamId)
20
    {
21
        // Set up the api details
22
        $this->url       = 'http://api.steampowered.com/';
23
        $this->interface = 'IEconItems_' . $appId;
24
        $this->method    = __FUNCTION__;
25
        $this->version   = 'v0001';
26
27
        $arguments = ['steamId' => $steamId];
28
29
        // Get the client
30
        $client = $this->setUpClient($arguments);
31
        dd($client);
32
33
        // Clean up the items
34
        $items = $this->convertToObjects($client->result->items, $client->result->qualities);
35
36
        return $items;
37
    }
38
39
    protected function convertToObjects($items, $qualities)
40
    {
41
        $convertedItems = $this->convertGames($items, $qualities);
0 ignored issues
show
Documentation Bug introduced by
The method convertGames does not exist on object<Syntax\SteamApi\Steam\Item>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
42
43
        $items = $this->sortObjects($convertedItems);
44
45
        return $items;
46
    }
47
48
    /**
49
     * @param array $items
50
     *
51
     * @return Collection
52
     */
53
    protected function convertItems($items, $qualities)
54
    {
55
        $convertedItems = new Collection();
56
57
        foreach ($items as $item) {
58
            if (isset($item->data)) {
59
                $convertedItems->add(new ItemContainer($item->data, $qualities));
0 ignored issues
show
Unused Code introduced by
The call to Item::__construct() has too many arguments starting with $qualities.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
            }
61
        }
62
63
        return $convertedItems;
64
    }
65
}
66