mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 08:35:00 +00:00
Clean up code.
This commit is contained in:
@@ -37,14 +37,14 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Support\Search\QueryParser\QueryParserInterface;
|
||||
use FireflyIII\Support\Search\QueryParser\Node;
|
||||
use FireflyIII\Support\Search\QueryParser\FieldNode;
|
||||
use FireflyIII\Support\Search\QueryParser\StringNode;
|
||||
use FireflyIII\Support\Search\QueryParser\NodeGroup;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use FireflyIII\Support\ParseDateString;
|
||||
use FireflyIII\Support\Search\QueryParser\FieldNode;
|
||||
use FireflyIII\Support\Search\QueryParser\Node;
|
||||
use FireflyIII\Support\Search\QueryParser\NodeGroup;
|
||||
use FireflyIII\Support\Search\QueryParser\QueryParserInterface;
|
||||
use FireflyIII\Support\Search\QueryParser\StringNode;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -56,26 +56,26 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class OperatorQuerySearch implements SearchInterface
|
||||
{
|
||||
protected Carbon $date;
|
||||
protected Carbon $date;
|
||||
private readonly AccountRepositoryInterface $accountRepository;
|
||||
private readonly BillRepositoryInterface $billRepository;
|
||||
private readonly BudgetRepositoryInterface $budgetRepository;
|
||||
private readonly CategoryRepositoryInterface $categoryRepository;
|
||||
private GroupCollectorInterface $collector;
|
||||
private GroupCollectorInterface $collector;
|
||||
private readonly CurrencyRepositoryInterface $currencyRepository;
|
||||
private array $excludeTags;
|
||||
private array $includeAnyTags;
|
||||
private array $excludeTags;
|
||||
private array $includeAnyTags;
|
||||
// added to fix #8632
|
||||
private array $includeTags;
|
||||
private array $invalidOperators;
|
||||
private int $limit;
|
||||
private array $includeTags;
|
||||
private array $invalidOperators;
|
||||
private int $limit;
|
||||
private readonly Collection $operators;
|
||||
private int $page;
|
||||
private array $prohibitedWords;
|
||||
private int $page;
|
||||
private array $prohibitedWords;
|
||||
private readonly float $startTime;
|
||||
private readonly TagRepositoryInterface $tagRepository;
|
||||
private readonly array $validOperators;
|
||||
private array $words;
|
||||
private array $words;
|
||||
|
||||
/**
|
||||
* OperatorQuerySearch constructor.
|
||||
@@ -122,16 +122,6 @@ class OperatorQuerySearch implements SearchInterface
|
||||
return implode(' ', $this->words);
|
||||
}
|
||||
|
||||
public function getWords(): array
|
||||
{
|
||||
return $this->words;
|
||||
}
|
||||
|
||||
public function getExcludedWords(): array
|
||||
{
|
||||
return $this->prohibitedWords;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -202,15 +192,6 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function handleNodeGroup(NodeGroup $node, bool $flipProhibitedFlag): void
|
||||
{
|
||||
$prohibited = $node->isProhibited($flipProhibitedFlag);
|
||||
|
||||
foreach ($node->getNodes() as $subNode) {
|
||||
$this->handleSearchNode($subNode, $prohibited);
|
||||
}
|
||||
}
|
||||
|
||||
private function handleStringNode(StringNode $node, bool $flipProhibitedFlag): void
|
||||
{
|
||||
$string = $node->getValue();
|
||||
@@ -2775,6 +2756,15 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
}
|
||||
|
||||
private function handleNodeGroup(NodeGroup $node, bool $flipProhibitedFlag): void
|
||||
{
|
||||
$prohibited = $node->isProhibited($flipProhibitedFlag);
|
||||
|
||||
foreach ($node->getNodes() as $subNode) {
|
||||
$this->handleSearchNode($subNode, $prohibited);
|
||||
}
|
||||
}
|
||||
|
||||
public function searchTime(): float
|
||||
{
|
||||
return microtime(true) - $this->startTime;
|
||||
@@ -2835,6 +2825,16 @@ class OperatorQuerySearch implements SearchInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function getWords(): array
|
||||
{
|
||||
return $this->words;
|
||||
}
|
||||
|
||||
public function getExcludedWords(): array
|
||||
{
|
||||
return $this->prohibitedWords;
|
||||
}
|
||||
|
||||
public function setDate(Carbon $date): void
|
||||
{
|
||||
$this->date = $date;
|
||||
|
@@ -26,9 +26,9 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Support\Search\QueryParser;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use Gdbots\QueryParser\QueryParser as BaseQueryParser;
|
||||
use Gdbots\QueryParser\Node as GdbotsNode;
|
||||
use Gdbots\QueryParser\Enum\BoolOperator;
|
||||
use Gdbots\QueryParser\Node as GdbotsNode;
|
||||
use Gdbots\QueryParser\QueryParser as BaseQueryParser;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GdbotsQueryParser implements QueryParserInterface
|
||||
|
@@ -34,28 +34,6 @@ abstract class Node
|
||||
{
|
||||
protected bool $prohibited;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param bool $flipFlag When true, inverts the prohibited status
|
||||
*
|
||||
* @return bool The (potentially inverted) prohibited status
|
||||
*/
|
||||
public function isProhibited(bool $flipFlag): bool
|
||||
{
|
||||
if ($flipFlag) {
|
||||
// Log::debug(sprintf('This %s is (flipped) now prohibited: %s',get_class($this), var_export(!$this->prohibited, true)));
|
||||
return !$this->prohibited;
|
||||
}
|
||||
|
||||
// Log::debug(sprintf('This %s is (not flipped) now prohibited: %s',get_class($this), var_export($this->prohibited, true)));
|
||||
return $this->prohibited;
|
||||
|
||||
}
|
||||
|
||||
public function equals(self $compare): bool
|
||||
{
|
||||
if ($compare->isProhibited(false) !== $this->isProhibited(false)) {
|
||||
@@ -87,4 +65,26 @@ abstract class Node
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* @param bool $flipFlag When true, inverts the prohibited status
|
||||
*
|
||||
* @return bool The (potentially inverted) prohibited status
|
||||
*/
|
||||
public function isProhibited(bool $flipFlag): bool
|
||||
{
|
||||
if ($flipFlag) {
|
||||
// Log::debug(sprintf('This %s is (flipped) now prohibited: %s',get_class($this), var_export(!$this->prohibited, true)));
|
||||
return !$this->prohibited;
|
||||
}
|
||||
|
||||
// Log::debug(sprintf('This %s is (not flipped) now prohibited: %s',get_class($this), var_export($this->prohibited, true)));
|
||||
return $this->prohibited;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -34,8 +34,8 @@ use Illuminate\Support\Facades\Log;
|
||||
*/
|
||||
class QueryParser implements QueryParserInterface
|
||||
{
|
||||
private string $query;
|
||||
private int $position = 0;
|
||||
private string $query;
|
||||
|
||||
public function parse(string $query): NodeGroup
|
||||
{
|
||||
|
@@ -33,6 +33,8 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface SearchInterface
|
||||
{
|
||||
public function getExcludedWords(): array;
|
||||
|
||||
public function getInvalidOperators(): array;
|
||||
|
||||
public function getModifiers(): Collection;
|
||||
@@ -43,8 +45,6 @@ interface SearchInterface
|
||||
|
||||
public function getWordsAsString(): string;
|
||||
|
||||
public function getExcludedWords(): array;
|
||||
|
||||
public function hasModifiers(): bool;
|
||||
|
||||
public function parseQuery(string $query): void;
|
||||
|
Reference in New Issue
Block a user