Skip to content

Commit e553377

Browse files
committed
chore: merged Component entity into AirPollution and removed it
1 parent 72f6971 commit e553377

File tree

3 files changed

+87
-112
lines changed

3 files changed

+87
-112
lines changed

src/Entity/AirPollution/AirPollution.php

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,34 @@ class AirPollution
88

99
private AirQuality $airQuality;
1010

11-
private Component $components;
11+
private float $carbonMonoxide;
12+
13+
private float $nitrogenMonoxide;
14+
15+
private float $nitrogenDioxide;
16+
17+
private float $ozone;
18+
19+
private float $sulphurDioxide;
20+
21+
private float $fineParticulateMatter;
22+
23+
private float $coarseParticulateMatter;
24+
25+
private float $ammonia;
1226

1327
public function __construct(array $data)
1428
{
1529
$this->dateTime = \DateTimeImmutable::createFromFormat('U', $data['dt'], new \DateTimeZone('UTC'));
1630
$this->airQuality = new AirQuality($data['main']);
17-
$this->components = new Component($data['components']);
31+
$this->carbonMonoxide = $data['components']['co'];
32+
$this->nitrogenMonoxide = $data['components']['no'];
33+
$this->nitrogenDioxide = $data['components']['no2'];
34+
$this->ozone = $data['components']['o3'];
35+
$this->sulphurDioxide = $data['components']['so2'];
36+
$this->fineParticulateMatter = $data['components']['pm2_5'];
37+
$this->coarseParticulateMatter = $data['components']['pm10'];
38+
$this->ammonia = $data['components']['nh3'];
1839
}
1940

2041
public function getDateTime(): \DateTimeImmutable
@@ -27,8 +48,43 @@ public function getAirQuality(): AirQuality
2748
return $this->airQuality;
2849
}
2950

30-
public function getComponents(): Component
51+
public function getCarbonMonoxide(): float
52+
{
53+
return $this->carbonMonoxide;
54+
}
55+
56+
public function getNitrogenMonoxide(): float
57+
{
58+
return $this->nitrogenMonoxide;
59+
}
60+
61+
public function getNitrogenDioxide(): float
62+
{
63+
return $this->nitrogenDioxide;
64+
}
65+
66+
public function getOzone(): float
67+
{
68+
return $this->ozone;
69+
}
70+
71+
public function getSulphurDioxide(): float
72+
{
73+
return $this->sulphurDioxide;
74+
}
75+
76+
public function getFineParticulateMatter(): float
77+
{
78+
return $this->fineParticulateMatter;
79+
}
80+
81+
public function getCoarseParticulateMatter(): float
82+
{
83+
return $this->coarseParticulateMatter;
84+
}
85+
86+
public function getAmmonia(): float
3187
{
32-
return $this->components;
88+
return $this->ammonia;
3389
}
3490
}

src/Entity/AirPollution/Component.php

Lines changed: 0 additions & 74 deletions
This file was deleted.

tests/AirPollutionEndpointTest.php

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollution;
88
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionList;
99
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirQuality;
10-
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\Component;
1110
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\CurrentAirPollution;
1211
use ProgrammatorDev\OpenWeatherMap\Entity\Coordinate;
1312
use ProgrammatorDev\OpenWeatherMap\Entity\Location;
@@ -131,6 +130,15 @@ private function assertCurrentResponse(CurrentAirPollution $response): void
131130
{
132131
$this->assertInstanceOf(CurrentAirPollution::class, $response);
133132

133+
$this->assertSame(196.93, $response->getCarbonMonoxide());
134+
$this->assertSame(0.65, $response->getNitrogenMonoxide());
135+
$this->assertSame(3.98, $response->getNitrogenDioxide());
136+
$this->assertSame(107.29, $response->getOzone());
137+
$this->assertSame(1.46, $response->getSulphurDioxide());
138+
$this->assertSame(8.58, $response->getFineParticulateMatter());
139+
$this->assertSame(13.5, $response->getCoarseParticulateMatter());
140+
$this->assertSame(2.03, $response->getAmmonia());
141+
134142
$location = $response->getLocation();
135143
$this->assertInstanceOf(Location::class, $location);
136144
$this->assertSame(null, $location->getId());
@@ -156,17 +164,6 @@ private function assertCurrentResponse(CurrentAirPollution $response): void
156164
$this->assertInstanceOf(AirQuality::class, $airQuality);
157165
$this->assertSame(3, $airQuality->getIndex());
158166
$this->assertSame('Moderate', $airQuality->getQualitativeName());
159-
160-
$components = $response->getComponents();
161-
$this->assertInstanceOf(Component::class, $components);
162-
$this->assertSame(196.93, $components->getCarbonMonoxide());
163-
$this->assertSame(0.65, $components->getNitrogenMonoxide());
164-
$this->assertSame(3.98, $components->getNitrogenDioxide());
165-
$this->assertSame(107.29, $components->getOzone());
166-
$this->assertSame(1.46, $components->getSulphurDioxide());
167-
$this->assertSame(8.58, $components->getFineParticulateMatter());
168-
$this->assertSame(13.5, $components->getCoarseParticulateMatter());
169-
$this->assertSame(2.03, $components->getAmmonia());
170167
}
171168

