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

CountrySearchResult::fromApi()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 1
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 CountrySearchResult
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 Country[]
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 Country[] $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 Country[]
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 CountrySearchResult
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 CountrySearchResult
100
     */
101
    public static function fromApi(array $response): self
102
    {
103
        return new self(
104
            array_map(
105
                static function ($data) {
106
                    return Country::fromApi($data);
107
                },
108
                $response['country']
109
            ),
110
            (int) $response['page'],
111
            (int) $response['itemsPerPage'],
112
            (int) $response['total']
113
        );
114
    }
115
}
116