aboutsummaryrefslogtreecommitdiffstats
path: root/apps/weather_status/lib/Service/WeatherStatusService.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/weather_status/lib/Service/WeatherStatusService.php')
-rw-r--r--apps/weather_status/lib/Service/WeatherStatusService.php26
1 files changed, 18 insertions, 8 deletions
diff --git a/apps/weather_status/lib/Service/WeatherStatusService.php b/apps/weather_status/lib/Service/WeatherStatusService.php
index da0ee855e85..c93010e7f58 100644
--- a/apps/weather_status/lib/Service/WeatherStatusService.php
+++ b/apps/weather_status/lib/Service/WeatherStatusService.php
@@ -49,7 +49,7 @@ class WeatherStatusService {
private IUserManager $userManager,
private IAppManager $appManager,
private ICacheFactory $cacheFactory,
- private ?string $userId
+ private ?string $userId,
) {
$this->version = $appManager->getAppVersion(Application::APP_ID);
$this->client = $clientService->newClient();
@@ -70,7 +70,7 @@ class WeatherStatusService {
/**
* Get favorites list
- * @return string[]
+ * @return list<string>
*/
public function getFavorites(): array {
$favoritesJson = $this->config->getUserValue($this->userId, Application::APP_ID, 'favorites', '');
@@ -79,7 +79,7 @@ class WeatherStatusService {
/**
* Set favorites list
- * @param string[] $favorites
+ * @param list<string> $favorites
* @return WeatherStatusSuccess success state
*/
public function setFavorites(array $favorites): array {
@@ -121,7 +121,7 @@ class WeatherStatusService {
$this->config->setUserValue($this->userId, Application::APP_ID, 'lon', strval($lon));
// resolve and store formatted address
$address = $this->resolveLocation($lat, $lon);
- $address = $address ? $address : $this->l10n->t('Unknown address');
+ $address = $address ?: $this->l10n->t('Unknown address');
$this->config->setUserValue($this->userId, Application::APP_ID, 'address', $address);
// get and store altitude
$altitude = $this->getAltitude($lat, $lon);
@@ -257,9 +257,19 @@ class WeatherStatusService {
];
$url = 'https://nominatim.openstreetmap.org/search';
$results = $this->requestJSON($url, $params);
- if (count($results) > 0) {
- return $results[0];
+
+ if (isset($results['error'])) {
+ return ['error' => (string)$results['error']];
+ }
+
+ if (count($results) > 0 && is_array($results[0])) {
+ return [
+ 'display_name' => (string)($results[0]['display_name'] ?? null),
+ 'lat' => (string)($results[0]['lat'] ?? null),
+ 'lon' => (string)($results[0]['lon'] ?? null),
+ ];
}
+
return ['error' => $this->l10n->t('No result.')];
}
@@ -284,7 +294,7 @@ class WeatherStatusService {
/**
* Get forecast for current location
*
- * @return WeatherStatusForecast[]|array{error: string}|WeatherStatusSuccess which contains success state and filtered forecast data
+ * @return list<WeatherStatusForecast>|array{error: string}|WeatherStatusSuccess which contains success state and filtered forecast data
*/
public function getForecast(): array {
$lat = $this->config->getUserValue($this->userId, Application::APP_ID, 'lat', '');
@@ -307,7 +317,7 @@ class WeatherStatusService {
* @param float $lon Longitude of requested forecast, in decimal degree format
* @param float $altitude Altitude of requested forecast, in meter
* @param int $nbValues Number of forecast values (hours)
- * @return WeatherStatusForecast[]|array{error: string} Filtered forecast data
+ * @return list<WeatherStatusForecast>|array{error: string} Filtered forecast data
*/
private function forecastRequest(float $lat, float $lon, float $altitude, int $nbValues = 10): array {
$params = [