Skip to content

Commit

Permalink
fix phpstan issues
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Jan 6, 2025
1 parent 402667e commit 1be8a9a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
25 changes: 13 additions & 12 deletions src/Modifier/TermModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Provider/LuceneIndexProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")';
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions src/Service/LuceneStorageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 1be8a9a

Please sign in to comment.