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 ( 74b698...28364d )
by Christian
01:33
created

ArtistSearchResult   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 104
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 104
loc 104
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
     * @param int      $page
37
     * @param int      $pageSize
38
     * @param int      $totalSize
39
     */
40
    private function __construct(array $result, int $page, int $pageSize, int $totalSize)
41
    {
42
        $this->result    = $result;
43
        $this->page      = $page;
44
        $this->pageSize  = $pageSize;
45
        $this->totalSize = $totalSize;
46
    }
47
48
    /**
49
     * @return Artist[]
50
     */
51
    public function getResult(): array
52
    {
53
        return $this->result;
54
    }
55
56
    /**
57
     * @return int
58
     */
59
    public function getPage(): int
60
    {
61
        return $this->page;
62
    }
63
64
    /**
65
     * @return int
66
     */
67
    public function getPageSize(): int
68
    {
69
        return $this->pageSize;
70
    }
71
72
    /**
73
     * @return int
74
     */
75
    public function getTotalSize(): int
76
    {
77
        return $this->totalSize;
78
    }
79
80
    /**
81
     * @return int
82
     */
83
    public function getLastPage(): int
84
    {
85
        return (int) floor($this->totalSize / $this->pageSize);
86
    }
87
88
    /**
89
     * @return ArtistSearchResult
90
     */
91
    public static function createEmpty(): self
92
    {
93
        return new self([], 0, 0, 0);
94
    }
95
96
    /**
97
     * @param array $response
98
     *
99
     * @return ArtistSearchResult
100
     */
101
    public static function fromApi(array $response): self
102
    {
103
        return new self(
104
            array_map(
105
                static function ($data) {
106
                    return Artist::fromApi($data);
107
                },
108
                $response['artist']
109
            ),
110
            (int) $response['page'],
111
            (int) $response['itemsPerPage'],
112
            (int) $response['total']
113
        );
114
    }
115
}
116