Skip to content

Commit

Permalink
Added exception throwing when searchFileNames array is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
ciastektk authored and webhdx committed Nov 20, 2023
1 parent 0336594 commit 0bb09c9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/lib/Query/Image/CriterionVisitor/AbstractImageVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -31,16 +32,27 @@ abstract protected function getSearchFieldName(): string;

/**
* @return array<string>
*
* @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,
$this->imageFieldType->getFieldTypeIdentifier(),
$this->getSearchFieldName()
)
);

if (empty($searchFieldNames)) {
throw new InvalidArgumentException(
'$criterion->target',
"No searchable Fields found for the provided Criterion target '{$criterion->target}'."
);
}

return $searchFieldNames;
}
}

0 comments on commit 0bb09c9

Please sign in to comment.