From 10a284848be36fc706b141eb13da8762df734652 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 5 Jan 2025 07:45:29 +0100 Subject: [PATCH] Drop else-statements, remove debug statement. --- app/Support/Search/OperatorQuerySearch.php | 10 +++++++--- .../Search/QueryParser/GdbotsQueryParser.php | 1 - app/Support/Search/QueryParser/Node.php | 9 +++++---- app/Support/Search/QueryParser/QueryParser.php | 15 ++++++++------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/Support/Search/OperatorQuerySearch.php b/app/Support/Search/OperatorQuerySearch.php index 403d859c4d..5fd97cde7e 100644 --- a/app/Support/Search/OperatorQuerySearch.php +++ b/app/Support/Search/OperatorQuerySearch.php @@ -147,6 +147,7 @@ class OperatorQuerySearch implements SearchInterface public function parseQuery(string $query): void { app('log')->debug(sprintf('Now in parseQuery(%s)', $query)); + /** @var QueryParserInterface $parser */ $parser = app(QueryParserInterface::class); app('log')->debug(sprintf('Using %s as implementation for QueryParserInterface', get_class($parser))); @@ -217,7 +218,8 @@ class OperatorQuerySearch implements SearchInterface if($prohibited) { app('log')->debug(sprintf('Exclude string "%s" from search string', $string)); $this->prohibitedWords[] = $string; - } else { + } + if(!$prohibited) { app('log')->debug(sprintf('Add string "%s" to search string', $string)); $this->words[] = $string; } @@ -246,7 +248,8 @@ class OperatorQuerySearch implements SearchInterface } // must be valid operator: - if (in_array($operator, $this->validOperators, true)) { + $inArray = in_array($operator, $this->validOperators, true); + if ($inArray) { if ($this->updateCollector($operator, $value, $prohibited)) { $this->operators->push([ 'type' => self::getRootOperator($operator), @@ -255,7 +258,8 @@ class OperatorQuerySearch implements SearchInterface ]); app('log')->debug(sprintf('Added operator type "%s"', $operator)); } - } else { + } + if(!$inArray) { app('log')->debug(sprintf('Added INVALID operator type "%s"', $operator)); $this->invalidOperators[] = [ 'type' => $operator, diff --git a/app/Support/Search/QueryParser/GdbotsQueryParser.php b/app/Support/Search/QueryParser/GdbotsQueryParser.php index 18f7054dcf..a83c14392d 100644 --- a/app/Support/Search/QueryParser/GdbotsQueryParser.php +++ b/app/Support/Search/QueryParser/GdbotsQueryParser.php @@ -54,7 +54,6 @@ class GdbotsQueryParser implements QueryParserInterface return new NodeGroup($nodes); } catch (\LogicException|\TypeError $e) { fwrite(STDERR, "Setting up GdbotsQueryParserTest\n"); - dd('Creating GdbotsQueryParser'); app('log')->error($e->getMessage()); app('log')->error(sprintf('Could not parse search: "%s".', $query)); diff --git a/app/Support/Search/QueryParser/Node.php b/app/Support/Search/QueryParser/Node.php index 8f79e5951d..6ab55485be 100644 --- a/app/Support/Search/QueryParser/Node.php +++ b/app/Support/Search/QueryParser/Node.php @@ -35,18 +35,19 @@ abstract class Node /** * Returns the prohibited status of the node, optionally inverted based on flipFlag * - * Flipping is used when a node is inside a NodeGroup that has a prohibited status itself, causing inversion of the query parts inside + * Flipping is used when a node is inside a NodeGroup that has a prohibited status itself, causing inversion of the + * query parts inside * * @param bool $flipFlag When true, inverts the prohibited status + * * @return bool The (potentially inverted) prohibited status */ public function isProhibited(bool $flipFlag): bool { - if ($flipFlag === true) { + if ($flipFlag) { return !$this->prohibited; - } else { - return $this->prohibited; } + return $this->prohibited; } } diff --git a/app/Support/Search/QueryParser/QueryParser.php b/app/Support/Search/QueryParser/QueryParser.php index b59e612f85..8b0e8d25ed 100644 --- a/app/Support/Search/QueryParser/QueryParser.php +++ b/app/Support/Search/QueryParser/QueryParser.php @@ -92,13 +92,12 @@ class QueryParser implements QueryParserInterface $tokenUnderConstruction .= $char; $this->position++; continue; - } else { + } $this->position++; return new NodeResult( $this->createNode($tokenUnderConstruction, $fieldName, $prohibited), false ); - } } switch ($char) { @@ -106,7 +105,8 @@ class QueryParser implements QueryParserInterface if ($tokenUnderConstruction === '') { // A minus sign at the beginning of a token indicates prohibition $prohibited = true; - } else { + } + if ($tokenUnderConstruction !== '') { // In any other location, it's just a normal character $tokenUnderConstruction .= $char; } @@ -116,7 +116,8 @@ class QueryParser implements QueryParserInterface if ($tokenUnderConstruction === '') { // A quote sign at the beginning of a token indicates the start of a quoted string $inQuotes = true; - } else { + } + if ($tokenUnderConstruction !== '') { // In any other location, it's just a normal character $tokenUnderConstruction .= $char; } @@ -129,10 +130,9 @@ class QueryParser implements QueryParserInterface return new NodeResult($this->buildNodeGroup(true, $prohibited), false ); - } else { + } // In any other location, it's just a normal character $tokenUnderConstruction .= $char; - } break; case ')': @@ -157,7 +157,8 @@ class QueryParser implements QueryParserInterface // If we meet a colon with a left-hand side string, we know we're in a field and are about to set up the value $fieldName = $tokenUnderConstruction; $tokenUnderConstruction = ''; - } else { + } + if ($tokenUnderConstruction === '') { // In any other location, it's just a normal character $tokenUnderConstruction .= $char; }