Skip to content

Commit

Permalink
Reworked criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk committed Aug 22, 2024
1 parent 5de21dc commit 002178a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
5 changes: 5 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,11 @@ parameters:
count: 1
path: src/lib/Query/Location/CriterionVisitor/Location/DepthIn.php

-
message: "#^Cannot access offset 0 on array\\<bool\\|float\\|int\\|string\\>\\|bool\\|float\\|int\\|string\\.$#"
count: 1
path: src/lib/Query/Location/CriterionVisitor/Location/IsBookmarked.php

-
message: "#^Cannot access offset 0 on array\\<bool\\|float\\|int\\|string\\>\\|bool\\|float\\|int\\|string\\.$#"
count: 1
Expand Down
27 changes: 7 additions & 20 deletions src/lib/Query/Location/CriterionVisitor/Location/IsBookmarked.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Ibexa\Solr\Query\Location\CriterionVisitor\Location;

use Ibexa\Contracts\Core\Exception\InvalidArgumentException;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion;
use Ibexa\Contracts\Solr\Query\CriterionVisitor;
Expand All @@ -34,28 +33,16 @@ public function visit(
Criterion $criterion,
CriterionVisitor $subVisitor = null
): string {
$userId = $this->getUserId($criterion);
$userId = $this->permissionResolver
->getCurrentUserReference()
->getUserId();

return self::SEARCH_FIELD . ':"' . $userId . '"';
}
$query = self::SEARCH_FIELD . ':"' . $userId . '"';

/**
* @throws \Ibexa\Contracts\Core\Exception\InvalidArgumentException
*/
private function getUserId(Criterion $criterion): int
{
$valueData = $criterion->valueData;
if (!$valueData instanceof Criterion\Value\IsBookmarkedValue) {
throw new InvalidArgumentException(
'$criterion->valueData',
sprintf(
'Is expected to be of type: "%s", got "%s"',
Criterion\Value\IsBookmarkedValue::class,
get_debug_type($valueData)
)
);
if (!$criterion->value[0]) {
$query = 'NOT ' . $query;
}

return $valueData->getUserId() ?? $this->permissionResolver->getCurrentUserReference()->getUserId();
return $query;
}
}

0 comments on commit 002178a

Please sign in to comment.