Clean up code.

This commit is contained in:
James Cole
2023-12-10 06:51:59 +01:00
parent c2b22a2bac
commit 46e130fdfe
195 changed files with 973 additions and 984 deletions

View File

@@ -77,7 +77,7 @@ class AccountSearch implements GenericSearchInterface
);
// meta data:
$searchQuery->orWhere(
static function (Builder $q) use ($originalQuery) { /** @phpstan-ignore-line */
static function (Builder $q) use ($originalQuery) { // @phpstan-ignore-line
$json = json_encode($originalQuery, JSON_THROW_ON_ERROR);
$q->where('account_meta.name', '=', 'account_number');
$q->where('account_meta.data', 'LIKE', $json);
@@ -96,7 +96,7 @@ class AccountSearch implements GenericSearchInterface
case self::SEARCH_NUMBER:
// meta data:
$searchQuery->Where(
static function (Builder $q) use ($originalQuery) { /** @phpstan-ignore-line */
static function (Builder $q) use ($originalQuery) { // @phpstan-ignore-line
$json = json_encode($originalQuery, JSON_THROW_ON_ERROR);
$q->where('account_meta.name', 'account_number');
$q->where('account_meta.data', $json);

View File

@@ -57,6 +57,8 @@ use Gdbots\QueryParser\QueryParser;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use LogicException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use TypeError;
/**
@@ -71,6 +73,8 @@ class OperatorQuerySearch implements SearchInterface
private CategoryRepositoryInterface $categoryRepository;
private GroupCollectorInterface $collector;
private CurrencyRepositoryInterface $currencyRepository;
private array $excludeTags;
private array $includeTags;
private array $invalidOperators;
private int $limit;
private Collection $operators;
@@ -81,9 +85,6 @@ class OperatorQuerySearch implements SearchInterface
private array $validOperators;
private array $words;
private array $excludeTags;
private array $includeTags;
/**
* OperatorQuerySearch constructor.
*
@@ -2165,6 +2166,44 @@ class OperatorQuerySearch implements SearchInterface
}
}
/**
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
private function parseTagInstructions(): void
{
app('log')->debug('Now in parseTagInstructions()');
// if exclude tags, remove excluded tags.
if (count($this->excludeTags) > 0) {
app('log')->debug(sprintf('%d exclude tag(s)', count($this->excludeTags)));
$collection = new Collection;
foreach ($this->excludeTags as $tagId) {
$tag = $this->tagRepository->find($tagId);
if (null !== $tag) {
app('log')->debug(sprintf('Exclude tag "%s"', $tag->tag));
$collection->push($tag);
}
}
app('log')->debug(sprintf('Selecting all tags except %d excluded tag(s).', $collection->count()));
$this->collector->setWithoutSpecificTags($collection);
}
// if include tags, include them:
if (count($this->includeTags) > 0) {
app('log')->debug(sprintf('%d include tag(s)', count($this->includeTags)));
$collection = new Collection;
foreach ($this->includeTags as $tagId) {
$tag = $this->tagRepository->find($tagId);
if (null !== $tag) {
app('log')->debug(sprintf('Include tag "%s"', $tag->tag));
$collection->push($tag);
}
}
$this->collector->setTags($collection);
}
}
/**
* @inheritDoc
*/
@@ -2235,42 +2274,4 @@ class OperatorQuerySearch implements SearchInterface
$this->limit = $limit;
$this->collector->setLimit($this->limit);
}
/**
* @return void
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
private function parseTagInstructions(): void
{
app('log')->debug('Now in parseTagInstructions()');
// if exclude tags, remove excluded tags.
if (count($this->excludeTags) > 0) {
app('log')->debug(sprintf('%d exclude tag(s)', count($this->excludeTags)));
$collection = new Collection;
foreach ($this->excludeTags as $tagId) {
$tag = $this->tagRepository->find($tagId);
if (null !== $tag) {
app('log')->debug(sprintf('Exclude tag "%s"', $tag->tag));
$collection->push($tag);
}
}
app('log')->debug(sprintf('Selecting all tags except %d excluded tag(s).', $collection->count()));
$this->collector->setWithoutSpecificTags($collection);
}
// if include tags, include them:
if (count($this->includeTags) > 0) {
app('log')->debug(sprintf('%d include tag(s)', count($this->includeTags)));
$collection = new Collection;
foreach ($this->includeTags as $tagId) {
$tag = $this->tagRepository->find($tagId);
if (null !== $tag) {
app('log')->debug(sprintf('Include tag "%s"', $tag->tag));
$collection->push($tag);
}
}
$this->collector->setTags($collection);
}
}
}