From 57a56d2ca7f142f97920bca06fa1a3d49b7065da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Fri, 27 May 2022 12:17:41 +0200 Subject: [PATCH] Add return types, cleanup code --- .../Classes/Command/DateCommandController.php | 4 ++-- .../Classes/Controller/ProductController.php | 8 ++++---- .../Classes/Service/ProductDataService.php | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/public/typo3conf/ext/ep_products/Classes/Command/DateCommandController.php b/public/typo3conf/ext/ep_products/Classes/Command/DateCommandController.php index 8d48136f..15271e8a 100644 --- a/public/typo3conf/ext/ep_products/Classes/Command/DateCommandController.php +++ b/public/typo3conf/ext/ep_products/Classes/Command/DateCommandController.php @@ -77,7 +77,7 @@ class DateCommandController extends Command * @param OutputInterface $output * @throws \Doctrine\DBAL\DBALException */ - public function execute(InputInterface $input, OutputInterface $output) + public function execute(InputInterface $input, OutputInterface $output): int { $path = GeneralUtility::getFileAbsFileName('fileadmin/xmlexport'); $count = $this->dateImportService->import($path); @@ -92,7 +92,7 @@ class DateCommandController extends Command /** * @return array */ - protected function getSettings() + protected function getSettings(): array { $settings = $this ->configurationManager diff --git a/public/typo3conf/ext/ep_products/Classes/Controller/ProductController.php b/public/typo3conf/ext/ep_products/Classes/Controller/ProductController.php index 492ddd55..bc7f055a 100644 --- a/public/typo3conf/ext/ep_products/Classes/Controller/ProductController.php +++ b/public/typo3conf/ext/ep_products/Classes/Controller/ProductController.php @@ -116,7 +116,7 @@ class ProductController extends ActionController Hotel $hotel = null, $dateFrom = null, $dateTo = null - ) { + ): void { // Get product to display from flexform settings if not provided via url if ($product === null) { $productUid = $this->settings['productUid']; @@ -186,7 +186,7 @@ class ProductController extends ActionController ]); } - public function pricetableAction() + public function pricetableAction(): void { $productUid = $this->settings['productUid']; /** @var \EP\EpProducts\Domain\Model\Product $product */ @@ -205,7 +205,7 @@ class ProductController extends ActionController /** * @param Product $product */ - public function hotelListAction(Product $product) + public function hotelListAction(Product $product): void { $hotels = $this->hotelDataService->getList($product); $this->view->assignMultiple([ @@ -215,7 +215,7 @@ class ProductController extends ActionController ]); } - public function teasergroupAction() + public function teasergroupAction(): void { $filterSettings = $this->filterService->getFiltersettingsFromSettings($this->settings); $dateAuto = !$this->settings['dateFrom'] && !$this->settings['dateTo']; diff --git a/public/typo3conf/ext/ep_products/Classes/Service/ProductDataService.php b/public/typo3conf/ext/ep_products/Classes/Service/ProductDataService.php index 232d6d36..cf400d75 100644 --- a/public/typo3conf/ext/ep_products/Classes/Service/ProductDataService.php +++ b/public/typo3conf/ext/ep_products/Classes/Service/ProductDataService.php @@ -65,8 +65,7 @@ class ProductDataService implements SingletonInterface HotelRepository $hotelRepository, HotelImageService $hotelImageService, ProductImageService $productImageService - ) - { + ) { $this->productRepository = $productRepository; $this->hotelRepository = $hotelRepository; $this->productImageService = $productImageService; @@ -78,10 +77,11 @@ class ProductDataService implements SingletonInterface * * @return array */ - public function getTeaser(array $filterSettings) + public function getTeaser(array $filterSettings): array { $teaserData = $this->productRepository->getTeasers($filterSettings); $teasers = $this->preprocessTeasergroup($teaserData); + return reset($teasers); } @@ -92,9 +92,10 @@ class ProductDataService implements SingletonInterface * * @return array */ - public function getTeasergroup(array $filterSettings, $excludedConceptUids = [], $limit = 0) + public function getTeasergroup(array $filterSettings, array $excludedConceptUids = [], int $limit = 0): array { $teaserData = $this->productRepository->getTeasers($filterSettings, $excludedConceptUids); + return $this->preprocessTeasergroup($teaserData, $limit); } @@ -104,12 +105,11 @@ class ProductDataService implements SingletonInterface * * @return array */ - public function preprocessTeasergroup(array $teaserData, $limit = 0) + public function preprocessTeasergroup(array $teaserData, int $limit = 0): array { $data = []; - foreach ($teaserData as $row) - { + foreach ($teaserData as $row) { if (!array_key_exists($row['productUid'], $data)) { $data[$row['productUid']] = $this->createTeaserData($row); } @@ -166,7 +166,7 @@ class ProductDataService implements SingletonInterface * * @return array */ - public function createTeaserData(array $teaserData) + public function createTeaserData(array $teaserData): array { $hotelCategory = Hotel::$categoryLabels[$teaserData['hotelCategory']] ?? null;