-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWeatherCollection.php
More file actions
50 lines (39 loc) · 1.28 KB
/
WeatherCollection.php
File metadata and controls
50 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace ProgrammatorDev\OpenWeatherMap\Entity\Weather;
use ProgrammatorDev\OpenWeatherMap\Entity\Location;
use ProgrammatorDev\OpenWeatherMap\Helper\EntityHelper;
class WeatherCollection
{
private int $numResults;
private Location $location;
/** @var WeatherData[] */
private array $data;
public function __construct(array $data)
{
$this->numResults = $data['cnt'];
$this->location = new Location([
'lat' => $data['city']['coord']['lat'],
'lon' => $data['city']['coord']['lon'],
'id' => $data['city']['id'] ?? null,
'name' => $data['city']['name'] ?? null,
'country' => $data['city']['country'] ?? null,
'population' => $data['city']['population'] ?? null,
'sunrise' => $data['city']['sunrise'],
'sunset' => $data['city']['sunset'],
'timezone_offset' => $data['city']['timezone']
]);
$this->data = EntityHelper::createEntityList(WeatherData::class, $data['list']);
}
public function getNumResults(): int
{
return $this->numResults;
}
public function getLocation(): Location
{
return $this->location;
}
public function getData(): array
{
return $this->data;
}
}