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.

UserService   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 39.44 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 28
loc 71
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getUser() 0 6 1
A getAttends() 14 14 2
A getEdits() 14 14 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\SetlistFm\Service;
13
14
use Core23\SetlistFm\Connection\ConnectionInterface;
15
use Core23\SetlistFm\Exception\ApiException;
16
use Core23\SetlistFm\Exception\NotFoundException;
17
use Core23\SetlistFm\Model\Setlist;
18
use Core23\SetlistFm\Model\User;
19
20
final class UserService
21
{
22
    /**
23
     * @var ConnectionInterface
24
     */
25
    private $connection;
26
27
    public function __construct(ConnectionInterface $connection)
28
    {
29
        $this->connection = $connection;
30
    }
31
32
    /**
33
     * Get the user data for an id.
34
     *
35
     * @throws ApiException
36
     * @throws NotFoundException
37
     */
38
    public function getUser(string $userId): User
39
    {
40
        return User::fromApi(
41
            $this->connection->call('user/'.$userId)
42
        );
43
    }
44
45
    /**
46
     * Get a list of attended venues for a user id.
47
     *
48
     * @throws ApiException
49
     * @throws NotFoundException
50
     *
51
     * @return Setlist[]
52
     */
53 View Code Duplication
    public function getAttends(string $userId, 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...
54
    {
55
        $response = $this->connection->call('user/'.$userId.'/attended', [
56
            'p' => $page,
57
        ]);
58
59
        if (!\array_key_exists('setlist', $response)) {
60
            return [];
61
        }
62
63
        return array_map(static function ($data) {
64
            return Setlist::fromApi($data);
65
        }, $response['setlist']);
66
    }
67
68
    /**
69
     * Get a list of edited venues for a user id.
70
     *
71
     * @throws ApiException
72
     * @throws NotFoundException
73
     *
74
     * @return Setlist[]
75
     */
76 View Code Duplication
    public function getEdits(string $userId, 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...
77
    {
78
        $response = $this->connection->call('user/'.$userId.'/edited', [
79
            'p' => $page,
80
        ]);
81
82
        if (!\array_key_exists('setlist', $response)) {
83
            return [];
84
        }
85
86
        return array_map(static function ($data) {
87
            return Setlist::fromApi($data);
88
        }, $response['setlist']);
89
    }
90
}
91