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.

ArtistSearchResult   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 87
loc 87
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A getResult() 4 4 1
A getPage() 4 4 1
A getPageSize() 4 4 1
A getTotalSize() 4 4 1
A getLastPage() 4 4 1
A createEmpty() 4 4 1
A fromApi() 14 14 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
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\SetlistFm\Model;
11
12 View Code Duplication
final class ArtistSearchResult
0 ignored issues
show
Duplication introduced by
This class 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...
13
{
14
    /**
15
     * @var Artist[]
16
     */
17
    private $result;
18
19
    /**
20
     * @var int
21
     */
22
    private $page;
23
24
    /**
25
     * @var int
26
     */
27
    private $pageSize;
28
29
    /**
30
     * @var int
31
     */
32
    private $totalSize;
33
34
    /**
35
     * @param Artist[] $result
36
     */
37
    private function __construct(array $result, int $page, int $pageSize, int $totalSize)
38
    {
39
        $this->result    = $result;
40
        $this->page      = $page;
41
        $this->pageSize  = $pageSize;
42
        $this->totalSize = $totalSize;
43
    }
44
45
    /**
46
     * @return Artist[]
47
     */
48
    public function getResult(): array
49
    {
50
        return $this->result;
51
    }
52
53
    public function getPage(): int
54
    {
55
        return $this->page;
56
    }
57
58
    public function getPageSize(): int
59
    {
60
        return $this->pageSize;
61
    }
62
63
    public function getTotalSize(): int
64
    {
65
        return $this->totalSize;
66
    }
67
68
    public function getLastPage(): int
69
    {
70
        return (int) ceil($this->totalSize / $this->pageSize);
71
    }
72
73
    /**
74
     * @return ArtistSearchResult
75
     */
76
    public static function createEmpty(): self
77
    {
78
        return new self([], 0, 0, 0);
79
    }
80
81
    /**
82
     * @return ArtistSearchResult
83
     */
84
    public static function fromApi(array $response): self
85
    {
86
        return new self(
87
            array_map(
88
                static function ($data) {
89
                    return Artist::fromApi($data);
90
                },
91
                $response['artist']
92
            ),
93
            (int) $response['page'],
94
            (int) $response['itemsPerPage'],
95
            (int) $response['total']
96
        );
97
    }
98
}
99