GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 625674...909c28 )
by Christian
01:42
created

GeoService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 30.65 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 19
loc 62
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getTopArtists() 19 19 2
A getTopTracks() 0 20 2

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
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\LastFm\Service;
13
14
use Core23\LastFm\Client\ApiClientInterface;
15
use Core23\LastFm\Model\Artist;
16
use Core23\LastFm\Model\Song;
17
use Core23\LastFm\Util\ApiHelper;
18
19
final class GeoService implements GeoServiceInterface
20
{
21
    /**
22
     * @var ApiClientInterface
23
     */
24
    private $client;
25
26
    /**
27
     * @param ApiClientInterface $client
28
     */
29
    public function __construct(ApiClientInterface $client)
30
    {
31
        $this->client = $client;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 View Code Duplication
    public function getTopArtists(string $country, int $limit = 50, int $page = 1): array
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...
38
    {
39
        $response = $this->client->unsignedCall('geo.getTopArtists', [
40
            'country' => $country,
41
            'limit'   => $limit,
42
            'page'    => $page,
43
        ]);
44
45
        if (!isset($response['topartists']['artist'])) {
46
            return [];
47
        }
48
49
        return ApiHelper::mapList(
50
            static function ($data) {
51
                return Artist::fromApi($data);
52
            },
53
            $response['topartists']['artist']
54
        );
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function getTopTracks(string $country, string $location = null, $limit = 50, int $page = 1): array
61
    {
62
        $response = $this->client->unsignedCall('geo.getTopTracks', [
63
            'country'  => $country,
64
            'location' => $location,
65
            'limit'    => $limit,
66
            'page'     => $page,
67
        ]);
68
69
        if (!isset($response['tracks']['track'])) {
70
            return [];
71
        }
72
73
        return ApiHelper::mapList(
74
            static function ($data) {
75
                return Song::fromApi($data);
76
            },
77
            $response['tracks']['track']
78
        );
79
    }
80
}
81