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 ( fc424a...ea923b )
by Christian
06:24
created

City::fromApi()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 3
eloc 14
nc 4
nop 1
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\Model;
13
14
final class City
15
{
16
    /**
17
     * @var int
18
     */
19
    private $id;
20
21
    /**
22
     * @var string
23
     */
24
    private $name;
25
26
    /**
27
     * @var string|null
28
     */
29
    private $state;
30
31
    /**
32
     * @var string|null
33
     */
34
    private $stateCode;
35
36
    /**
37
     * @var Country|null
38
     */
39
    private $county;
40
41
    /**
42
     * @var Geo|null
43
     */
44
    private $geo;
45
46
    /**
47
     * City constructor.
48
     *
49
     * @param int          $id
50
     * @param string       $name
51
     * @param null|string  $state
52
     * @param null|string  $stateCode
53
     * @param Country|null $county
54
     * @param Geo|null     $geo
55
     */
56
    public function __construct(
57
        int $id,
58
        string $name,
59
        ?string $state,
60
        ?string $stateCode,
61
        ?Country $county,
62
        ?Geo $geo
63
    ) {
64
        $this->id        = $id;
65
        $this->name      = $name;
66
        $this->state     = $state;
67
        $this->stateCode = $stateCode;
68
        $this->county    = $county;
69
        $this->geo       = $geo;
70
    }
71
72
    /**
73
     * @return int
74
     */
75
    public function getId(): int
76
    {
77
        return $this->id;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getName(): string
84
    {
85
        return $this->name;
86
    }
87
88
    /**
89
     * @return null|string
90
     */
91
    public function getState(): ?string
92
    {
93
        return $this->state;
94
    }
95
96
    /**
97
     * @return null|string
98
     */
99
    public function getStateCode(): ?string
100
    {
101
        return $this->stateCode;
102
    }
103
104
    /**
105
     * @return Country|null
106
     */
107
    public function getCounty(): ?Country
108
    {
109
        return $this->county;
110
    }
111
112
    /**
113
     * @return Geo|null
114
     */
115
    public function getGeo(): ?Geo
116
    {
117
        return $this->geo;
118
    }
119
120
    /**
121
     * @param array $data
122
     *
123
     * @return City
124
     */
125
    public static function fromApi(array $data): self
126
    {
127
        $geo     = null;
128
        $country = null;
129
130
        if ($data['coords']) {
131
            $geo = Geo::fromApi($data['coords']);
132
        }
133
134
        if ($data['country']) {
135
            $country = Country::fromApi($data['country']);
136
        }
137
138
        return new self(
139
            (int) $data['id'],
140
            $data['name'],
141
            $data['state'],
142
            $data['stateCode'],
143
            $country,
144
            $geo
145
        );
146
    }
147
}
148