172169
private function assertForecastResponse(AirPollutionList $response): void
@@ -193,6 +190,15 @@ private function assertForecastResponse(AirPollutionList $response): void
193190
$list = $response->getList();
194191
$this->assertContainsOnlyInstancesOf(AirPollution::class, $list);
195192

193+
$this->assertSame(196.93, $list[0]->getCarbonMonoxide());
194+
$this->assertSame(0.65, $list[0]->getNitrogenMonoxide());
195+
$this->assertSame(3.98, $list[0]->getNitrogenDioxide());
196+
$this->assertSame(107.29, $list[0]->getOzone());
197+
$this->assertSame(1.46, $list[0]->getSulphurDioxide());
198+
$this->assertSame(8.58, $list[0]->getFineParticulateMatter());
199+
$this->assertSame(13.5, $list[0]->getCoarseParticulateMatter());
200+
$this->assertSame(2.03, $list[0]->getAmmonia());
201+
196202
$dateTime = $list[0]->getDateTime();
197203
$this->assertInstanceOf(\DateTimeImmutable::class, $dateTime);
198204
$this->assertSame('2023-06-23 17:00:00', $dateTime->format('Y-m-d H:i:s'));
@@ -201,17 +207,6 @@ private function assertForecastResponse(AirPollutionList $response): void
201207
$this->assertInstanceOf(AirQuality::class, $airQuality);
202208
$this->assertSame(3, $airQuality->getIndex());
203209
$this->assertSame('Moderate', $airQuality->getQualitativeName());
204-
205-
$components = $list[0]->getComponents();
206-
$this->assertInstanceOf(Component::class, $components);
207-
$this->assertSame(196.93, $components->getCarbonMonoxide());
208-
$this->assertSame(0.65, $components->getNitrogenMonoxide());
209-
$this->assertSame(3.98, $components->getNitrogenDioxide());
210-
$this->assertSame(107.29, $components->getOzone());
211-
$this->assertSame(1.46, $components->getSulphurDioxide());
212-
$this->assertSame(8.58, $components->getFineParticulateMatter());
213-
$this->assertSame(13.5, $components->getCoarseParticulateMatter());
214-
$this->assertSame(2.03, $components->getAmmonia());
215210
}
216211

217212
private function assertHistoryResponse(AirPollutionList $response): void
@@ -238,6 +233,15 @@ private function assertHistoryResponse(AirPollutionList $response): void
238233
$list = $response->getList();
239234
$this->assertContainsOnlyInstancesOf(AirPollution::class, $list);
240235

236+
$this->assertSame(220.3, $list[0]->getCarbonMonoxide());
237+
$this->assertSame(0.12, $list[0]->getNitrogenMonoxide());
238+
$this->assertSame(3.3, $list[0]->getNitrogenDioxide());
239+
$this->assertSame(87.26, $list[0]->getOzone());
240+
$this->assertSame(1.25, $list[0]->getSulphurDioxide());
241+
$this->assertSame(1.62, $list[0]->getFineParticulateMatter());
242+
$this->assertSame(2.94, $list[0]->getCoarseParticulateMatter());
243+
$this->assertSame(0.38, $list[0]->getAmmonia());
244+
241245
$dateTime = $list[0]->getDateTime();
242246
$this->assertInstanceOf(\DateTimeImmutable::class, $dateTime);
243247
$this->assertSame('2023-06-18 18:00:00', $dateTime->format('Y-m-d H:i:s'));
@@ -246,16 +250,5 @@ private function assertHistoryResponse(AirPollutionList $response): void
246250
$this->assertInstanceOf(AirQuality::class, $airQuality);
247251
$this->assertSame(2, $airQuality->getIndex());
248252
$this->assertSame('Fair', $airQuality->getQualitativeName());
249-
250-
$components = $list[0]->getComponents();
251-
$this->assertInstanceOf(Component::class, $components);
252-
$this->assertSame(220.3, $components->getCarbonMonoxide());
253-
$this->assertSame(0.12, $components->getNitrogenMonoxide());
254-
$this->assertSame(3.3, $components->getNitrogenDioxide());
255-
$this->assertSame(87.26, $components->getOzone());
256-
$this->assertSame(1.25, $components->getSulphurDioxide());
257-
$this->assertSame(1.62, $components->getFineParticulateMatter());
258-
$this->assertSame(2.94, $components->getCoarseParticulateMatter());
259-
$this->assertSame(0.38, $components->getAmmonia());
260253
}
261254
}

0 commit comments

Comments
 (0)