From 006ca4b05e9bf9d96861d079dfea381e687ac60e Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Fri, 22 Jul 2022 12:50:20 -0500 Subject: [PATCH] [TASK] Remove unnecessary conditionals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PHPStan says all of these are unnecessary. On visual inspection, it appears to be correct. Used command: > ./Build/Scripts/runTests.sh -s phpstanGenerateBaseline Resolves: #98001 Releases: main, 11.5 Change-Id: Ic18ce25997357c786b17bc5be02cfdb3617c6eef Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75286 Tested-by: core-ci Tested-by: Stefan Bürk Reviewed-by: Stefan Bürk --- Build/phpstan/phpstan-baseline.neon | 17 +------- .../Controller/File/FileController.php | 10 ++--- .../Repository/IndexSearchRepository.php | 42 +++++++++---------- .../QueryRestrictions/EditableRestriction.php | 4 +- 4 files changed, 25 insertions(+), 48 deletions(-) diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/phpstan-baseline.neon index e2a2293211dd..d492c7eb4ce1 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/phpstan-baseline.neon @@ -40,11 +40,6 @@ parameters: count: 1 path: ../../typo3/sysext/backend/Classes/Controller/EditDocumentController.php - - - message: "#^If condition is always true\\.$#" - count: 1 - path: ../../typo3/sysext/backend/Classes/Controller/File/FileController.php - - message: "#^Parameter \\#1 \\.\\.\\.\\$expressions of method TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\Expression\\\\ExpressionBuilder\\:\\:orX\\(\\) expects string, TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\Expression\\\\CompositeExpression given\\.$#" count: 1 @@ -4685,11 +4680,6 @@ parameters: count: 1 path: ../../typo3/sysext/indexed_search/Classes/Domain/Repository/AdministrationRepository.php - - - message: "#^If condition is always true\\.$#" - count: 1 - path: ../../typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php - - message: "#^Else branch is unreachable because previous condition is always true\\.$#" count: 2 @@ -4925,14 +4915,9 @@ parameters: count: 2 path: ../../typo3/sysext/linkvalidator/Classes/LinkAnalyzer.php - - - message: "#^If condition is always true\\.$#" - count: 1 - path: ../../typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php - - message: "#^Parameter \\#1 \\.\\.\\.\\$expressions of method TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\Expression\\\\ExpressionBuilder\\:\\:orX\\(\\) expects string, TYPO3\\\\CMS\\\\Core\\\\Database\\\\Query\\\\Expression\\\\CompositeExpression given\\.$#" - count: 4 + count: 3 path: ../../typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php - diff --git a/typo3/sysext/backend/Classes/Controller/File/FileController.php b/typo3/sysext/backend/Classes/Controller/File/FileController.php index b9df7c3e45db..be3db3ee5ebb 100644 --- a/typo3/sysext/backend/Classes/Controller/File/FileController.php +++ b/typo3/sysext/backend/Classes/Controller/File/FileController.php @@ -294,13 +294,9 @@ protected function getFileEditRedirect(File $file): ?string protected function flattenFileResultDataValue(File $result): array { - $thumbUrl = ''; - if ($result->isImage()) { - $processedFile = $result->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, []); - if ($processedFile) { - $thumbUrl = $processedFile->getPublicUrl() ?? ''; - } - } + $thumbUrl = $result->isImage() + ? ($result->process(ProcessedFile::CONTEXT_IMAGEPREVIEW, [])->getPublicUrl() ?? '') + : ''; $path = ''; if (is_callable([$result->getParentFolder(), 'getReadablePath'])) { $path = $result->getParentFolder()->getReadablePath(); diff --git a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php index 47d8bfa3417f..c911d98de0a2 100644 --- a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php +++ b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php @@ -623,29 +623,27 @@ protected function getPhashList($searchWords) $res = $this->searchDistinct($sWord); } // If there was a query to do, then select all phash-integers which resulted from this. - if ($res) { - // Get phash list by searching for it: - $phashList = []; - while ($row = $res->fetchAssociative()) { - $phashList[] = $row['phash']; - } - // Here the phash list are merged with the existing result based on whether we are dealing with OR, NOT or AND operations. - if ($c) { - switch ($v['oper']) { - case 'OR': - $totalHashList = array_unique(array_merge($phashList, $totalHashList)); - break; - case 'AND NOT': - $totalHashList = array_diff($totalHashList, $phashList); - break; - default: - // AND... - $totalHashList = array_intersect($totalHashList, $phashList); - } - } else { - // First search - $totalHashList = $phashList; + // Get phash list by searching for it: + $phashList = []; + while ($row = $res->fetchAssociative()) { + $phashList[] = $row['phash']; + } + // Here the phash list are merged with the existing result based on whether we are dealing with OR, NOT or AND operations. + if ($c) { + switch ($v['oper']) { + case 'OR': + $totalHashList = array_unique(array_merge($phashList, $totalHashList)); + break; + case 'AND NOT': + $totalHashList = array_diff($totalHashList, $phashList); + break; + default: + // AND... + $totalHashList = array_intersect($totalHashList, $phashList); } + } else { + // First search + $totalHashList = $phashList; } $this->getTimeTracker()->pull(); $c++; diff --git a/typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php b/typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php index 96ad9840d409..c141908f26fb 100644 --- a/typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php +++ b/typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php @@ -229,9 +229,7 @@ public function buildExpression(array $queriedTables, ExpressionBuilder $express 'tx_linkvalidator_link.table_name', $this->queryBuilder->quote($table) ); - if ($additionalWhere) { - $constraints[] = $expressionBuilder->orX(...$additionalWhere); - } + $constraints[] = $expressionBuilder->or(...$additionalWhere); } if ($this->allowedLanguages) {