diff --git a/search_api_db/src/DatabaseCompatibility/MySql.php b/search_api_db/src/DatabaseCompatibility/MySql.php index 909a256..134e4f3 100644 --- a/search_api_db/src/DatabaseCompatibility/MySql.php +++ b/search_api_db/src/DatabaseCompatibility/MySql.php @@ -24,7 +24,7 @@ class MySql extends GenericDatabase { $this->database->query("ALTER TABLE {{$table}} CONVERT TO CHARACTER SET 'utf8' COLLATE '$collation'"); } catch (\PDOException $e) { - throw new SearchApiException(get_class($e) . ' while trying to change collation of' . $type . ' search data table ' . $table . ':' . $e->getMessage() . '.', 0, $e); + throw new SearchApiException(get_class($e) . " while trying to change collation of {$type} search data table {$table} ':' {$e->getMessage()}", 0, $e); } } diff --git a/search_api_db/src/Plugin/search_api/backend/Database.php b/search_api_db/src/Plugin/search_api/backend/Database.php index c81f03d..0e55d1e 100644 --- a/search_api_db/src/Plugin/search_api/backend/Database.php +++ b/search_api_db/src/Plugin/search_api/backend/Database.php @@ -806,7 +806,7 @@ class Database extends BackendPluginBase { return array('type' => 'int', 'size' => 'tiny'); default: - throw new SearchApiException('Unknown field type ' . $type . '. Database search module might be out of sync with Search API.'); + throw new SearchApiException("Unknown field type {$type}. Database search module might be out of sync with Search API."); } } @@ -1062,7 +1062,7 @@ class Database extends BackendPluginBase { */ public function indexItems(IndexInterface $index, array $items) { if (!$this->getIndexDbInfo($index)) { - throw new SearchApiException('No field settings for index with id ' . $index->id() . '.'); + throw new SearchApiException("No field settings for index with id {$index->id()}."); } $indexed = array(); foreach ($items as $id => $item) { @@ -1405,7 +1405,7 @@ class Database extends BackendPluginBase { return strtotime($value); default: - throw new SearchApiException('Unknown field type ' . $type . '. Database search module might be out of sync with Search API.'); + throw new SearchApiException("Unknown field type {$type}. Database search module might be out of sync with Search API."); } } @@ -1467,7 +1467,7 @@ class Database extends BackendPluginBase { $db_info = $this->getIndexDbInfo($index); if (!isset($db_info['field_tables'])) { - throw new SearchApiException('Unknown index ' . $index->id() . '.'); + throw new SearchApiException("Unknown index {$index->id()}."); } $fields = $this->getFieldInfo($index); @@ -1511,7 +1511,7 @@ class Database extends BackendPluginBase { } if (!isset($fields[$field_name])) { - throw new SearchApiException('Trying to sort on unknown field ' . $field_name . '.'); + throw new SearchApiException("Trying to sort on unknown field {$field_name}."); } $alias = $this->getTableAlias(array('table' => $db_info['index_table']), $db_query); $db_query->orderBy($alias . '.' . $fields[$field_name]['column'], $order); @@ -1588,12 +1588,12 @@ class Database extends BackendPluginBase { $fulltext_field_information = array(); foreach ($fulltext_fields as $name) { if (!isset($fields[$name])) { - throw new SearchApiException('Unknown field ' . $name . ' specified as search target.'); + throw new SearchApiException("Unknown field {$name} specified as search target."); } if (!Utility::isTextType($fields[$name]['type'])) { $types = $this->getDataTypePluginManager()->getInstances(); $type = $types[$fields[$name]['type']]->label(); - throw new SearchApiException('Cannot perform fulltext search on field ' . $name . ' of type ' . $type . '.'); + throw new SearchApiException("Cannot perform fulltext search on field {$name} of type {$type}."); } $fulltext_field_information[$name] = $fields[$name]; } @@ -2040,7 +2040,7 @@ class Database extends BackendPluginBase { $not_between = $operator == 'NOT BETWEEN'; if (!isset($fields[$field])) { - throw new SearchApiException('Unknown field in filter clause: ' . $field . '.'); + throw new SearchApiException("Unknown field in filter clause: {$field}."); } $field_info = $fields[$field]; // For NULL values, we can just use the single-values table, since we @@ -2330,7 +2330,7 @@ class Database extends BackendPluginBase { $index = $query->getIndex(); $db_info = $this->getIndexDbInfo($index); if (empty($db_info['field_tables'])) { - throw new SearchApiException('Unknown index ' . $index->id() . '.'); + throw new SearchApiException("Unknown index {$index->id()}."); } $fields = $this->getFieldInfo($index); diff --git a/src/Entity/Index.php b/src/Entity/Index.php index b54d08a..6cb2860 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -377,7 +377,7 @@ class Index extends ConfigEntityBase implements IndexInterface { $datasources = $this->getDatasources(); if (empty($datasources[$datasource_id])) { - throw new SearchApiException('The datasource with ID "' . $datasource_id . '" could not be retrieved for index ' . $this->label() . '.'); + throw new SearchApiException("The datasource with ID '{$datasource_id}' could not be retrieved for index {$this->label()}."); } return $datasources[$datasource_id]; @@ -458,7 +458,7 @@ class Index extends ConfigEntityBase implements IndexInterface { } if (!($this->trackerInstance = \Drupal::service('plugin.manager.search_api.tracker')->createInstance($tracker_id, $configuration))) { - throw new SearchApiException('The tracker with ID "' . $tracker_id . '" could not be retrieved for index ' . $this->label() . '.'); + throw new SearchApiException("The tracker with ID '{$tracker_id}' could not be retrieved for index {$this->label()}."); } } @@ -501,7 +501,7 @@ class Index extends ConfigEntityBase implements IndexInterface { if (!$this->serverInstance && $this->server) { $this->serverInstance = Server::load($this->server); if (!$this->serverInstance) { - throw new SearchApiException('The server with ID "' . $this->server . '" could not be retrieved for index ' . $this->label() . '.'); + throw new SearchApiException("The server with ID '{$this->server}' could not be retrieved for index {$this->label()}."); } } @@ -672,12 +672,12 @@ class Index extends ConfigEntityBase implements IndexInterface { public function addField(FieldInterface $field) { $field_id = $field->getFieldIdentifier(); if (Utility::isFieldIdReserved($field_id)) { - throw new SearchApiException($field_id . ' is a reserved value and cannot be used as the machine name of a normal field.'); + throw new SearchApiException("{$field_id} is a reserved value and cannot be used as the machine name of a normal field."); } $old_field = $this->getField($field_id); if ($old_field && $old_field != $field) { - throw new SearchApiException('Cannot add field with machine name ' . $field_id . ': machine name is already taken.'); + throw new SearchApiException("Cannot add field with machine name {$field_id}: machine name is already taken."); } $this->fieldInstances[$field_id] = $field; @@ -690,13 +690,13 @@ class Index extends ConfigEntityBase implements IndexInterface { */ public function renameField($old_field_id, $new_field_id) { if (!isset($this->getFields()[$old_field_id])) { - throw new SearchApiException('Could not rename field with machine name '. $old_field_id . ': no such field.'); + throw new SearchApiException("Could not rename field with machine name {$old_field_id}: no such field."); } if (Utility::isFieldIdReserved($new_field_id)) { - throw new SearchApiException($new_field_id . ' is a reserved value and cannot be used as the machine name of a normal field.'); + throw new SearchApiException("{$new_field_id} is a reserved value and cannot be used as the machine name of a normal field."); } if (isset($this->getFields()[$new_field_id])) { - throw new SearchApiException($new_field_id . ' already exists and can\'t be used as a new field id.'); + throw new SearchApiException("{$new_field_id} already exists and can't be used as a new field id."); } $this->fieldInstances[$new_field_id] = $this->fieldInstances[$old_field_id]; @@ -714,7 +714,7 @@ class Index extends ConfigEntityBase implements IndexInterface { return $this; } if ($field->isIndexedLocked()) { - throw new SearchApiException('Cannot remove field with machine name ' . $field_id . ': field is locked.'); + throw new SearchApiException("Cannot remove field with machine name {$field_id}: field is locked."); } unset($this->fieldInstances[$field_id]); @@ -863,7 +863,7 @@ class Index extends ConfigEntityBase implements IndexInterface { return array(); } if (!$this->status) { - throw new SearchApiException('Couldn\'t index values on index ' . $this->label() . ' (index is disabled)'); + throw new SearchApiException("Couldn't index values on index {$this->label()}' (index is disabled)"); } /** @var \Drupal\search_api\Item\ItemInterface[] $items */ diff --git a/src/Entity/Server.php b/src/Entity/Server.php index 19aff85..84bdc21 100644 --- a/src/Entity/Server.php +++ b/src/Entity/Server.php @@ -132,7 +132,7 @@ class Server extends ConfigEntityBase implements ServerInterface { $config = $this->backend_config; $config['server'] = $this; if (!($this->backendPlugin = $backend_plugin_manager->createInstance($this->getBackendId(), $config))) { - throw new SearchApiException('The backend with ID "' . $this->getBackendId() . '" could not be retrieved for server ' . $this->label() . '.'); + throw new SearchApiException("The backend with ID '{$this->getBackendId()}' could not be retrieved for server '{$this->label()}."); } } return $this->backendPlugin; @@ -277,7 +277,7 @@ class Server extends ConfigEntityBase implements ServerInterface { if ($server_task_manager->execute($this)) { return $this->getBackend()->indexItems($index, $items); } - throw new SearchApiException('Could not index items on index ' . $index->label() . ' because pending server tasks could not be executed.'); + throw new SearchApiException("Could not index items on index '{$index->label()}' because pending server tasks could not be executed."); } /** diff --git a/src/IndexBatchHelper.php b/src/IndexBatchHelper.php index 3ac6211..c70b620 100644 --- a/src/IndexBatchHelper.php +++ b/src/IndexBatchHelper.php @@ -93,7 +93,7 @@ class IndexBatchHelper { batch_set($batch_definition); } else { - throw new SearchApiException('Failed to create a batch with batch size ' . $batch_size . ' and limit ' . $limit . ' for index ' . $index->label()); + throw new SearchApiException("Failed to create a batch with batch size {$batch_size} and limit {$limit} for index {$index->label()}."); } } diff --git a/src/Item/Field.php b/src/Item/Field.php index bbdb992..3575f89 100644 --- a/src/Item/Field.php +++ b/src/Item/Field.php @@ -348,7 +348,7 @@ class Field implements \IteratorAggregate, FieldInterface { $definitions = $this->index->getPropertyDefinitions($this->getDatasourceId()); $definition = Utility::retrieveNestedProperty($definitions, $this->getPropertyPath()); if (!$definition) { - throw new SearchApiException('Could not retrieve data definition for field ' . $this->getLabel() .' on index ' . $this->getIndex()->label() . '.'); + throw new SearchApiException("Could not retrieve data definition for field {$this->getLabel()} on index {$this->getIndex()->label()}."); } $this->dataDefinition = $definition; } @@ -367,7 +367,7 @@ class Field implements \IteratorAggregate, FieldInterface { */ public function setType($type) { if ($type != $this->type && $this->isTypeLocked()) { - throw new SearchApiException('Trying to change the type of field ' . $this->getLabel() . ' on index ' . $this->getIndex()->label() . ', which is locked.'); + throw new SearchApiException("Trying to change the type of field {$this->getLabel()} on index {$this->getIndex()->label()}, which is locked."); } $this->type = $type; return $this; diff --git a/src/Query/Query.php b/src/Query/Query.php index de0f445..d0b3e36 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -137,7 +137,7 @@ class Query implements QueryInterface { */ public function __construct(IndexInterface $index, ResultsCacheInterface $results_cache, array $options = array()) { if (!$index->status()) { - throw new SearchApiException('Can\'t search on index ' . $index->label() . ' which is disabled.'); + throw new SearchApiException("Can't search on index {$index->label()} which is disabled."); } $this->index = $index; $this->resultsCache = $results_cache; diff --git a/tests/src/Kernel/ServerTaskTest.php b/tests/src/Kernel/ServerTaskTest.php index 4bfa220..690496c 100644 --- a/tests/src/Kernel/ServerTaskTest.php +++ b/tests/src/Kernel/ServerTaskTest.php @@ -237,8 +237,7 @@ class ServerTaskTest extends KernelTestBase { $this->fail('Pending server tasks did not prevent indexing of items.'); } catch (SearchApiException $e) { - $args['%index'] = $this->index->label(); - $expected_message = new FormattableMarkup('Could not index items on index %index because pending server tasks could not be executed.', $args); + $expected_message = "Could not index items on index {$this->index->label()} because pending server tasks could not be executed."; $this->assertEquals($expected_message, $e->getMessage(), 'Pending server tasks prevented indexing of items.'); } $this->assertEquals(array(), $this->getCalledBackendMethods(), 'indexItems was not executed.');