From 11e30fe558be95f2f856e733a5ad1252f90b187d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Mon, 16 Oct 2023 11:33:15 +0200 Subject: [PATCH] IBX-6601: Fixed wrong documentation for Indexable/Unindexed (#283) --- phpstan-baseline.neon | 10 ---------- src/contracts/FieldType/Indexable.php | 4 ++-- src/lib/FieldType/Unindexed.php | 8 +++----- src/lib/Search/Common/FieldNameResolver.php | 6 ++++++ 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 60485190d5..d7db7376e1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10370,16 +10370,6 @@ parameters: count: 1 path: src/lib/FieldType/Time/Value.php - - - message: "#^Method Ibexa\\\\Core\\\\FieldType\\\\Unindexed\\:\\:getDefaultMatchField\\(\\) should return string but returns null\\.$#" - count: 1 - path: src/lib/FieldType/Unindexed.php - - - - message: "#^Method Ibexa\\\\Core\\\\FieldType\\\\Unindexed\\:\\:getDefaultSortField\\(\\) should return string but returns null\\.$#" - count: 1 - path: src/lib/FieldType/Unindexed.php - - message: "#^Access to an undefined property Ibexa\\\\Contracts\\\\Core\\\\FieldType\\\\Value\\:\\:\\$text\\.$#" count: 1 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/FieldType/Unindexed.php b/src/lib/FieldType/Unindexed.php index 09c29cb234..30fde7f162 100644 --- a/src/lib/FieldType/Unindexed.php +++ b/src/lib/FieldType/Unindexed.php @@ -11,7 +11,9 @@ use Ibexa\Contracts\Core\Persistence\Content\Type\FieldDefinition; /** - * Indexable definition for string field type. + * Empty implementation of \Ibexa\Contracts\Core\FieldType\Indexable. + * + * Used when field type doesn't contribute to search index. */ class Unindexed implements Indexable { @@ -31,8 +33,6 @@ public function getIndexDefinition() * As field types can index multiple fields (see MapLocation field type's * implementation of this interface), this method is used to define default * field for matching. Default field is typically used by Field criterion. - * - * @return string */ public function getDefaultMatchField() { @@ -45,8 +45,6 @@ public function getDefaultMatchField() * As field types can index multiple fields (see MapLocation field type's * 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 */ 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"