From 7ef13f8e4e4a0a573944fd0f632276cde69c8d22 Mon Sep 17 00:00:00 2001 From: Ingo Pfennigstorf Date: Mon, 11 Mar 2024 13:29:10 +0100 Subject: [PATCH] Use style linter with PHP 8.1 --- .github/workflows/ci.yml | 14 ++-- Classes/Controller/SearchController.php | 68 +++++++++---------- .../Find/PathExistsViewHelperTest.php | 4 +- 3 files changed, 40 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27447c29..58e064cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,34 +19,30 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.env.php }} - tools: composer + tools: composer:2 extensions: pdo, sqlite3 - # composer - - name: Update Composer - run: | - sudo composer self-update - composer --version - name: Validate composer.json and composer.lock run: composer validate - name: Cache dependencies - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ~/.composer/cache - key: dependencies-composer-${{ hashFiles('composer.json') }} + key: dependencies-composer-${{ matrix.env.php }}-${{ hashFiles('composer.json') }} - name: Install dependencies run: composer install - name: Check coding style run: composer lint + if: ${{ matrix.env.php == '8.1' }} - name: Run Unit Tests run: | diff --git a/Classes/Controller/SearchController.php b/Classes/Controller/SearchController.php index b0f879eb..80d303ee 100644 --- a/Classes/Controller/SearchController.php +++ b/Classes/Controller/SearchController.php @@ -43,8 +43,6 @@ class SearchController extends ActionController { - public $response; - protected array $requestArguments = []; protected ?object $searchProvider = null; @@ -64,17 +62,15 @@ public function detailAction(string $id): ResponseInterface { $arguments = $this->searchProvider->getRequestArguments(); $detail = $this->searchProvider->getDocumentById($id); - + $response = $this->responseFactory->createResponse(); if ($this->request->hasArgument('underlyingQuery')) { $underlyingQueryInfo = $this->request->getArgument('underlyingQuery'); - $this->response->addAdditionalHeaderData( - FrontendUtility::addQueryInformationAsJavaScript( - $underlyingQueryInfo['q'], - $this->settings, - (int) $underlyingQueryInfo['position'], - $arguments - ) - ); + $response->withAddedHeader('detail', FrontendUtility::addQueryInformationAsJavaScript( + $underlyingQueryInfo['q'], + $this->settings, + (int) $underlyingQueryInfo['position'], + $arguments + )); } $this->addStandardAssignments(); @@ -95,36 +91,38 @@ public function indexAction(): ResponseInterface { if (array_key_exists('id', $this->requestArguments)) { return new ForwardResponse('detail'); - } else { - $this->searchProvider->setCounter(); - $this->response->addAdditionalHeaderData( - FrontendUtility::addQueryInformationAsJavaScript( - $this->searchProvider->getRequestArguments()['q'], - $this->settings, - null, - $this->searchProvider->getRequestArguments() - ) - ); - - $this->addStandardAssignments(); - $defaultQuery = $this->searchProvider->getDefaultQuery(); - - $viewValues = [ - 'arguments' => $this->searchProvider->getRequestArguments(), - 'config' => $this->searchProvider->getConfiguration(), - ]; - - CoreArrayUtility::mergeRecursiveWithOverrule($viewValues, $defaultQuery); - $this->view->assignMultiple($viewValues); } + $this->searchProvider->setCounter(); + $response = $this->responseFactory->createResponse(); + + $response->withAddedHeader('index', + FrontendUtility::addQueryInformationAsJavaScript( + $this->searchProvider->getRequestArguments()['q'], + $this->settings, + null, + $this->searchProvider->getRequestArguments() + ) + ); + + $this->addStandardAssignments(); + $defaultQuery = $this->searchProvider->getDefaultQuery(); + + $viewValues = [ + 'arguments' => $this->searchProvider->getRequestArguments(), + 'config' => $this->searchProvider->getConfiguration(), + ]; + + CoreArrayUtility::mergeRecursiveWithOverrule($viewValues, $defaultQuery); + $this->view->assignMultiple($viewValues); + return $this->htmlResponse(); } /** * Initialisation and setup. */ - protected function initializeAction() + protected function initializeAction(): void { ksort($this->settings['queryFields']); @@ -152,7 +150,7 @@ public function suggestAction(): ResponseInterface /** * Assigns standard variables to the view. */ - protected function addStandardAssignments() + protected function addStandardAssignments(): void { $this->searchProvider->setConfigurationValue('extendedSearch', $this->searchProvider->isExtendedSearch()); $this->searchProvider->setConfigurationValue( @@ -166,7 +164,7 @@ protected function addStandardAssignments() /** * @param string $activeConnection */ - protected function initializeConnection($activeConnection) + protected function initializeConnection($activeConnection): void { $connectionConfiguration = $this->settings['connections'][$activeConnection]; diff --git a/Tests/Unit/ViewHelpers/Find/PathExistsViewHelperTest.php b/Tests/Unit/ViewHelpers/Find/PathExistsViewHelperTest.php index 00d1b292..c075b691 100644 --- a/Tests/Unit/ViewHelpers/Find/PathExistsViewHelperTest.php +++ b/Tests/Unit/ViewHelpers/Find/PathExistsViewHelperTest.php @@ -49,7 +49,7 @@ protected function setUp(): void /** * @test */ - public function returnFalseIfAPathDoesNotExist() + public function returnFalseIfAPathDoesNotExist(): void { $this->fixture->setArguments( [ @@ -63,7 +63,7 @@ public function returnFalseIfAPathDoesNotExist() /** * @test */ - public function returnTrueIfAPathExists() + public function returnTrueIfAPathExists(): void { $this->fixture->setArguments( [