Drop else-statements, remove debug statement.

This commit is contained in:
James Cole 2025-01-05 07:45:29 +01:00
parent fd6560bdd0
commit 10a284848b
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
4 changed files with 20 additions and 15 deletions

View File

@ -147,6 +147,7 @@ class OperatorQuerySearch implements SearchInterface
public function parseQuery(string $query): void public function parseQuery(string $query): void
{ {
app('log')->debug(sprintf('Now in parseQuery(%s)', $query)); app('log')->debug(sprintf('Now in parseQuery(%s)', $query));
/** @var QueryParserInterface $parser */
$parser = app(QueryParserInterface::class); $parser = app(QueryParserInterface::class);
app('log')->debug(sprintf('Using %s as implementation for QueryParserInterface', get_class($parser))); app('log')->debug(sprintf('Using %s as implementation for QueryParserInterface', get_class($parser)));
@ -217,7 +218,8 @@ class OperatorQuerySearch implements SearchInterface
if($prohibited) { if($prohibited) {
app('log')->debug(sprintf('Exclude string "%s" from search string', $string)); app('log')->debug(sprintf('Exclude string "%s" from search string', $string));
$this->prohibitedWords[] = $string; $this->prohibitedWords[] = $string;
} else { }
if(!$prohibited) {
app('log')->debug(sprintf('Add string "%s" to search string', $string)); app('log')->debug(sprintf('Add string "%s" to search string', $string));
$this->words[] = $string; $this->words[] = $string;
} }
@ -246,7 +248,8 @@ class OperatorQuerySearch implements SearchInterface
} }
// must be valid operator: // 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)) { if ($this->updateCollector($operator, $value, $prohibited)) {
$this->operators->push([ $this->operators->push([
'type' => self::getRootOperator($operator), 'type' => self::getRootOperator($operator),
@ -255,7 +258,8 @@ class OperatorQuerySearch implements SearchInterface
]); ]);
app('log')->debug(sprintf('Added operator type "%s"', $operator)); app('log')->debug(sprintf('Added operator type "%s"', $operator));
} }
} else { }
if(!$inArray) {
app('log')->debug(sprintf('Added INVALID operator type "%s"', $operator)); app('log')->debug(sprintf('Added INVALID operator type "%s"', $operator));
$this->invalidOperators[] = [ $this->invalidOperators[] = [
'type' => $operator, 'type' => $operator,

View File

@ -54,7 +54,6 @@ class GdbotsQueryParser implements QueryParserInterface
return new NodeGroup($nodes); return new NodeGroup($nodes);
} catch (\LogicException|\TypeError $e) { } catch (\LogicException|\TypeError $e) {
fwrite(STDERR, "Setting up GdbotsQueryParserTest\n"); fwrite(STDERR, "Setting up GdbotsQueryParserTest\n");
dd('Creating GdbotsQueryParser');
app('log')->error($e->getMessage()); app('log')->error($e->getMessage());
app('log')->error(sprintf('Could not parse search: "%s".', $query)); app('log')->error(sprintf('Could not parse search: "%s".', $query));

View File

@ -35,18 +35,19 @@ abstract class Node
/** /**
* Returns the prohibited status of the node, optionally inverted based on flipFlag * 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 * @param bool $flipFlag When true, inverts the prohibited status
*
* @return bool The (potentially inverted) prohibited status * @return bool The (potentially inverted) prohibited status
*/ */
public function isProhibited(bool $flipFlag): bool public function isProhibited(bool $flipFlag): bool
{ {
if ($flipFlag === true) { if ($flipFlag) {
return !$this->prohibited; return !$this->prohibited;
} else {
return $this->prohibited;
} }
return $this->prohibited;
} }
} }

View File

@ -92,13 +92,12 @@ class QueryParser implements QueryParserInterface
$tokenUnderConstruction .= $char; $tokenUnderConstruction .= $char;
$this->position++; $this->position++;
continue; continue;
} else { }
$this->position++; $this->position++;
return new NodeResult( return new NodeResult(
$this->createNode($tokenUnderConstruction, $fieldName, $prohibited), $this->createNode($tokenUnderConstruction, $fieldName, $prohibited),
false false
); );
}
} }
switch ($char) { switch ($char) {
@ -106,7 +105,8 @@ class QueryParser implements QueryParserInterface
if ($tokenUnderConstruction === '') { if ($tokenUnderConstruction === '') {
// A minus sign at the beginning of a token indicates prohibition // A minus sign at the beginning of a token indicates prohibition
$prohibited = true; $prohibited = true;
} else { }
if ($tokenUnderConstruction !== '') {
// In any other location, it's just a normal character // In any other location, it's just a normal character
$tokenUnderConstruction .= $char; $tokenUnderConstruction .= $char;
} }
@ -116,7 +116,8 @@ class QueryParser implements QueryParserInterface
if ($tokenUnderConstruction === '') { if ($tokenUnderConstruction === '') {
// A quote sign at the beginning of a token indicates the start of a quoted string // A quote sign at the beginning of a token indicates the start of a quoted string
$inQuotes = true; $inQuotes = true;
} else { }
if ($tokenUnderConstruction !== '') {
// In any other location, it's just a normal character // In any other location, it's just a normal character
$tokenUnderConstruction .= $char; $tokenUnderConstruction .= $char;
} }
@ -129,10 +130,9 @@ class QueryParser implements QueryParserInterface
return new NodeResult($this->buildNodeGroup(true, $prohibited), return new NodeResult($this->buildNodeGroup(true, $prohibited),
false false
); );
} else { }
// In any other location, it's just a normal character // In any other location, it's just a normal character
$tokenUnderConstruction .= $char; $tokenUnderConstruction .= $char;
}
break; break;
case ')': 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 // 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; $fieldName = $tokenUnderConstruction;
$tokenUnderConstruction = ''; $tokenUnderConstruction = '';
} else { }
if ($tokenUnderConstruction === '') {
// In any other location, it's just a normal character // In any other location, it's just a normal character
$tokenUnderConstruction .= $char; $tokenUnderConstruction .= $char;
} }