Package::convertToObjects()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\Package as PackageContainer;
8
9
class Package extends Client
10
{
11 1
    public function __construct()
12
    {
13 1
        parent::__construct();
14 1
        $this->url = 'http://store.steampowered.com/';
15 1
        $this->interface = 'api';
16 1
    }
17
18 1 View Code Duplication
    public function packageDetails($packIds, $cc = null, $language = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        // Set up the api details
21 1
        $this->method = 'packagedetails';
22 1
        $this->version = null;
23
        // Set up the arguments
24
        $arguments = [
25 1
            'packageids' => $packIds,
26 1
            'cc'         => $cc,
27 1
            'l'          => $language,
28
        ];
29
        // Get the client
30 1
        $client = $this->setUpClient($arguments);
31
32 1
        return $this->convertToObjects($client, $packIds);
33
    }
34
35 1
    protected function convertToObjects($package, $packIds)
36
    {
37 1
        $convertedPacks = $this->convertPacks($package, $packIds);
38 1
        $package = $this->sortObjects($convertedPacks);
39
40 1
        return $package;
41
    }
42
43
    /**
44
     * @param $packages
45
     * @param $packIds
46
     * @return Collection
47
     */
48 1
    protected function convertPacks($packages, $packIds)
49
    {
50 1
        $convertedPacks = new Collection();
51 1
        foreach ($packages as $package) {
52 1
            if (isset($package->data)) {
53 1
                $convertedPacks->add(new PackageContainer($package->data, $packIds));
54
            }
55
        }
56
57 1
        return $convertedPacks;
58
    }
59
}
60