mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 04:19:12 +00:00
Fix code quality with rector [skip ci]
This commit is contained in:
@@ -36,30 +36,20 @@ use function Safe\json_encode;
|
||||
*/
|
||||
class AccountSearch implements GenericSearchInterface
|
||||
{
|
||||
/** @var string */
|
||||
public const string SEARCH_ALL = 'all';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_IBAN = 'iban';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_ID = 'id';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_NAME = 'name';
|
||||
|
||||
/** @var string */
|
||||
public const string SEARCH_NUMBER = 'number';
|
||||
private string $field;
|
||||
private string $query;
|
||||
private array $types;
|
||||
private array $types = [];
|
||||
private User $user;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->types = [];
|
||||
}
|
||||
|
||||
public function search(): Collection
|
||||
{
|
||||
$searchQuery = $this->user->accounts()
|
||||
|
||||
@@ -66,19 +66,19 @@ class OperatorQuerySearch implements SearchInterface
|
||||
private readonly CategoryRepositoryInterface $categoryRepository;
|
||||
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 = 25;
|
||||
private readonly Collection $operators;
|
||||
private int $page;
|
||||
private array $prohibitedWords;
|
||||
private int $page = 1;
|
||||
private array $prohibitedWords = [];
|
||||
private readonly float $startTime;
|
||||
private readonly TagRepositoryInterface $tagRepository;
|
||||
private readonly array $validOperators;
|
||||
private array $words;
|
||||
private array $words = [];
|
||||
|
||||
/**
|
||||
* OperatorQuerySearch constructor.
|
||||
@@ -87,14 +87,6 @@ class OperatorQuerySearch implements SearchInterface
|
||||
{
|
||||
Log::debug('Constructed OperatorQuerySearch');
|
||||
$this->operators = new Collection();
|
||||
$this->page = 1;
|
||||
$this->words = [];
|
||||
$this->excludeTags = [];
|
||||
$this->includeAnyTags = [];
|
||||
$this->includeTags = [];
|
||||
$this->prohibitedWords = [];
|
||||
$this->invalidOperators = [];
|
||||
$this->limit = 25;
|
||||
$this->validOperators = array_keys(config('search.operators'));
|
||||
$this->startTime = microtime(true);
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
@@ -293,15 +285,13 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
// must be valid operator:
|
||||
$inArray = in_array($operator, $this->validOperators, true);
|
||||
if ($inArray) {
|
||||
if ($this->updateCollector($operator, $value, $prohibited)) {
|
||||
$this->operators->push([
|
||||
'type' => self::getRootOperator($operator),
|
||||
'value' => $value,
|
||||
'prohibited' => $prohibited,
|
||||
]);
|
||||
Log::debug(sprintf('Added operator type "%s"', $operator));
|
||||
}
|
||||
if ($inArray && $this->updateCollector($operator, $value, $prohibited)) {
|
||||
$this->operators->push([
|
||||
'type' => self::getRootOperator($operator),
|
||||
'value' => $value,
|
||||
'prohibited' => $prohibited,
|
||||
]);
|
||||
Log::debug(sprintf('Added operator type "%s"', $operator));
|
||||
}
|
||||
if (!$inArray) {
|
||||
Log::debug(sprintf('Added INVALID operator type "%s"', $operator));
|
||||
@@ -495,14 +485,14 @@ class OperatorQuerySearch implements SearchInterface
|
||||
|
||||
return;
|
||||
}
|
||||
if (0 === $accounts->count() && true === $prohibited) {
|
||||
if (0 === $accounts->count() && $prohibited) {
|
||||
Log::debug('Found zero accounts, but the search is negated, so effectively we ignore the search parameter.');
|
||||
|
||||
return;
|
||||
}
|
||||
Log::debug(sprintf('Found %d accounts, will filter.', $accounts->count()));
|
||||
$filtered = $accounts->filter(
|
||||
static fn (Account $account) => $stringMethod(strtolower($account->name), strtolower($value))
|
||||
static fn (Account $account): bool => $stringMethod(strtolower($account->name), strtolower($value))
|
||||
);
|
||||
|
||||
if (0 === $filtered->count()) {
|
||||
@@ -530,7 +520,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
// search direction (default): for source accounts
|
||||
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::REVENUE->value];
|
||||
$collectorMethod = 'setSourceAccounts';
|
||||
if (true === $prohibited) {
|
||||
if ($prohibited) {
|
||||
$collectorMethod = 'excludeSourceAccounts';
|
||||
}
|
||||
|
||||
@@ -539,7 +529,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
// destination can be
|
||||
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value];
|
||||
$collectorMethod = 'setDestinationAccounts';
|
||||
if (true === $prohibited) {
|
||||
if ($prohibited) {
|
||||
$collectorMethod = 'excludeDestinationAccounts';
|
||||
}
|
||||
}
|
||||
@@ -548,7 +538,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
if (SearchDirection::BOTH === $searchDirection) {
|
||||
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value, AccountTypeEnum::REVENUE->value];
|
||||
$collectorMethod = 'setAccounts';
|
||||
if (true === $prohibited) {
|
||||
if ($prohibited) {
|
||||
$collectorMethod = 'excludeAccounts';
|
||||
}
|
||||
}
|
||||
@@ -580,7 +570,7 @@ class OperatorQuerySearch implements SearchInterface
|
||||
// if found, do filter
|
||||
Log::debug(sprintf('Found %d accounts, will filter.', $accounts->count()));
|
||||
$filtered = $accounts->filter(
|
||||
static function (Account $account) use ($value, $stringMethod) {
|
||||
static function (Account $account) use ($value, $stringMethod): bool {
|
||||
// either IBAN or account number
|
||||
$ibanMatch = $stringMethod(strtolower((string)$account->iban), strtolower($value));
|
||||
$accountNrMatch = false;
|
||||
|
||||
@@ -54,15 +54,15 @@ class GdbotsQueryParser implements QueryParserInterface
|
||||
try {
|
||||
$result = $this->parser->parse($query);
|
||||
$nodes = array_map(
|
||||
fn (GdbotsNode\Node $node) => $this->convertNode($node),
|
||||
$this->convertNode(...),
|
||||
$result->getNodes()
|
||||
);
|
||||
|
||||
return new NodeGroup($nodes);
|
||||
} catch (LogicException|TypeError $e) {
|
||||
fwrite(STDERR, "Setting up GdbotsQueryParserTest\n");
|
||||
app('log')->error($e->getMessage());
|
||||
app('log')->error(sprintf('Could not parse search: "%s".', $query));
|
||||
Log::error($e->getMessage());
|
||||
Log::error(sprintf('Could not parse search: "%s".', $query));
|
||||
|
||||
throw new FireflyException(sprintf('Invalid search value "%s". See the logs.', e($query)), 0, $e);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class GdbotsQueryParser implements QueryParserInterface
|
||||
|
||||
return new NodeGroup(
|
||||
array_map(
|
||||
fn (GdbotsNode\Node $subNode) => $this->convertNode($subNode),
|
||||
$this->convertNode(...),
|
||||
$node->getNodes()
|
||||
)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user