App   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 22.78 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 18
loc 79
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A GetAppList() 0 13 1
A convertToObjects() 0 8 1
A convertGames() 0 12 3
A appDetails() 18 18 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\App as AppContainer;
8
9
class App extends Client
10
{
11
    /**
12
     * @var bool
13
     */
14
15 2
    public function __construct()
16
    {
17 2
        parent::__construct();
18 2
        $this->url       = 'http://store.steampowered.com/';
19 2
        $this->interface = 'api';
20 2
    }
21
22
    /**
23
     * @param $appIds
24
     * @param null $country
25
     * @param null $language
26
     * @return Collection
27
     */
28 1 View Code Duplication
    public function appDetails($appIds, $country = 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...
29
    {
30
        // Set up the api details
31 1
        $this->method  = 'appdetails';
32 1
        $this->version = null;
33
34
        // Set up the arguments
35
        $arguments = [
36 1
            'appids' => $appIds,
37 1
            'cc' => $country,
38 1
            'l' => $language,
39
        ];
40
41
        // Get the client
42 1
        $client = $this->setUpClient($arguments);
43
44 1
        return $this->convertToObjects($client);
45
    }
46
47 1
    public function GetAppList()
48
    {
49
        // Set up the api details
50 1
        $this->url       = 'http://api.steampowered.com/';
51 1
        $this->interface = 'ISteamApps';
52 1
        $this->method    = __FUNCTION__;
53 1
        $this->version   = 'v0001';
54
55
        // Get the client
56 1
        $client = $this->setUpClient();
57
58 1
        return $client->applist->apps->app;
59
    }
60
61 1
    protected function convertToObjects($apps)
62
    {
63 1
        $convertedApps = $this->convertGames($apps);
64
65 1
        $apps = $this->sortObjects($convertedApps);
66
67 1
        return $apps;
68
    }
69
70
    /**
71
     * @param $apps
72
     *
73
     * @return Collection
74
     */
75 1
    protected function convertGames($apps)
76
    {
77 1
        $convertedApps = new Collection();
78
79 1
        foreach ($apps as $app) {
80 1
            if (isset($app->data)) {
81 1
                $convertedApps->add(new AppContainer($app->data));
82
            }
83
        }
84
85 1
        return $convertedApps;
86
    }
87
}
88