mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-05 05:33:36 +00:00
Autoformat lol
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* FieldNode.php
|
||||
* Copyright (c) 2025 https://github.com/Sobuno
|
||||
@@ -30,8 +29,11 @@ namespace FireflyIII\Support\Search\QueryParser;
|
||||
*/
|
||||
class FieldNode extends Node
|
||||
{
|
||||
public function __construct(private readonly string $operator, private readonly string $value, bool $prohibited = false)
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $operator,
|
||||
private readonly string $value,
|
||||
bool $prohibited = false
|
||||
) {
|
||||
$this->prohibited = $prohibited;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* GdbotsQueryParser.php
|
||||
* Copyright (c) 2025 https://github.com/Sobuno
|
||||
@@ -53,10 +52,7 @@ class GdbotsQueryParser implements QueryParserInterface
|
||||
{
|
||||
try {
|
||||
$result = $this->parser->parse($query);
|
||||
$nodes = array_map(
|
||||
$this->convertNode(...),
|
||||
$result->getNodes()
|
||||
);
|
||||
$nodes = array_map($this->convertNode(...), $result->getNodes());
|
||||
|
||||
return new NodeGroup($nodes);
|
||||
} catch (LogicException|TypeError $e) {
|
||||
@@ -70,27 +66,17 @@ class GdbotsQueryParser implements QueryParserInterface
|
||||
|
||||
private function convertNode(GdbotsNode\Node $node): Node
|
||||
{
|
||||
|
||||
switch (true) {
|
||||
case $node instanceof GdbotsNode\Word:
|
||||
return new StringNode($node->getValue(), BoolOperator::PROHIBITED === $node->getBoolOperator());
|
||||
|
||||
case $node instanceof GdbotsNode\Field:
|
||||
return new FieldNode(
|
||||
$node->getValue(),
|
||||
(string)$node->getNode()->getValue(),
|
||||
BoolOperator::PROHIBITED === $node->getBoolOperator()
|
||||
);
|
||||
return new FieldNode($node->getValue(), (string) $node->getNode()->getValue(), BoolOperator::PROHIBITED === $node->getBoolOperator());
|
||||
|
||||
case $node instanceof GdbotsNode\Subquery:
|
||||
Log::debug('Subquery');
|
||||
|
||||
return new NodeGroup(
|
||||
array_map(
|
||||
$this->convertNode(...),
|
||||
$node->getNodes()
|
||||
)
|
||||
);
|
||||
return new NodeGroup(array_map($this->convertNode(...), $node->getNodes()));
|
||||
|
||||
case $node instanceof GdbotsNode\Phrase:
|
||||
case $node instanceof GdbotsNode\Numbr:
|
||||
@@ -100,12 +86,10 @@ class GdbotsQueryParser implements QueryParserInterface
|
||||
case $node instanceof GdbotsNode\Mention:
|
||||
case $node instanceof GdbotsNode\Emoticon:
|
||||
case $node instanceof GdbotsNode\Emoji:
|
||||
return new StringNode((string)$node->getValue(), BoolOperator::PROHIBITED === $node->getBoolOperator());
|
||||
return new StringNode((string) $node->getValue(), BoolOperator::PROHIBITED === $node->getBoolOperator());
|
||||
|
||||
default:
|
||||
throw new FireflyException(
|
||||
sprintf('Unsupported node type: %s', $node::class)
|
||||
);
|
||||
throw new FireflyException(sprintf('Unsupported node type: %s', $node::class));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* Node.php
|
||||
* Copyright (c) 2025 https://github.com/Sobuno
|
||||
@@ -43,7 +42,11 @@ abstract class Node
|
||||
}
|
||||
if ($compare instanceof NodeGroup && $this instanceof NodeGroup) {
|
||||
if (count($compare->getNodes()) !== count($this->getNodes())) {
|
||||
Log::debug(sprintf('Return false because node count is different. Original is %d, compare is %d', count($this->getNodes()), count($compare->getNodes())));
|
||||
Log::debug(sprintf(
|
||||
'Return false because node count is different. Original is %d, compare is %d',
|
||||
count($this->getNodes()),
|
||||
count($compare->getNodes())
|
||||
));
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -85,6 +88,5 @@ abstract class Node
|
||||
|
||||
// Log::debug(sprintf('This %s is (not flipped) now prohibited: %s',get_class($this), var_export($this->prohibited, true)));
|
||||
return $this->prohibited;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* NodeGroup.php
|
||||
* Copyright (c) 2025 https://github.com/Sobuno
|
||||
@@ -35,8 +34,10 @@ class NodeGroup extends Node
|
||||
/**
|
||||
* @param Node[] $nodes
|
||||
*/
|
||||
public function __construct(private readonly array $nodes, bool $prohibited = false)
|
||||
{
|
||||
public function __construct(
|
||||
private readonly array $nodes,
|
||||
bool $prohibited = false
|
||||
) {
|
||||
$this->prohibited = $prohibited;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace FireflyIII\Support\Search\QueryParser;
|
||||
class NodeResult
|
||||
{
|
||||
public function __construct(
|
||||
public readonly ?Node $node,
|
||||
public readonly bool $isSubqueryEnd
|
||||
public readonly null|Node $node,
|
||||
public readonly bool $isSubqueryEnd
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* QueryParser.php
|
||||
* Copyright (c) 2025 https://github.com/Sobuno
|
||||
@@ -35,13 +34,13 @@ use SensitiveParameter;
|
||||
*/
|
||||
class QueryParser implements QueryParserInterface
|
||||
{
|
||||
private int $position = 0;
|
||||
private int $position = 0;
|
||||
private string $query;
|
||||
|
||||
public function parse(string $query): NodeGroup
|
||||
{
|
||||
Log::debug(sprintf('Parsing query in QueryParser: "%s"', $query));
|
||||
$this->query = $query;
|
||||
$this->query = $query;
|
||||
$this->position = 0;
|
||||
|
||||
return $this->buildNodeGroup(false);
|
||||
@@ -65,8 +64,8 @@ class QueryParser implements QueryParserInterface
|
||||
if ('\\' === $char && '"' === $nextChar) {
|
||||
// Log::debug('BACKSLASH!');
|
||||
// escaped quote, pretend it's a normal char and continue two places (skipping the actual character).
|
||||
$tokenUnderConstruction .= '\\'.$nextChar;
|
||||
$this->position += 2;
|
||||
$tokenUnderConstruction .= '\\' . $nextChar;
|
||||
$this->position += 2;
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -114,10 +113,7 @@ class QueryParser implements QueryParserInterface
|
||||
// A left parentheses at the beginning of a token indicates the start of a subquery
|
||||
++$this->position;
|
||||
|
||||
return new NodeResult(
|
||||
$this->buildNodeGroup(true, $prohibited),
|
||||
false
|
||||
);
|
||||
return new NodeResult($this->buildNodeGroup(true, $prohibited), false);
|
||||
}
|
||||
// In any other location, it's just a normal character
|
||||
$tokenUnderConstruction .= $char;
|
||||
@@ -131,9 +127,7 @@ class QueryParser implements QueryParserInterface
|
||||
++$this->position;
|
||||
|
||||
return new NodeResult(
|
||||
'' !== $tokenUnderConstruction
|
||||
? $this->createNode($tokenUnderConstruction, $fieldName, $prohibited)
|
||||
: null,
|
||||
'' !== $tokenUnderConstruction ? $this->createNode($tokenUnderConstruction, $fieldName, $prohibited) : null,
|
||||
true
|
||||
);
|
||||
}
|
||||
@@ -142,13 +136,12 @@ class QueryParser implements QueryParserInterface
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case ':':
|
||||
$skipNext = false;
|
||||
if ('' === $tokenUnderConstruction) {
|
||||
// In any other location, it's just a normal character
|
||||
$tokenUnderConstruction .= $char;
|
||||
$skipNext = true;
|
||||
$skipNext = true;
|
||||
}
|
||||
if ('' !== $tokenUnderConstruction && !$skipNext) { // @phpstan-ignore-line
|
||||
Log::debug(sprintf('Turns out that "%s" is a field name. Reset the token.', $tokenUnderConstruction));
|
||||
@@ -157,7 +150,6 @@ class QueryParser implements QueryParserInterface
|
||||
$tokenUnderConstruction = '';
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
@@ -165,10 +157,7 @@ class QueryParser implements QueryParserInterface
|
||||
if ('' !== $tokenUnderConstruction) {
|
||||
++$this->position;
|
||||
|
||||
return new NodeResult(
|
||||
$this->createNode($tokenUnderConstruction, $fieldName, $prohibited),
|
||||
false
|
||||
);
|
||||
return new NodeResult($this->createNode($tokenUnderConstruction, $fieldName, $prohibited), false);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -180,9 +169,7 @@ class QueryParser implements QueryParserInterface
|
||||
++$this->position;
|
||||
}
|
||||
|
||||
$finalNode = '' !== $tokenUnderConstruction || '' !== $fieldName
|
||||
? $this->createNode($tokenUnderConstruction, $fieldName, $prohibited)
|
||||
: null;
|
||||
$finalNode = '' !== $tokenUnderConstruction || '' !== $fieldName ? $this->createNode($tokenUnderConstruction, $fieldName, $prohibited) : null;
|
||||
|
||||
return new NodeResult($finalNode, true);
|
||||
}
|
||||
@@ -193,7 +180,7 @@ class QueryParser implements QueryParserInterface
|
||||
$nodeResult = $this->buildNextNode($isSubquery);
|
||||
|
||||
while ($nodeResult->node instanceof Node) {
|
||||
$nodes[] = $nodeResult->node;
|
||||
$nodes[] = $nodeResult->node;
|
||||
if ($nodeResult->isSubqueryEnd) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* QueryParserInterface.php
|
||||
* Copyright (c) 2025 https://github.com/Sobuno
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/*
|
||||
* StringNode.php
|
||||
* Copyright (c) 2025 https://github.com/Sobuno
|
||||
@@ -30,8 +29,10 @@ namespace FireflyIII\Support\Search\QueryParser;
|
||||
*/
|
||||
class StringNode extends Node
|
||||
{
|
||||
public function __construct(private readonly string $value, bool $prohibited = false)
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $value,
|
||||
bool $prohibited = false
|
||||
) {
|
||||
$this->prohibited = $prohibited;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user