From 5e7bcb946af4fcff68cfb6621dbc78b7c840e259 Mon Sep 17 00:00:00 2001 From: Hoja Mustaffa Abdul Latheef Date: Fri, 6 Dec 2024 15:02:13 +0100 Subject: [PATCH] [TASK] Fixed php stan and CLI fixes --- .../Command/DeutscherWetterdienstCommand.php | 18 ++++++++++----- .../DeutscherWetterdienstWarnCellCommand.php | 15 ++++++++++--- Classes/Command/OpenWeatherMapCommand.php | 22 +------------------ ext_localconf.php | 5 ----- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/Classes/Command/DeutscherWetterdienstCommand.php b/Classes/Command/DeutscherWetterdienstCommand.php index 0659e54..3ed995e 100644 --- a/Classes/Command/DeutscherWetterdienstCommand.php +++ b/Classes/Command/DeutscherWetterdienstCommand.php @@ -158,7 +158,7 @@ protected function processDwdItems(array $category, bool $isPreliminaryInformati $recordStoragePid = (int)$input->getArgument('recordStoragePage'); foreach ($selectedWarnCells as $warnCellId) { $dwdWarnCells = $this->getDwdRecordsFindByName( - htmlspecialchars(strip_tags($warnCellId ?? '')), + htmlspecialchars(strip_tags($warnCellId)), ); $progressBar = new ProgressBar($output, count($dwdWarnCells)); $progressBar->start(); @@ -175,7 +175,7 @@ protected function processDwdItems(array $category, bool $isPreliminaryInformati $alert, $dwdWarnCell['uid'], $isPreliminaryInformation, - $recordStoragePid + $recordStoragePid, ); $this->insertRecord($row); $progressBar->advance(); @@ -188,6 +188,9 @@ protected function processDwdItems(array $category, bool $isPreliminaryInformati } } + /** + * @param array $row + */ private function insertRecord(array $row): void { $queryBuilder = $this->connectionPool->getQueryBuilderForTable('tx_weather2_domain_model_weatheralert'); @@ -251,12 +254,13 @@ protected function getBackendUserAuthentication(): BackendUserAuthentication * Returns filled WeatherAlert instance * * @param array $alert + * @return array */ protected function getWeatherAlertInstanceForAlert( array $alert, int $warnCellId, bool $isPreliminaryInformation, - int $recordStoragePid + int $recordStoragePid, ): array { $weatherAlert['pid'] = $recordStoragePid; $weatherAlert['dwd_warn_cell'] = $warnCellId; @@ -317,6 +321,10 @@ protected function removeOldAlertsFromDb(): void $queryBuilder->executeStatement(); } + /** + * @return array + * @throws Exception + */ protected function getDwdRecordsFindByName(string $name): array { $table = 'tx_weather2_domain_model_dwdwarncell'; @@ -330,8 +338,8 @@ protected function getDwdRecordsFindByName(string $name): array ->where( $queryBuilder->expr()->or( $queryBuilder->expr()->eq('name', $queryBuilder->createNamedParameter(trim($name))), - $queryBuilder->expr()->eq('warn_cell_id', $queryBuilder->createNamedParameter($name)) - ) + $queryBuilder->expr()->eq('warn_cell_id', $queryBuilder->createNamedParameter($name)), + ), ) ->orderBy('uid', 'ASC'); diff --git a/Classes/Command/DeutscherWetterdienstWarnCellCommand.php b/Classes/Command/DeutscherWetterdienstWarnCellCommand.php index 9ce9ef2..594203d 100644 --- a/Classes/Command/DeutscherWetterdienstWarnCellCommand.php +++ b/Classes/Command/DeutscherWetterdienstWarnCellCommand.php @@ -30,7 +30,7 @@ final class DeutscherWetterdienstWarnCellCommand extends Command public function __construct( protected readonly LoggerInterface $logger, protected readonly RequestFactory $requestFactory, - protected readonly ConnectionPool $connectionPool + protected readonly ConnectionPool $connectionPool, ) { parent::__construct(); } @@ -38,7 +38,7 @@ public function __construct( protected function configure(): void { $this->setHelp( - 'Calls the Deutscher Wetterdienst api and saves warn cells into database. Required before using DeutscherWetterdienstTask!' + 'Calls the Deutscher Wetterdienst api and saves warn cells into database. Required before using DeutscherWetterdienstTask!', ); } @@ -56,7 +56,7 @@ public function execute(InputInterface $input, OutputInterface $output): int } catch (\Throwable $e) { $this->logger->error( sprintf('Error while updating warn cells: %s', $e->getMessage()), - ['exception' => $e] + ['exception' => $e], ); $output->writeln($e->getMessage()); $output->writeln('An error occurred. Check the logs for details.'); @@ -82,6 +82,9 @@ protected function fetchWarnCellData(): ResponseInterface } } + /** + * @return array + */ private function parseResponse(ResponseInterface $response): array { $rawRows = explode(PHP_EOL, trim((string)$response->getBody())); @@ -108,6 +111,9 @@ private function parseResponse(ResponseInterface $response): array return $rows; } + /** + * @param array $rows + */ private function updateDatabase(array $rows, OutputInterface $output): void { $connection = $this->connectionPool->getConnectionForTable('tx_weather2_domain_model_dwdwarncell'); @@ -139,6 +145,9 @@ private function doesRecordExist(Connection $connection, string $warnCellId): bo return (int)$count > 0; } + /** + * @param array $row + */ private function insertRecord(Connection $connection, array $row): void { $connection->insert('tx_weather2_domain_model_dwdwarncell', [ diff --git a/Classes/Command/OpenWeatherMapCommand.php b/Classes/Command/OpenWeatherMapCommand.php index f8eefb6..b268ef3 100644 --- a/Classes/Command/OpenWeatherMapCommand.php +++ b/Classes/Command/OpenWeatherMapCommand.php @@ -18,7 +18,6 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use TYPO3\CMS\Core\Context\Context; use TYPO3\CMS\Core\Database\ConnectionPool; use TYPO3\CMS\Core\Http\RequestFactory; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -39,7 +38,7 @@ public function __construct( private readonly LoggerInterface $logger, private readonly RequestFactory $requestFactory, private readonly CacheService $cacheService, - private readonly ConnectionPool $connectionPool + private readonly ConnectionPool $connectionPool, ) { parent::__construct(); } @@ -122,18 +121,10 @@ private function checkResponseCode(ResponseInterface $response): bool { if ($response->getStatusCode() === 401) { $this->logger->error(WeatherUtility::translate('message.api_response_401', 'openweatherapi')); - $this->sendMail( - 'Error while requesting weather data', - WeatherUtility::translate('message.api_response_401', 'openweatherapi'), - ); return false; } if ($response->getStatusCode() !== 200) { $this->logger->error(WeatherUtility::translate('message.api_response_null', 'openweatherapi')); - $this->sendMail( - 'Error while requesting weather data', - WeatherUtility::translate('message.api_response_null', 'openweatherapi'), - ); return false; } @@ -145,10 +136,6 @@ private function checkResponseCode(ResponseInterface $response): bool return true; case '404': $this->logger->error(WeatherUtility::translate('messages.api_code_404', 'openweatherapi')); - $this->sendMail( - 'Error while requesting weather data', - WeatherUtility::translate('messages.api_code_404', 'openweatherapi'), - ); return false; default: $this->logger->error( @@ -157,13 +144,6 @@ private function checkResponseCode(ResponseInterface $response): bool (string)$response->getBody(), ), ); - $this->sendMail( - 'Error while requesting weather data', - sprintf( - WeatherUtility::translate('messages.api_code_none', 'openweatherapi'), - (string)$response->getBody() - ), - ); return false; } } diff --git a/ext_localconf.php b/ext_localconf.php index 2553b5b..f930b45 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -6,11 +6,6 @@ use JWeiland\Weather2\Controller\CurrentWeatherController; use JWeiland\Weather2\Controller\WeatherAlertController; -use JWeiland\Weather2\Task\DeutscherWetterdienstTask; -use JWeiland\Weather2\Task\DeutscherWetterdienstTaskAdditionalFieldProvider; -use JWeiland\Weather2\Task\DeutscherWetterdienstWarnCellTask; -use JWeiland\Weather2\Task\OpenWeatherMapTask; -use JWeiland\Weather2\Task\OpenWeatherMapTaskAdditionalFieldProvider; use TYPO3\CMS\Extbase\Utility\ExtensionUtility; call_user_func(static function () {