From 402a2238de1bdf70a87ad2c354f69d97760230c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Wed, 11 Oct 2023 22:30:06 +0200 Subject: [PATCH] IBX-6601: Aligned \Ibexa\Contracts\Core\FieldType\Indexable::{getDefaultMatchField, getDefaultSortField} allowed return types with existing implementations --- src/contracts/FieldType/Indexable.php | 4 ++-- src/lib/Search/Common/FieldNameResolver.php | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/contracts/FieldType/Indexable.php b/src/contracts/FieldType/Indexable.php index 1d72714a9a..1229d34279 100644 --- a/src/contracts/FieldType/Indexable.php +++ b/src/contracts/FieldType/Indexable.php @@ -39,7 +39,7 @@ public function getIndexDefinition(); * implementation of this interface), this method is used to define default * field for matching. Default field is typically used by Field criterion. * - * @return string + * @return string|null */ public function getDefaultMatchField(); @@ -50,7 +50,7 @@ public function getDefaultMatchField(); * implementation of this interface), this method is used to define default * field for sorting. Default field is typically used by Field sort clause. * - * @return string + * @return string|null */ public function getDefaultSortField(); } diff --git a/src/lib/Search/Common/FieldNameResolver.php b/src/lib/Search/Common/FieldNameResolver.php index 02a94ab5d2..1bce132395 100644 --- a/src/lib/Search/Common/FieldNameResolver.php +++ b/src/lib/Search/Common/FieldNameResolver.php @@ -263,6 +263,12 @@ public function getIndexFieldName( $indexDefinition = $indexFieldType->getIndexDefinition(); // Should only happen by mistake, so let's throw if it does + if ($name === null) { + throw new RuntimeException( + "Undefined default sort or match field in '{$fieldTypeIdentifier}' Field Type's index definition" + ); + } + if (!isset($indexDefinition[$name])) { throw new RuntimeException( "Could not find Field '{$name}' in '{$fieldTypeIdentifier}' Field Type's index definition"