From d2f8b4dce983fa583573894cc0af6067002a40b8 Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Wed, 24 Jan 2024 16:00:42 +0530 Subject: [PATCH 01/11] WIP: Initial commit. --- .../Serializer/WarningInfoNormalizer.php | 38 +++ src/Warning/Serializer/WarningNormalizer.php | 82 ++++++ .../Serializer/WarningSerializerFactory.php | 39 +++ src/Warning/Warning.php | 249 ++++++++++++++++++ src/Warning/WarningInfo.php | 94 +++++++ 5 files changed, 502 insertions(+) create mode 100644 src/Warning/Serializer/WarningInfoNormalizer.php create mode 100644 src/Warning/Serializer/WarningNormalizer.php create mode 100644 src/Warning/Serializer/WarningSerializerFactory.php create mode 100644 src/Warning/Warning.php create mode 100644 src/Warning/WarningInfo.php diff --git a/src/Warning/Serializer/WarningInfoNormalizer.php b/src/Warning/Serializer/WarningInfoNormalizer.php new file mode 100644 index 0000000..cf81e5f --- /dev/null +++ b/src/Warning/Serializer/WarningInfoNormalizer.php @@ -0,0 +1,38 @@ +serializer instanceof DenormalizerInterface) { + throw new \RuntimeException('The serializer must implement the DenormalizerInterface.'); + } + + $warningInfo = (new WarningInfo()); + + + return $warningInfo; + } + +} diff --git a/src/Warning/Serializer/WarningNormalizer.php b/src/Warning/Serializer/WarningNormalizer.php new file mode 100644 index 0000000..11ed547 --- /dev/null +++ b/src/Warning/Serializer/WarningNormalizer.php @@ -0,0 +1,82 @@ +serializer instanceof DenormalizerInterface) { + throw new \RuntimeException('The serializer must implement the DenormalizerInterface.'); + } + + $warning = (new Warning()) + ->setIssueTime($this->serializer->denormalize($data['amoc']['issue-time-utc'], \DateTimeImmutable::class)); + + if ($this->isAssoc($data['warning']['area'])) { + $area = $data['warning']['area']; + $this->setValue($area, $warning); + } + else { + \array_map(function ($area) use ($warning): void { + $this->setValue($area, $warning); + }, $data['warning']['area'], [$warning]); + } + + $warningInfo = $this->serializer->denormalize($data['warning']['warning-info'], WarningInfo::class); + + return $warning; + } + + /** + * Sets the area value. + * + * @param array $area + * The area data. + * @param \BomWeather\Warning\Warning $warning + * The warning. + */ + public function setValue(array $area, Warning $warning): void { + switch ($area['@type']) { + case Area::TYPE_REGION: + $warning->addRegion($this->serializer->denormalize($area, Area::class)); + break; + + case Area::TYPE_DISTRICT: + $warning->addDistrict($this->serializer->denormalize($area, Area::class)); + break; + + case Area::TYPE_METROPOLITAN: + $warning->addMetropolitanArea($this->serializer->denormalize($area, Area::class)); + break; + + case Area::TYPE_LOCATION: + $warning->addLocation($this->serializer->denormalize($area, Area::class)); + break; + + case Area::TYPE_COAST: + $warning->addCoast($this->serializer->denormalize($area, Area::class)); + break; + } + } + +} diff --git a/src/Warning/Serializer/WarningSerializerFactory.php b/src/Warning/Serializer/WarningSerializerFactory.php new file mode 100644 index 0000000..91b4451 --- /dev/null +++ b/src/Warning/Serializer/WarningSerializerFactory.php @@ -0,0 +1,39 @@ + $rootNode])]; + $normalizers = [ + new DateTimeNormalizer([DateTimeNormalizer::TIMEZONE_KEY => 'UTC']), + new WarningNormalizer(), + new WarningInfoNormalizer(), + new AreaNormalizer(), + ]; + return new Serializer($normalizers, $encoders); + } + +} diff --git a/src/Warning/Warning.php b/src/Warning/Warning.php new file mode 100644 index 0000000..40c6055 --- /dev/null +++ b/src/Warning/Warning.php @@ -0,0 +1,249 @@ +regions; + } + + /** + * Sets the regions. + * + * @param \BomWeather\Forecast\Area[] $regions + * The regions. + * + * @return $this + */ + public function setRegions(array $regions): Warning { + $this->regions = $regions; + return $this; + } + + /** + * Adds a region. + * + * @param \BomWeather\Forecast\Area $region + * The region. + * + * @return $this + */ + public function addRegion(Area $region): Warning { + $this->regions[] = $region; + return $this; + } + + /** + * Gets the districts. + * + * @return \BomWeather\Forecast\Area[] + * The districts. + */ + public function getDistricts(): array { + return $this->districts; + } + + /** + * Sets the districts. + * + * @param \BomWeather\Forecast\Area[] $districts + * The districts. + * + * @return $this + */ + public function setDistricts(array $districts): Warning { + $this->districts = $districts; + return $this; + } + + /** + * Adds a district. + * + * @param \BomWeather\Forecast\Area $district + * The district. + * + * @return $this + */ + public function addDistrict(Area $district): Warning { + $this->districts[] = $district; + return $this; + } + + /** + * Gets the metropolitan areas. + * + * @return \BomWeather\Forecast\Area[] + * The metropolitan areas. + */ + public function getMetropolitanAreas(): array { + return $this->metropolitanAreas; + } + + /** + * Sets the metropolitan areas. + * + * @param \BomWeather\Forecast\Area[] $metropolitanAreas + * The metropolitan areas. + * + * @return $this + */ + public function setMetropolitanAreas(array $metropolitanAreas): Warning { + $this->metropolitanAreas = $metropolitanAreas; + return $this; + } + + /** + * Adds a metropolitan area. + * + * @param \BomWeather\Forecast\Area $metropolitanArea + * The metropolitan area. + * + * @return $this + */ + public function addMetropolitanArea(Area $metropolitanArea): Warning { + $this->metropolitanAreas[] = $metropolitanArea; + return $this; + } + + /** + * Gets the locations. + * + * @return \BomWeather\Forecast\Area[] + * The locations. + */ + public function getLocations(): array { + return $this->locations; + } + + /** + * Sets the locations. + * + * @param \BomWeather\Forecast\Area[] $locations + * The locations. + * + * @return $this + */ + public function setLocations(array $locations): Warning { + $this->locations = $locations; + return $this; + } + + /** + * Adds a location. + * + * @param \BomWeather\Forecast\Area $location + * The location. + * + * @return $this + */ + public function addLocation(Area $location): Warning { + $this->locations[] = $location; + return $this; + } + + /** + * Gets the issue time. + */ + public function getIssueTime(): ?\DateTimeImmutable { + return $this->issueTime; + } + + /** + * Sets the issue time. + */ + public function setIssueTime(\DateTimeImmutable $issueTime): Warning { + $this->issueTime = $issueTime; + return $this; + } + + /** + * Gets the coasts. + * + * @return \BomWeather\Forecast\Area[] + * The coasts. + */ + public function getCoasts(): array { + return $this->coasts; + } + + /** + * Sets the coasts. + * + * @param \BomWeather\Forecast\Area[] $coasts + * The coasts. + * + * @return $this + */ + public function setCoasts(array $coasts): Warning { + $this->coasts = $coasts; + return $this; + } + + /** + * Adds a coast. + * + * @param \BomWeather\Forecast\Area $coast + * The coast. + * + * @return $this + */ + public function addCoast(Area $coast): Warning { + $this->coasts[] = $coast; + return $this; + } + +} diff --git a/src/Warning/WarningInfo.php b/src/Warning/WarningInfo.php new file mode 100644 index 0000000..e73e5f0 --- /dev/null +++ b/src/Warning/WarningInfo.php @@ -0,0 +1,94 @@ +warningTitle; + } + + /** + * Sets the warning title. + */ + public function setWarningTitle(?string $warningTitle): WarningInfo { + $this->warningTitle = $warningTitle; + return $this; + } + + /** + * Gets the preamble text. + */ + public function getPreamble(): ?string { + return $this->preamble; + } + + /** + * Sets the preamble text. + */ + public function setPreamble(?string $preamble): WarningInfo { + $this->preamble = $preamble; + return $this; + } + + /** + * Gets an array of warning advices. + */ + public function getWarningAdvices(): array { + return $this->warningAdvice; + } + + /** + * Sets warning advice to advices array. + */ + public function setWarningAdvice(string $warningAdvice): WarningInfo { + $this->warningAdvice[] = $warningAdvice; + return $this; + } + + /** + * Get the text for next warning issue date. + */ + public function getWarningNextIssue(): ?string { + return $this->warningNextIssue; + } + + /** + * Set the text for next warning issue date. + */ + public function setWarningNextIssue(?string $warningNextIssue): WarningInfo { + $this->warningNextIssue = $warningNextIssue; + return $this; + } + +} From 215a5b53bc985ea3932a6990791d34e5e8601ae4 Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Thu, 25 Jan 2024 09:54:51 +0530 Subject: [PATCH 02/11] Refactoring --- .../Serializer/WarningInfoNormalizer.php | 34 +++++++++++++++++-- src/Warning/Serializer/WarningNormalizer.php | 2 +- .../Serializer/WarningSerializerFactory.php | 2 +- src/Warning/Warning.php | 22 +++++++++++- src/Warning/WarningInfo.php | 4 +-- 5 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/Warning/Serializer/WarningInfoNormalizer.php b/src/Warning/Serializer/WarningInfoNormalizer.php index cf81e5f..11a068a 100644 --- a/src/Warning/Serializer/WarningInfoNormalizer.php +++ b/src/Warning/Serializer/WarningInfoNormalizer.php @@ -4,10 +4,7 @@ namespace BomWeather\Warning\Serializer; -use BomWeather\Forecast\Area; -use BomWeather\Forecast\Forecast; use BomWeather\Util\BaseNormalizer; -use BomWeather\Warning\Warning; use BomWeather\Warning\WarningInfo; use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; @@ -31,8 +28,39 @@ public function denormalize($data, $type, $format = NULL, array $context = []) { $warningInfo = (new WarningInfo()); + if (isset($data['text'])) { + if ($this->isAssoc($data['text'])) { + $text = $data['text']; + $this->setTextValue($text, $warningInfo); + } + else { + \array_map(function ($text) use ($warningInfo): void { + $this->setTextValue($text, $warningInfo); + }, $data['text'], [$warningInfo]); + } + } return $warningInfo; } + /** + * Sets a text value. + * + * @param array $text + * The text array. + * @param \BomWeather\Warning\WarningInfo $warningInfo + * The warning info. + */ + public function setTextValue(array $text, WarningInfo $warningInfo): void { + match ($text['@type']) { + 'warning_title' => $warningInfo->setWarningTitle($text['#']), + 'preamble' => $warningInfo->setPreamble($text['#']), + 'warning_advice' => \array_map(function ($advice) use ($warningInfo): void { + $warningInfo->setWarningAdvice($advice); + }, $text['p']), + 'warning_next_issue' => $warningInfo->setWarningNextIssue($text['#']), + default => '', + }; + } + } diff --git a/src/Warning/Serializer/WarningNormalizer.php b/src/Warning/Serializer/WarningNormalizer.php index 11ed547..be6e4fa 100644 --- a/src/Warning/Serializer/WarningNormalizer.php +++ b/src/Warning/Serializer/WarningNormalizer.php @@ -5,7 +5,6 @@ namespace BomWeather\Warning\Serializer; use BomWeather\Forecast\Area; -use BomWeather\Forecast\Forecast; use BomWeather\Util\BaseNormalizer; use BomWeather\Warning\Warning; use BomWeather\Warning\WarningInfo; @@ -43,6 +42,7 @@ public function denormalize($data, $type, $format = NULL, array $context = []) { } $warningInfo = $this->serializer->denormalize($data['warning']['warning-info'], WarningInfo::class); + $warning->setWarningInfo($warningInfo); return $warning; } diff --git a/src/Warning/Serializer/WarningSerializerFactory.php b/src/Warning/Serializer/WarningSerializerFactory.php index 91b4451..0a5231d 100644 --- a/src/Warning/Serializer/WarningSerializerFactory.php +++ b/src/Warning/Serializer/WarningSerializerFactory.php @@ -5,7 +5,6 @@ namespace BomWeather\Warning\Serializer; use BomWeather\Forecast\Serializer\AreaNormalizer; -use BomWeather\Forecast\Serializer\ForecastNormalizer; use BomWeather\Forecast\Serializer\ForecastPeriodNormalizer; use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer; @@ -32,6 +31,7 @@ public static function create(string $rootNode = 'product'): Serializer { new WarningNormalizer(), new WarningInfoNormalizer(), new AreaNormalizer(), + new ForecastPeriodNormalizer(), ]; return new Serializer($normalizers, $encoders); } diff --git a/src/Warning/Warning.php b/src/Warning/Warning.php index 40c6055..a16e8b2 100644 --- a/src/Warning/Warning.php +++ b/src/Warning/Warning.php @@ -7,7 +7,7 @@ use BomWeather\Forecast\Area; /** - * A value object for weather forcasts. + * A value object for weather warning. */ final class Warning { @@ -51,6 +51,11 @@ final class Warning { */ protected \DateTimeImmutable $issueTime; + /** + * The warning information. + */ + protected ?WarningInfo $warningInfo = NULL; + /** * Gets the regions. * @@ -246,4 +251,19 @@ public function addCoast(Area $coast): Warning { return $this; } + /** + * Gets the warning information. + */ + public function getWarningInfo(): ?WarningInfo { + return $this->warningInfo; + } + + /** + * Sets the warning information. + */ + public function setWarningInfo(?WarningInfo $warningInfo): Warning { + $this->warningInfo = $warningInfo; + return $this; + } + } diff --git a/src/Warning/WarningInfo.php b/src/Warning/WarningInfo.php index e73e5f0..2ed317c 100644 --- a/src/Warning/WarningInfo.php +++ b/src/Warning/WarningInfo.php @@ -4,10 +4,8 @@ namespace BomWeather\Warning; -use BomWeather\Forecast\Area; - /** - * A value object for weather forcasts. + * A value object for weather warning information. */ final class WarningInfo { From 9bd719a8c1d0296952ae168bb1aaff7406b068fa Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Mon, 29 Jan 2024 17:53:47 +0530 Subject: [PATCH 03/11] validation to check that weather exists. --- src/Forecast/ForecastPeriod.php | 2 +- src/Warning/Serializer/WarningNormalizer.php | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Forecast/ForecastPeriod.php b/src/Forecast/ForecastPeriod.php index 13a79c6..e2c063b 100644 --- a/src/Forecast/ForecastPeriod.php +++ b/src/Forecast/ForecastPeriod.php @@ -216,7 +216,7 @@ public function getForecast(): ?string { /** * Sets the forecast. */ - public function setForecast(string $forecast): ForecastPeriod { + public function setForecast(?string $forecast): ForecastPeriod { $this->forecast = $forecast; return $this; } diff --git a/src/Warning/Serializer/WarningNormalizer.php b/src/Warning/Serializer/WarningNormalizer.php index be6e4fa..7f4cf42 100644 --- a/src/Warning/Serializer/WarningNormalizer.php +++ b/src/Warning/Serializer/WarningNormalizer.php @@ -31,14 +31,16 @@ public function denormalize($data, $type, $format = NULL, array $context = []) { $warning = (new Warning()) ->setIssueTime($this->serializer->denormalize($data['amoc']['issue-time-utc'], \DateTimeImmutable::class)); - if ($this->isAssoc($data['warning']['area'])) { - $area = $data['warning']['area']; - $this->setValue($area, $warning); - } - else { - \array_map(function ($area) use ($warning): void { + if (array_key_exists('warning', $data)) { + if ($this->isAssoc($data['warning']['area'])) { + $area = $data['warning']['area']; $this->setValue($area, $warning); - }, $data['warning']['area'], [$warning]); + } + else { + \array_map(function ($area) use ($warning): void { + $this->setValue($area, $warning); + }, $data['warning']['area'], [$warning]); + } } $warningInfo = $this->serializer->denormalize($data['warning']['warning-info'], WarningInfo::class); From f3305b074c5ae69b02e80e0d770b2ac66b5b1bbf Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Mon, 29 Jan 2024 17:55:55 +0530 Subject: [PATCH 04/11] phpcs fixes. --- src/Warning/Serializer/WarningNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Warning/Serializer/WarningNormalizer.php b/src/Warning/Serializer/WarningNormalizer.php index 7f4cf42..d9d51de 100644 --- a/src/Warning/Serializer/WarningNormalizer.php +++ b/src/Warning/Serializer/WarningNormalizer.php @@ -31,7 +31,7 @@ public function denormalize($data, $type, $format = NULL, array $context = []) { $warning = (new Warning()) ->setIssueTime($this->serializer->denormalize($data['amoc']['issue-time-utc'], \DateTimeImmutable::class)); - if (array_key_exists('warning', $data)) { + if (\array_key_exists('warning', $data)) { if ($this->isAssoc($data['warning']['area'])) { $area = $data['warning']['area']; $this->setValue($area, $warning); From e48748e3b471013fcf6168c7fb8f8ecb65d0f5fc Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Mon, 29 Jan 2024 18:08:35 +0530 Subject: [PATCH 05/11] Further validation. --- src/Warning/Serializer/WarningNormalizer.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Warning/Serializer/WarningNormalizer.php b/src/Warning/Serializer/WarningNormalizer.php index d9d51de..ab6148c 100644 --- a/src/Warning/Serializer/WarningNormalizer.php +++ b/src/Warning/Serializer/WarningNormalizer.php @@ -41,11 +41,10 @@ public function denormalize($data, $type, $format = NULL, array $context = []) { $this->setValue($area, $warning); }, $data['warning']['area'], [$warning]); } + $warningInfo = $this->serializer->denormalize($data['warning']['warning-info'], WarningInfo::class); + $warning->setWarningInfo($warningInfo); } - $warningInfo = $this->serializer->denormalize($data['warning']['warning-info'], WarningInfo::class); - $warning->setWarningInfo($warningInfo); - return $warning; } From 33a4fd4a60131a2e579901f050a078b84f73f386 Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Thu, 1 Feb 2024 21:23:56 +0530 Subject: [PATCH 06/11] Set accessor trait to validate the key before accessing. --- .../Serializer/ForecastPeriodNormalizer.php | 75 ++++++------------- src/Trait/WeatherDataAccessorTrait.php | 30 ++++++++ .../Serializer/WarningInfoNormalizer.php | 12 ++- 3 files changed, 61 insertions(+), 56 deletions(-) create mode 100644 src/Trait/WeatherDataAccessorTrait.php diff --git a/src/Forecast/Serializer/ForecastPeriodNormalizer.php b/src/Forecast/Serializer/ForecastPeriodNormalizer.php index 70dc9cc..d6b8239 100644 --- a/src/Forecast/Serializer/ForecastPeriodNormalizer.php +++ b/src/Forecast/Serializer/ForecastPeriodNormalizer.php @@ -5,6 +5,7 @@ namespace BomWeather\Forecast\Serializer; use BomWeather\Forecast\ForecastPeriod; +use BomWeather\Trait\WeatherDataAccessorTrait; use BomWeather\Util\BaseNormalizer; /** @@ -12,6 +13,8 @@ */ class ForecastPeriodNormalizer extends BaseNormalizer { + use WeatherDataAccessorTrait; + protected string|array $supportedInterfaceOrClass = ForecastPeriod::class; /** @@ -57,24 +60,14 @@ public function denormalize($data, $type, $format = NULL, array $context = []) { * The period. */ protected function setElementValue(array $element, ForecastPeriod $period): void { - switch ($element['@type']) { - case 'forecast_icon_code': - $period->setIconCode($element['#']); - break; - - case 'air_temperature_minimum': - $period->setAirTempMinimum((int) $element['#']); - break; - - case 'air_temperature_maximum': - $period->setAirTempMaximum((int) $element['#']); - break; - - case 'precipitation_range': - $period->setPrecipitationRange($element['#']); - break; - - } + $value = $this->accessWeatherData($element, '#'); + match ($element['@type']) { + 'forecast_icon_code' => $period->setIconCode($value), + 'air_temperature_minimum' => $period->setAirTempMinimum((int) $value), + 'air_temperature_maximum' => $period->setAirTempMaximum((int) $value), + 'precipitation_range' => $period->setPrecipitationRange($value), + default => '', + }; } /** @@ -86,40 +79,18 @@ protected function setElementValue(array $element, ForecastPeriod $period): void * The period. */ public function setTextValue(array $text, ForecastPeriod $period): void { - switch ($text['@type']) { - case 'precis': - $period->setPrecis($text['#']); - break; - - case 'probability_of_precipitation': - $period->setProbabilityOfPrecipitation($text['#']); - break; - - case 'forecast': - $period->setForecast($text['#']); - break; - - case 'uv_alert': - $period->setUvAlert($text['#']); - break; - - case 'forecast_seas': - $period->setSeas($text['#']); - break; - - case 'forecast_swell1': - $period->setSwell($text['#']); - break; - - case 'forecast_weather': - $period->setWeather($text['#']); - break; - - case 'forecast_winds': - $period->setWinds($text['#']); - break; - - } + $value = $this->accessWeatherData($text, '#'); + match ($text['@type']) { + 'precis' => $period->setPrecis($value), + 'probability_of_precipitation' => $period->setProbabilityOfPrecipitation($value), + 'forecast' => $period->setForecast($value), + 'uv_alert' => $period->setUvAlert($value), + 'forecast_seas' => $period->setSeas($value), + 'forecast_swell1' => $period->setSwell($value), + 'forecast_weather' => $period->setWeather($value), + 'forecast_winds' => $period->setWinds($value), + default => '', + }; } } diff --git a/src/Trait/WeatherDataAccessorTrait.php b/src/Trait/WeatherDataAccessorTrait.php new file mode 100644 index 0000000..9349d5d --- /dev/null +++ b/src/Trait/WeatherDataAccessorTrait.php @@ -0,0 +1,30 @@ +accessWeatherData($text, '#'); match ($text['@type']) { - 'warning_title' => $warningInfo->setWarningTitle($text['#']), - 'preamble' => $warningInfo->setPreamble($text['#']), + 'warning_title' => $warningInfo->setWarningTitle($value), + 'preamble' => $warningInfo->setPreamble($value), 'warning_advice' => \array_map(function ($advice) use ($warningInfo): void { $warningInfo->setWarningAdvice($advice); - }, $text['p']), - 'warning_next_issue' => $warningInfo->setWarningNextIssue($text['#']), + }, $this->accessWeatherData($text, 'p')), + 'warning_next_issue' => $warningInfo->setWarningNextIssue($value), default => '', }; } From 49a3a2a7d236263f562cdcaa0683c2e781805f3a Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Thu, 1 Feb 2024 21:30:59 +0530 Subject: [PATCH 07/11] Merging PR #13 into this branch. --- src/Forecast/ForecastPeriod.php | 20 +++++++++++++++++++ .../Serializer/ForecastPeriodNormalizer.php | 1 + 2 files changed, 21 insertions(+) diff --git a/src/Forecast/ForecastPeriod.php b/src/Forecast/ForecastPeriod.php index e2c063b..39b6c4d 100644 --- a/src/Forecast/ForecastPeriod.php +++ b/src/Forecast/ForecastPeriod.php @@ -84,6 +84,11 @@ final class ForecastPeriod { */ protected ?string $winds = NULL; + /** + * The fire danger value. + */ + protected ?string $fireDanger = NULL; + /** * Gets the start time. */ @@ -311,4 +316,19 @@ public function setWinds(string $winds): ForecastPeriod { return $this; } + /** + * Gets the fire danger value. + */ + public function getFireDanger(): ?string { + return $this->fireDanger; + } + + /** + * Sets the fire danger value. + */ + public function setFireDanger(?string $fireDanger): ForecastPeriod { + $this->fireDanger = $fireDanger; + return $this; + } + } diff --git a/src/Forecast/Serializer/ForecastPeriodNormalizer.php b/src/Forecast/Serializer/ForecastPeriodNormalizer.php index d6b8239..e0cb25d 100644 --- a/src/Forecast/Serializer/ForecastPeriodNormalizer.php +++ b/src/Forecast/Serializer/ForecastPeriodNormalizer.php @@ -89,6 +89,7 @@ public function setTextValue(array $text, ForecastPeriod $period): void { 'forecast_swell1' => $period->setSwell($value), 'forecast_weather' => $period->setWeather($value), 'forecast_winds' => $period->setWinds($value), + 'fire_danger' => $period->setFireDanger($text), default => '', }; } From 04249f73f00079507dddabe398155399dc20d0d1 Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Thu, 1 Feb 2024 21:32:24 +0530 Subject: [PATCH 08/11] Fixing typo. --- src/Forecast/Serializer/ForecastPeriodNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Forecast/Serializer/ForecastPeriodNormalizer.php b/src/Forecast/Serializer/ForecastPeriodNormalizer.php index e0cb25d..060ce18 100644 --- a/src/Forecast/Serializer/ForecastPeriodNormalizer.php +++ b/src/Forecast/Serializer/ForecastPeriodNormalizer.php @@ -89,7 +89,7 @@ public function setTextValue(array $text, ForecastPeriod $period): void { 'forecast_swell1' => $period->setSwell($value), 'forecast_weather' => $period->setWeather($value), 'forecast_winds' => $period->setWinds($value), - 'fire_danger' => $period->setFireDanger($text), + 'fire_danger' => $period->setFireDanger($value), default => '', }; } From e700c8652426b39728fdffb1edc2ed5b636073dc Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Fri, 9 Feb 2024 12:09:28 +0530 Subject: [PATCH 09/11] Checking the fallback values. Sometimes weather data have value under p tag. --- src/Warning/Serializer/WarningInfoNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Warning/Serializer/WarningInfoNormalizer.php b/src/Warning/Serializer/WarningInfoNormalizer.php index 5606faa..1ac771a 100644 --- a/src/Warning/Serializer/WarningInfoNormalizer.php +++ b/src/Warning/Serializer/WarningInfoNormalizer.php @@ -55,7 +55,7 @@ public function denormalize($data, $type, $format = NULL, array $context = []) { * The warning info. */ public function setTextValue(array $text, WarningInfo $warningInfo): void { - $value = $this->accessWeatherData($text, '#'); + $value = array_key_exists('#', $text) ? $this->accessWeatherData($text, '#') : $this->accessWeatherData($text, 'p'); match ($text['@type']) { 'warning_title' => $warningInfo->setWarningTitle($value), 'preamble' => $warningInfo->setPreamble($value), From 5ce5e517ba0fe3601c1b45ba9681bfc7e5321486 Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Fri, 9 Feb 2024 12:12:48 +0530 Subject: [PATCH 10/11] Linting fixes. --- src/Warning/Serializer/WarningInfoNormalizer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Warning/Serializer/WarningInfoNormalizer.php b/src/Warning/Serializer/WarningInfoNormalizer.php index 1ac771a..fe73980 100644 --- a/src/Warning/Serializer/WarningInfoNormalizer.php +++ b/src/Warning/Serializer/WarningInfoNormalizer.php @@ -55,7 +55,7 @@ public function denormalize($data, $type, $format = NULL, array $context = []) { * The warning info. */ public function setTextValue(array $text, WarningInfo $warningInfo): void { - $value = array_key_exists('#', $text) ? $this->accessWeatherData($text, '#') : $this->accessWeatherData($text, 'p'); + $value = \array_key_exists('#', $text) ? $this->accessWeatherData($text, '#') : $this->accessWeatherData($text, 'p'); match ($text['@type']) { 'warning_title' => $warningInfo->setWarningTitle($value), 'preamble' => $warningInfo->setPreamble($value), From a5baaf7344bf7edb886ff5370df17a5da7e03e50 Mon Sep 17 00:00:00 2001 From: Mohit Aghera Date: Fri, 23 Feb 2024 10:21:51 +0530 Subject: [PATCH 11/11] Handle the edge cases for fetching the warning advice data. --- src/Warning/Serializer/WarningInfoNormalizer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Warning/Serializer/WarningInfoNormalizer.php b/src/Warning/Serializer/WarningInfoNormalizer.php index fe73980..28f23d0 100644 --- a/src/Warning/Serializer/WarningInfoNormalizer.php +++ b/src/Warning/Serializer/WarningInfoNormalizer.php @@ -59,9 +59,9 @@ public function setTextValue(array $text, WarningInfo $warningInfo): void { match ($text['@type']) { 'warning_title' => $warningInfo->setWarningTitle($value), 'preamble' => $warningInfo->setPreamble($value), - 'warning_advice' => \array_map(function ($advice) use ($warningInfo): void { + 'warning_advice' => \is_array($value) ? \array_map(function ($advice) use ($warningInfo): void { $warningInfo->setWarningAdvice($advice); - }, $this->accessWeatherData($text, 'p')), + }, $value) : $warningInfo->setWarningAdvice($value), 'warning_next_issue' => $warningInfo->setWarningNextIssue($value), default => '', };