Package   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 31.37 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 16
loc 51
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A convertToObjects() 0 7 1
A convertPacks() 0 11 3
A packageDetails() 16 16 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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