From 002178ac9d8aff9968c1588ea1ac4fb5ad120ac6 Mon Sep 17 00:00:00 2001 From: Tomasz Kryszan Date: Thu, 22 Aug 2024 12:15:55 +0200 Subject: [PATCH] Reworked criterion --- phpstan-baseline.neon | 5 ++++ .../Location/IsBookmarked.php | 27 +++++-------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2993acd5..87ea39c4 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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\\.$#" + count: 1 + path: src/lib/Query/Location/CriterionVisitor/Location/IsBookmarked.php + - message: "#^Cannot access offset 0 on array\\\\|bool\\|float\\|int\\|string\\.$#" count: 1 diff --git a/src/lib/Query/Location/CriterionVisitor/Location/IsBookmarked.php b/src/lib/Query/Location/CriterionVisitor/Location/IsBookmarked.php index 348e583f..50d66521 100644 --- a/src/lib/Query/Location/CriterionVisitor/Location/IsBookmarked.php +++ b/src/lib/Query/Location/CriterionVisitor/Location/IsBookmarked.php @@ -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; @@ -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; } }