From aa82131692a7d9c8c86a38c406f253b136eaf256 Mon Sep 17 00:00:00 2001 From: Tomasz Kryszan Date: Tue, 7 Nov 2023 14:23:02 +0100 Subject: [PATCH] Added exception throwing when searchFileNames array is empty --- .../CriterionVisitor/AbstractImageVisitor.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/Query/Image/CriterionVisitor/AbstractImageVisitor.php b/src/lib/Query/Image/CriterionVisitor/AbstractImageVisitor.php index 4077aa4f..9cd613ec 100644 --- a/src/lib/Query/Image/CriterionVisitor/AbstractImageVisitor.php +++ b/src/lib/Query/Image/CriterionVisitor/AbstractImageVisitor.php @@ -10,6 +10,7 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion; use Ibexa\Contracts\Solr\Query\CriterionVisitor; +use Ibexa\Core\Base\Exceptions\InvalidArgumentException; use Ibexa\Core\FieldType\Image\Type; use Ibexa\Core\Search\Common\FieldNameResolver; @@ -31,10 +32,12 @@ abstract protected function getSearchFieldName(): string; /** * @return array + * + * @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException */ protected function getSearchFieldNames(Criterion $criterion): array { - return array_keys( + $searchFieldNames = array_keys( $this->fieldNameResolver->getFieldTypes( $criterion, $criterion->target, @@ -42,5 +45,14 @@ protected function getSearchFieldNames(Criterion $criterion): array $this->getSearchFieldName() ) ); + + if (empty($searchFieldNames)) { + throw new InvalidArgumentException( + '$criterion->target', + "No searchable Fields found for the provided Criterion target '{$criterion->target}'." + ); + } + + return $searchFieldNames; } }