diff --git a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php index f81a3e9dcc294e9fd24b4f26ad2d7f18d3dbcb1a..241aee91fef3f89e169fcd1b56b4ffa0a7847be6 100644 --- a/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php +++ b/typo3/sysext/indexed_search/Classes/Domain/Repository/IndexSearchRepository.php @@ -612,11 +612,9 @@ class IndexSearchRepository * Search for a word * * @param string $sWord the search word - * @param int $wildcard Bit-field of Utility\LikeWildcard */ - protected function searchWord(string $sWord, int $wildcard): Result + protected function searchWord(string $sWord, LikeWildcard $likeWildcard): Result { - $likeWildcard = LikeWildcard::cast($wildcard); $wSel = $likeWildcard->getLikeQueryPart( 'index_words', 'IW.baseword', @@ -649,7 +647,7 @@ class IndexSearchRepository protected function searchSentence(string $sWord): Result { $this->wSelClauses[] = '1=1'; - $likeWildcard = LikeWildcard::cast(LikeWildcard::BOTH); + $likeWildcard = LikeWildcard::BOTH; $likePart = $likeWildcard->getLikeQueryPart( 'index_fulltext', 'IFT.fulltextdata', diff --git a/typo3/sysext/indexed_search/Classes/Utility/LikeWildcard.php b/typo3/sysext/indexed_search/Classes/Utility/LikeWildcard.php index 84d5249dd0791da81f58ee47d96f964337ca8b16..34f186d15cbbcf32d9aa448e2fa9cece3a299cc4 100644 --- a/typo3/sysext/indexed_search/Classes/Utility/LikeWildcard.php +++ b/typo3/sysext/indexed_search/Classes/Utility/LikeWildcard.php @@ -1,5 +1,7 @@ <?php +declare(strict_types=1); + /* * This file is part of the TYPO3 CMS project. * @@ -16,28 +18,25 @@ namespace TYPO3\CMS\IndexedSearch\Utility; use TYPO3\CMS\Core\Database\ConnectionPool; -use TYPO3\CMS\Core\Type\Enumeration; use TYPO3\CMS\Core\Utility\GeneralUtility; /** * Enumeration object for LikeWildcard * @internal */ -final class LikeWildcard extends Enumeration +enum LikeWildcard: int { - public const __default = self::BOTH; - - /** @var int Do not use any wildcard */ - public const NONE = 0; + /** Do not use any wildcard */ + case NONE = 0; - /** @var int Use wildcard on left side */ - public const LEFT = 1; + /** Use wildcard on left side */ + case LEFT = 1; - /** @var int Use wildcard on right side */ - public const RIGHT = 2; + /** Use wildcard on right side */ + case RIGHT = 2; - /** @var int Use wildcard on both sides */ - public const BOTH = 3; + /** Use wildcard on both sides */ + case BOTH = 3; /** * Returns a LIKE clause for sql queries. @@ -47,14 +46,14 @@ final class LikeWildcard extends Enumeration * @param string $likeValue The value for the LIKE clause operation. * @return string */ - public function getLikeQueryPart($tableName, $fieldName, $likeValue) + public function getLikeQueryPart(string $tableName, string $fieldName, string $likeValue): string { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable($tableName); - $string = ($this->value & self::LEFT ? '%' : '') + $string = ($this->value & self::LEFT->value ? '%' : '') . $queryBuilder->escapeLikeWildcards($likeValue) - . ($this->value & self::RIGHT ? '%' : ''); + . ($this->value & self::RIGHT->value ? '%' : ''); return $queryBuilder->expr()->like($fieldName, $queryBuilder->quote($string)); } diff --git a/typo3/sysext/indexed_search/Tests/Functional/Utility/LikeWildcardTest.php b/typo3/sysext/indexed_search/Tests/Functional/Utility/LikeWildcardTest.php index 3ef9ed7cd18f4b7ffc8ad6e5e8e398b38853f963..15f1b9ac03f124c06f9b589b55659d0d192d82b0 100644 --- a/typo3/sysext/indexed_search/Tests/Functional/Utility/LikeWildcardTest.php +++ b/typo3/sysext/indexed_search/Tests/Functional/Utility/LikeWildcardTest.php @@ -24,19 +24,15 @@ use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\IndexedSearch\Utility\LikeWildcard; use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; -/** - * This class contains unit tests for the LikeQueryUtility - */ class LikeWildcardTest extends FunctionalTestCase { /** * @test * @dataProvider getLikeQueryPartDataProvider */ - public function getLikeQueryPart(string $tableName, string $fieldName, string $likeValue, int $wildcard, string $expected): void + public function getLikeQueryPart(string $tableName, string $fieldName, string $likeValue, LikeWildcard $subject, string $expected): void { $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName); - $subject = LikeWildcard::cast($wildcard); if ($connection->getDatabasePlatform() instanceof PostgreSQLPlatform) { $expected = str_replace('LIKE', 'ILIKE', $expected); }