Completed
Pull Request — master (#74)
by Ernest
01:33
created

Package::convertPacks()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
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\Package as PackageContainer;
8
9
class Package extends Client
10
{
11
    public function __construct()
12
    {
13
        parent::__construct();
14
        $this->url = 'http://store.steampowered.com/';
15
        $this->interface = 'api';
16
    }
17
18
    public function packageDetails($packIds, $cc = null, $language = null)
19
    {
20
        // Set up the api details
21
        $this->method = 'packagedetails';
22
        $this->version = null;
23
        // Set up the arguments
24
        $arguments = [
25
            'packageids' => $packIds,
26
            'cc'         => $cc,
27
            'l'          => $language,
28
        ];
29
        // Get the client
30
        $client = $this->setUpClient($arguments);
31
        $packs = $this->convertToObjects($client, $packIds);
32
33
        return $packs;
34
    }
35
36
    protected function convertToObjects($package, $packIds)
37
    {
38
        $convertedPacks = $this->convertPacks($package, $packIds);
39
        $package = $this->sortObjects($convertedPacks);
0 ignored issues
show
Documentation introduced by
$convertedPacks is of type object<NukaCode\Database\Collection>, but the function expects a object<Syntax\SteamApi\Collection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
41
        return $package;
42
    }
43
44
    /**
45
     * @param $packs
46
     *
47
     * @return Collection
48
     */
49
    protected function convertPacks($packages, $packIds)
50
    {
51
        $convertedPacks = new Collection();
52
        foreach ($packages as $package) {
53
            if (isset($package->data)) {
54
                $convertedPacks->add(new PackageContainer($package->data, $packIds));
55
            }
56
        }
57
58
        return $convertedPacks;
59
    }
60
}
61