From e0e42172c9fcce4b9e12dea435050c0006629356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Thu, 3 Aug 2023 11:35:46 +0200 Subject: [PATCH] Task: Simplify code --- .../Classes/Service/GroupsSwissService.php | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php b/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php index 9938db69..38257dbc 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/GroupsSwissService.php @@ -162,7 +162,7 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface return Contingent::STATUS_BLOCKED; } - if ($percentageAvailable > 20 && $percentageAvailable <= 80) { + if ($percentageAvailable <= 80) { return $contingent::STATUS_ONREQUEST; } @@ -177,25 +177,31 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface */ protected function addItem(array $item, $status, $apiKey, $houseNumber): void { + $from = $item['from']->format('Y-m-d'); + $to = $item['to']->format('Y-m-d'); + $this->logger->info(sprintf( 'Adding status %d in %s-%s for %s', $status, - $item['from']->format('Y-m-d'), - $item['to']->format('Y-m-d'), + $from, + $to, $houseNumber )); - $url = sprintf( - 'https://www.groups.swiss/api/1.0/json.php?apiKey=%s&method=setAvailabilityChart&house=%d&from=%s&till=%s&state=%d', - $apiKey, - $houseNumber, - $item['from']->format('Y-m-d'), - $item['to']->format('Y-m-d'), - $status - ); - try { - $response = $this->httpClient->request('GET', $url); + $response = $this + ->httpClient + ->request('GET', 'https://www.groups.swiss/api/1.0/json.php', [ + 'query' => [ + 'apiKey' => $apiKey, + 'method' => 'setAvailabilityChart', + 'house' => $houseNumber, + 'from' => $from, + 'till' => $to, + 'state' => $status, + ], + ]) + ; $this->logger->info($response->getContent()); } catch (TransportExceptionInterface $e) { $this->logger->error(sprintf('A problem occured: %s', $e->getMessage()));