From 1be8a9a4bfda7198a64b56f2db63aba16ed992e1 Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Mon, 6 Jan 2025 15:17:43 +0100 Subject: [PATCH] fix phpstan issues --- src/Modifier/TermModifier.php | 25 +++++++++++++------------ src/Provider/LuceneIndexProvider.php | 4 ++-- src/Service/LuceneStorageBuilder.php | 4 ---- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Modifier/TermModifier.php b/src/Modifier/TermModifier.php index 68aa0d6..33247e1 100644 --- a/src/Modifier/TermModifier.php +++ b/src/Modifier/TermModifier.php @@ -14,31 +14,32 @@ class TermModifier */ public function splitTerm(string $query, int $minPrefixLength = 3, int $maxTerms = 0): array { - $terms = array_values(array_filter(explode(' ', $query), function ($t) use ($minPrefixLength) { + $cleanTermBlocks = []; + + $terms = array_values(array_filter(explode(' ', $query), static function ($t) use ($minPrefixLength) { return strlen($t) >= $minPrefixLength; })); - $cleanTerms = []; - foreach ($terms as $term) { preg_match_all('/[\p{L}\p{N}]+/u', $term, $match, PREG_OFFSET_CAPTURE); - if (!is_array($match[0])) { - $cleanTerms[] = $term; - - continue; - } - $specialTerms = []; foreach ($match[0] as $matchTerm) { $specialTerms[] = $matchTerm[0]; } - $cleanTerms = array_merge($cleanTerms, array_values(array_filter($specialTerms, function ($t) use ($minPrefixLength) { - return strlen($t) >= $minPrefixLength; - }))); + $cleanTermBlocks[] = array_values( + array_filter( + $specialTerms, + static function ($t) use ($minPrefixLength) { + return strlen($t) >= $minPrefixLength; + } + ) + ); } + $cleanTerms = array_merge([], ...$cleanTermBlocks); + return $maxTerms === 0 ? $cleanTerms : array_slice($cleanTerms, 0, $maxTerms); } diff --git a/src/Provider/LuceneIndexProvider.php b/src/Provider/LuceneIndexProvider.php index 8f627ef..bb096a2 100644 --- a/src/Provider/LuceneIndexProvider.php +++ b/src/Provider/LuceneIndexProvider.php @@ -177,7 +177,7 @@ protected function executeUpdate(ContextDefinitionInterface $contextDefinition, $luceneHandler = new LuceneHandler($this->getStableIndex($this->getLocaleFromIndexDocumentResource($indexDocument))); $termDocuments = $luceneHandler->findTermDocuments($indexDocument->getDocumentId()); - if (!is_array($termDocuments) || count($termDocuments) === 0) { + if (count($termDocuments) === 0) { $createNewDocumentMessage = $this->options['force_adding_document'] === true ? ' Going to add new document (options "force_adding_document" is set to "true")' : ' Going to skip adding new document (options "force_adding_document" is set to "false")'; @@ -220,7 +220,7 @@ protected function executeDelete(ContextDefinitionInterface $contextDefinition, $luceneHandler = new LuceneHandler($this->getStableIndex()); $termDocuments = $luceneHandler->findTermDocuments($indexDocument->getDocumentId()); - if (!is_array($termDocuments) || count($termDocuments) === 0) { + if (count($termDocuments) === 0) { $this->logger->error( sprintf('document with id "%s" could not be found. Skipping deletion...', $indexDocument->getDocumentId()), DsLuceneBundle::PROVIDER_NAME, diff --git a/src/Service/LuceneStorageBuilder.php b/src/Service/LuceneStorageBuilder.php index 5b13fe2..f0c35b0 100644 --- a/src/Service/LuceneStorageBuilder.php +++ b/src/Service/LuceneStorageBuilder.php @@ -50,10 +50,6 @@ public function createGenesisIndex(array $providerOptions, bool $killExistingIns throw new LuceneException(sprintf('Unable to create lucene database "%s". Error was: %s', $databaseName, $e), $e); } - if (!$index instanceof SearchIndexInterface) { - throw new LuceneException(sprintf('Unable to create lucene database "%s"', $databaseName)); - } - return $this->getLuceneIndex($providerOptions); }