Skip to content

Commit 11b656f

Browse files
committed
chore: refactored EntityListTrait and entities
1 parent 2419859 commit 11b656f

18 files changed

+62
-124
lines changed

src/Endpoint/AbstractEndpoint.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ private function handleResponseErrors(ResponseInterface $response): void
123123
private function buildUrl(string $path, array $query): string
124124
{
125125
// Add application key to all requests
126-
$query = $query + [
127-
'appid' => $this->config->getApplicationKey()
128-
];
126+
$query['appid'] = $this->config->getApplicationKey();
129127

130128
return \sprintf('%s%s?%s', $this->config->getBaseUrl(), $path, http_build_query($query));
131129
}

src/Endpoint/AirPollutionEndpoint.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionLocation;
99
use ProgrammatorDev\OpenWeatherMap\Exception\ApiErrorException;
1010
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
11-
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
1211

1312
class AirPollutionEndpoint extends AbstractEndpoint
1413
{

src/Endpoint/GeocodingEndpoint.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77
use ProgrammatorDev\OpenWeatherMap\Entity\Geocoding\ZipCodeLocation;
88
use ProgrammatorDev\OpenWeatherMap\Entity\Location;
99
use ProgrammatorDev\OpenWeatherMap\Exception\ApiErrorException;
10-
use ProgrammatorDev\OpenWeatherMap\Util\CreateEntityListTrait;
10+
use ProgrammatorDev\OpenWeatherMap\Util\EntityListTrait;
1111
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
12-
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
1312

1413
class GeocodingEndpoint extends AbstractEndpoint
1514
{
1615
use ValidationTrait;
17-
use CreateEntityListTrait;
16+
use EntityListTrait;
1817

1918
private const NUM_RESULTS = 5;
2019

@@ -40,7 +39,7 @@ public function getByLocationName(string $locationName, int $numResults = self::
4039
]
4140
);
4241

43-
return $this->createEntityList($data, Location::class);
42+
return $this->createEntityList(Location::class, $data);
4443
}
4544

4645
/**
@@ -85,6 +84,6 @@ public function getByCoordinate(float $latitude, float $longitude, int $numResul
8584
]
8685
);
8786

88-
return $this->createEntityList($data, Location::class);
87+
return $this->createEntityList(Location::class, $data);
8988
}
9089
}

src/Endpoint/OneCallEndpoint.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\OneCall;
1212
use ProgrammatorDev\OpenWeatherMap\Exception\ApiErrorException;
1313
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
14-
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
1514

1615
class OneCallEndpoint extends AbstractEndpoint
1716
{

src/Endpoint/WeatherEndpoint.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use ProgrammatorDev\OpenWeatherMap\Entity\Weather\WeatherLocationList;
1111
use ProgrammatorDev\OpenWeatherMap\Exception\ApiErrorException;
1212
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
13-
use ProgrammatorDev\YetAnotherPhpValidator\Validator;
1413

1514
class WeatherEndpoint extends AbstractEndpoint
1615
{

src/Entity/AirPollution/AirPollutionLocationList.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,28 @@
33
namespace ProgrammatorDev\OpenWeatherMap\Entity\AirPollution;
44

55
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
6-
use ProgrammatorDev\OpenWeatherMap\Util\CreateEntityListTrait;
6+
use ProgrammatorDev\OpenWeatherMap\Util\EntityListTrait;
77

88
class AirPollutionLocationList
99
{
10-
use CreateEntityListTrait;
10+
use EntityListTrait;
1111

1212
private Coordinate $coordinate;
1313

14+
/** @var AirPollution[] */
1415
private array $list;
1516

1617
public function __construct(array $data)
1718
{
1819
$this->coordinate = new Coordinate($data['coord']);
19-
$this->list = $this->createEntityList($data['list'], AirPollution::class);
20+
$this->list = $this->createEntityList(AirPollution::class, $data['list']);
2021
}
2122

2223
public function getCoordinate(): Coordinate
2324
{
2425
return $this->coordinate;
2526
}
2627

27-
/**
28-
* @return AirPollution[]
29-
*/
3028
public function getList(): array
3129
{
3230
return $this->list;

src/Entity/AirPollution/AirQuality.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace ProgrammatorDev\OpenWeatherMap\Entity\AirPollution;
44

5-
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\Util\GetAirQualityQualitativeNameTrait;
5+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\Util\AirQualityQualitativeNameTrait;
66

77
class AirQuality
88
{
9-
use GetAirQualityQualitativeNameTrait;
9+
use AirQualityQualitativeNameTrait;
1010

1111
private int $index;
1212

src/Entity/AirPollution/Util/GetAirQualityQualitativeNameTrait.php renamed to src/Entity/AirPollution/Util/AirQualityQualitativeNameTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\Util;
44

5-
trait GetAirQualityQualitativeNameTrait
5+
trait AirQualityQualitativeNameTrait
66
{
77
// Levels based on https://openweathermap.org/api/air-pollution
88
private array $airQualityIndex = [

src/Entity/AtmosphericPressure.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class AtmosphericPressure
1313
public function __construct(array $data)
1414
{
1515
$this->pressure = $data['pressure'];
16-
1716
$this->seaLevelPressure = $data['sea_level'] ?? null;
1817
$this->groundLevelPressure = $data['grnd_level'] ?? null;
1918
}

src/Entity/Location.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,15 @@ public function __construct(array $data)
3030
'lat' => $data['lat'],
3131
'lon' => $data['lon']
3232
]);
33-
3433
$this->id = !empty($data['id']) ? $data['id'] : null;
3534
$this->name = !empty($data['name']) ? $data['name'] : null;
3635
$this->state = !empty($data['state']) ? $data['state'] : null;
3736
$this->countryCode = !empty($data['country']) ? $data['country'] : null;
3837
$this->localNames = !empty($data['local_names']) ? $data['local_names'] : null;
3938
$this->population = !empty($data['population']) ? $data['population'] : null;
40-
41-
$this->sunriseAt = !empty($data['sunrise'])
42-
? \DateTimeImmutable::createFromFormat('U', $data['sunrise'], new \DateTimeZone('UTC'))
43-
: null;
44-
$this->sunsetAt = !empty($data['sunset'])
45-
? \DateTimeImmutable::createFromFormat('U', $data['sunset'], new \DateTimeZone('UTC'))
46-
: null;
47-
48-
$this->timezone = isset($data['timezone_offset'])
49-
? new Timezone(['timezone_offset' => $data['timezone_offset']])
50-
: null;
39+
$this->sunriseAt = !empty($data['sunrise']) ? \DateTimeImmutable::createFromFormat('U', $data['sunrise'], new \DateTimeZone('UTC')) : null;
40+
$this->sunsetAt = !empty($data['sunset']) ? \DateTimeImmutable::createFromFormat('U', $data['sunset'], new \DateTimeZone('UTC')) : null;
41+
$this->timezone = isset($data['timezone_offset']) ? new Timezone(['timezone_offset' => $data['timezone_offset']]) : null;
5142
}
5243

5344
public function getId(): ?int

0 commit comments

Comments
 (0)