diff options
Diffstat (limited to 'apps/weather_status/lib')
6 files changed, 41 insertions, 140 deletions
diff --git a/apps/weather_status/lib/AppInfo/Application.php b/apps/weather_status/lib/AppInfo/Application.php index 19cfd643a7e..147d69ee543 100644 --- a/apps/weather_status/lib/AppInfo/Application.php +++ b/apps/weather_status/lib/AppInfo/Application.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2020, Julien Veyssier - * - * @author Julien Veyssier <eneiluj@posteo.net> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WeatherStatus\AppInfo; diff --git a/apps/weather_status/lib/Capabilities.php b/apps/weather_status/lib/Capabilities.php index af1e92b83b3..953b40036f3 100644 --- a/apps/weather_status/lib/Capabilities.php +++ b/apps/weather_status/lib/Capabilities.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2020, Julien Veyssier - * - * @author Julien Veyssier <eneiluj@posteo.net> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WeatherStatus; diff --git a/apps/weather_status/lib/Controller/WeatherStatusController.php b/apps/weather_status/lib/Controller/WeatherStatusController.php index da82bb4f03f..c56ea3b97b3 100644 --- a/apps/weather_status/lib/Controller/WeatherStatusController.php +++ b/apps/weather_status/lib/Controller/WeatherStatusController.php @@ -3,31 +3,15 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2020, Julien Veyssier - * - * @author Julien Veyssier <eneiluj@posteo.net> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WeatherStatus\Controller; use OCA\WeatherStatus\ResponseDefinitions; use OCA\WeatherStatus\Service\WeatherStatusService; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\Attribute\NoAdminRequired; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\IRequest; @@ -50,21 +34,18 @@ class WeatherStatusController extends OCSController { } /** - * @NoAdminRequired - * * Try to use the address set in user personal settings as weather location * * @return DataResponse<Http::STATUS_OK, WeatherStatusLocationWithSuccess, array{}> * * 200: Address updated */ + #[NoAdminRequired] public function usePersonalAddress(): DataResponse { return new DataResponse($this->service->usePersonalAddress()); } /** - * @NoAdminRequired - * * Change the weather status mode. There are currently 2 modes: * - ask the browser * - use the user defined address @@ -74,13 +55,12 @@ class WeatherStatusController extends OCSController { * * 200: Weather status mode updated */ + #[NoAdminRequired] public function setMode(int $mode): DataResponse { return new DataResponse($this->service->setMode($mode)); } /** - * @NoAdminRequired - * * Set address and resolve it to get coordinates * or directly set coordinates and get address with reverse geocoding * @@ -91,35 +71,34 @@ class WeatherStatusController extends OCSController { * * 200: Location updated */ + #[NoAdminRequired] public function setLocation(?string $address, ?float $lat, ?float $lon): DataResponse { $currentWeather = $this->service->setLocation($address, $lat, $lon); return new DataResponse($currentWeather); } /** - * @NoAdminRequired - * * Get stored user location * * @return DataResponse<Http::STATUS_OK, WeatherStatusLocationWithMode, array{}> * * 200: Location returned */ + #[NoAdminRequired] public function getLocation(): DataResponse { $location = $this->service->getLocation(); return new DataResponse($location); } /** - * @NoAdminRequired - * * Get forecast for current location * - * @return DataResponse<Http::STATUS_OK, WeatherStatusForecast[]|array{error: string}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, WeatherStatusSuccess, array{}> + * @return DataResponse<Http::STATUS_OK, list<WeatherStatusForecast>|array{error: string}, array{}>|DataResponse<Http::STATUS_NOT_FOUND, WeatherStatusSuccess, array{}> * * 200: Forecast returned * 404: Forecast not found */ + #[NoAdminRequired] public function getForecast(): DataResponse { $forecast = $this->service->getForecast(); if (isset($forecast['success']) && $forecast['success'] === false) { @@ -130,28 +109,26 @@ class WeatherStatusController extends OCSController { } /** - * @NoAdminRequired - * * Get favorites list * - * @return DataResponse<Http::STATUS_OK, string[], array{}> + * @return DataResponse<Http::STATUS_OK, list<string>, array{}> * * 200: Favorites returned */ + #[NoAdminRequired] public function getFavorites(): DataResponse { return new DataResponse($this->service->getFavorites()); } /** - * @NoAdminRequired - * * Set favorites list * - * @param string[] $favorites Favorite addresses + * @param list<string> $favorites Favorite addresses * @return DataResponse<Http::STATUS_OK, WeatherStatusSuccess, array{}> * * 200: Favorites updated */ + #[NoAdminRequired] public function setFavorites(array $favorites): DataResponse { return new DataResponse($this->service->setFavorites($favorites)); } diff --git a/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php b/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php index 5b08661337b..5d3b76626b6 100644 --- a/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php +++ b/apps/weather_status/lib/Listeners/BeforeTemplateRenderedListener.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de> - * - * @author Ferdinand Thiessen <opensource@fthiessen.de> - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WeatherStatus\Listeners; diff --git a/apps/weather_status/lib/ResponseDefinitions.php b/apps/weather_status/lib/ResponseDefinitions.php index d69afbbb3c2..17d7cebf76e 100644 --- a/apps/weather_status/lib/ResponseDefinitions.php +++ b/apps/weather_status/lib/ResponseDefinitions.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2023 Kate Döen <kate.doeen@nextcloud.com> - * - * @author Kate Döen <kate.doeen@nextcloud.com> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WeatherStatus; diff --git a/apps/weather_status/lib/Service/WeatherStatusService.php b/apps/weather_status/lib/Service/WeatherStatusService.php index ed416d09a87..c93010e7f58 100644 --- a/apps/weather_status/lib/Service/WeatherStatusService.php +++ b/apps/weather_status/lib/Service/WeatherStatusService.php @@ -3,26 +3,8 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2020, Julien Veyssier - * - * @author Julien Veyssier <eneiluj@posteo.net> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * - * @license AGPL-3.0-or-later - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\WeatherStatus\Service; @@ -67,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(); @@ -88,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', ''); @@ -97,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 { @@ -139,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); @@ -275,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.')]; } @@ -302,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', ''); @@ -325,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 = [ |