diff --git a/src/ActiveDataProvider.php b/src/ActiveDataProvider.php index 3f70d91..20b969e 100644 --- a/src/ActiveDataProvider.php +++ b/src/ActiveDataProvider.php @@ -77,9 +77,9 @@ public function getAggregations(): array * * @param string $name aggregation name. * - * @return array aggregation results. - * * @throws InvalidCallException if query results do not contain the requested aggregation. + * + * @return array aggregation results. */ public function getAggregation(string $name): array { @@ -107,9 +107,9 @@ public function getSuggestions(): array * * @param string $name suggestion name. * - * @return array suggestion results. - * * @throws InvalidCallException if query results do not contain the requested suggestion. + * + * @return array suggestion results. */ public function getSuggestion(string $name): array { diff --git a/src/ActiveFixture.php b/src/ActiveFixture.php index 7b1cba3..3b06be5 100644 --- a/src/ActiveFixture.php +++ b/src/ActiveFixture.php @@ -149,9 +149,9 @@ public function load(): void * * If the data file does not exist, an empty array will be returned. * - * @return array the data rows to be inserted into the database index. - * * @throws InvalidConfigException + * + * @return array the data rows to be inserted into the database index. */ protected function getData(): array { diff --git a/src/ActiveQuery.php b/src/ActiveQuery.php index 393724b..c03bf9e 100644 --- a/src/ActiveQuery.php +++ b/src/ActiveQuery.php @@ -119,9 +119,9 @@ public function init(): void * @param Connection|null $db the DB connection used to create the DB command. * If null, the DB connection returned by [[modelClass]] will be used. * - * @return Command the created DB command instance. - * * @throws Exception + * + * @return Command the created DB command instance. */ public function createCommand(Connection $db = null): Command { @@ -169,9 +169,9 @@ public function createCommand(Connection $db = null): Command * @param Connection|null $db the DB connection used to create the DB command. * If null, the DB connection returned by [[modelClass]] will be used. * - * @return array the query results. If the query results in nothing, an empty array will be returned. - * * @throws Exception + * + * @return array the query results. If the query results in nothing, an empty array will be returned. */ public function all($db = null): array { @@ -258,11 +258,11 @@ public function populate(array $rows): array * @param Connection|null $db the DB connection used to create the DB command. * If null, the DB connection returned by [[modelClass]] will be used. * + * @throws Exception + * * @return ActiveRecord|array|null a single row of a query result. Depending on the setting of [[asArray]], * the query result may be either an array or an ActiveRecord object. Null will be returned * if the query results in nothing. - * - * @throws Exception */ public function one($db = null): ActiveRecord|array|null { diff --git a/src/ActiveRecord.php b/src/ActiveRecord.php index b6979c7..572aa11 100644 --- a/src/ActiveRecord.php +++ b/src/ActiveRecord.php @@ -83,9 +83,9 @@ class ActiveRecord extends BaseActiveRecord * By default, the "elasticsearch" application component is used as the database connection. * You may override this method if you want to use a different database connection. * - * @return Connection the database connection used by this AR class. - * * @throws InvalidConfigException + * + * @return Connection the database connection used by this AR class. */ public static function getDb() { @@ -95,9 +95,9 @@ public static function getDb() /** * @inheritdoc * - * @return ActiveQuery the newly created [[ActiveQuery]] instance. - * * @throws InvalidConfigException + * + * @return ActiveQuery the newly created [[ActiveQuery]] instance. */ public static function find() { @@ -174,10 +174,10 @@ private static function filterCondition(array $condition): array * Please refer to the [Elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html) * for more details on these options. * - * @return static|null The record instance or null if it was not found. - * * @throws InvalidConfigException * @throws \yii\elasticsearch\Exception + * + * @return static|null The record instance or null if it was not found. */ public static function get(mixed $primaryKey, array $options = []): static|null { @@ -209,10 +209,10 @@ public static function get(mixed $primaryKey, array $options = []): static|null * Please refer to the [Elasticsearch documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html) * for more details on these options. * - * @return array The record instances, or empty array if nothing was found - * * @throws InvalidConfigException * @throws \yii\elasticsearch\Exception + * + * @return array The record instances, or empty array if nothing was found */ public static function mget(array $primaryKeys, array $options = []): array { @@ -455,9 +455,9 @@ public static function populateRecord($record, $row): void * - `_type`: the type this record is stored in. * - `_Index`: the index this record is stored in. * - * @return static the newly created active record - * * @throws InvalidConfigException + * + * @return static the newly created active record */ public static function instantiate($row): static { @@ -510,10 +510,10 @@ public static function instantiate($row): static * * By default, the `op_type` is set to `create` if a model primary key is present. * - * @return bool whether the attributes are valid and the record is inserted successfully. - * * @throws InvalidConfigException * @throws \yii\elasticsearch\Exception + * + * @return bool whether the attributes are valid and the record is inserted successfully. */ public function insert($runValidation = true, $attributes = null, array $options = [ ]): bool { @@ -590,13 +590,13 @@ public function insert($runValidation = true, $attributes = null, array $options * Make sure the record has been fetched with a [[version]] before. This is only the case * for records fetched via [[get()]] and [[mget()]] by default. For normal queries, the `_version` field has to be fetched explicitly. * - * @return bool|int the number of rows affected, or false if validation fails - * or [[beforeSave()]] stops the updating process. - * * @throws InvalidArgumentException if no [[version]] is available and optimistic locking is enabled. * @throws Exception * @throws InvalidConfigException in case update failed. * @throws StaleObjectException if optimistic, locking is enabled and the data being updated is outdated. + * + * @return bool|int the number of rows affected, or false if validation fails + * or [[beforeSave()]] stops the updating process. */ public function update($runValidation = true, $attributeNames = null, array $options = []): bool|int { @@ -611,12 +611,12 @@ public function update($runValidation = true, $attributeNames = null, array $opt * @param array $options options given in this parameter are passed to Elasticsearch * as request URI parameters. See [[update()]] for details. * - * @return false|int the number of rows affected, or false if [[beforeSave()]] stops the updating process. - * * @throws Exception in case update failed. * @throws InvalidConfigException * @throws StaleObjectException if optimistic, locking is enabled and the data being updated is outdated. * + * @return false|int the number of rows affected, or false if [[beforeSave()]] stops the updating process. + * * @see update() */ protected function updateInternal($attributes = null, array $options = []): bool|int @@ -684,10 +684,10 @@ protected function updateInternal($attributes = null, array $options = []): bool * * @param array $condition please refer to [[ActiveQuery::where()]] on how to specify this parameter * - * @return array primary keys that correspond to given conditions - * * @throws InvalidConfigException * + * @return array primary keys that correspond to given conditions + * * @see updateAllCounters() * @see deleteAll() * @see updateAll() @@ -721,11 +721,10 @@ protected static function primaryKeysByCondition(array $condition): array * @param array $condition the conditions that will be passed to the `where()` method when building the query. * Please refer to [[ActiveQuery::where()]] on how to specify this parameter. * - * @return int the number of rows updated - * * @throws InvalidConfigException - * * @throws Exception on error.*@see [[ActiveRecord::primaryKeysByCondition()]] + * + * @return int the number of rows updated */ public static function updateAll($attributes, $condition = []): int { @@ -774,11 +773,11 @@ public static function updateAll($attributes, $condition = []): int * @param array $condition the conditions that will be passed to the `where()` method when building the query. * Please refer to [[ActiveQuery::where()]] on how to specify this parameter. * - * @return int the number of rows updated - * * @throws InvalidConfigException * @throws Exception on error. * + * @return int the number of rows updated + * * @see [[ActiveRecord::primaryKeysByCondition()]] */ public static function updateAllCounters($counters, $condition = []): int @@ -854,13 +853,13 @@ public static function updateAllCounters($counters, $condition = []): int * for records fetched via [[get()]] and [[mget()]] by default. * For normal queries, the `_version` field has to be fetched explicitly. * - * @return bool|int the number of rows deleted, or false if the deletion is unsuccessful for some reason. - * * @throws StaleObjectException if optimistic, locking is enabled and the data being deleted is outdated. * @throws Exception * @throws InvalidConfigException in case delete failed. * * Note that it is possible the number of rows deleted is 0, even though the deletion execution is successful. + * + * @return bool|int the number of rows deleted, or false if the deletion is unsuccessful for some reason. */ public function delete(array $options = []): bool|int { @@ -914,11 +913,11 @@ public function delete(array $options = []): bool|int * @param array $condition the conditions that will be passed to the `where()` method when building the query. * Please refer to [[ActiveQuery::where()]] on how to specify this parameter. * - * @return int the number of rows deleted - * * @throws InvalidConfigException * @throws Exception on error. * + * @return int the number of rows deleted + * * @see [[ActiveRecord::primaryKeysByCondition()]] */ public static function deleteAll($condition = []): int diff --git a/src/BatchQueryResult.php b/src/BatchQueryResult.php index 57540c9..fc73689 100644 --- a/src/BatchQueryResult.php +++ b/src/BatchQueryResult.php @@ -165,10 +165,10 @@ public function next(): void /** * Fetches the next batch of data. * - * @return array the data fetched - * * @throws Exception * @throws InvalidConfigException + * + * @return array the data fetched */ protected function fetchData(): array { diff --git a/src/BulkCommand.php b/src/BulkCommand.php index f715c4b..00edf71 100644 --- a/src/BulkCommand.php +++ b/src/BulkCommand.php @@ -55,9 +55,10 @@ class BulkCommand extends Component /** * Executes the bulk command. * - * @return mixed * @throws Exception * @throws InvalidConfigException + * + * @return mixed */ public function execute(): mixed { diff --git a/src/Command.php b/src/Command.php index 72a4fdf..46e66c7 100644 --- a/src/Command.php +++ b/src/Command.php @@ -61,10 +61,10 @@ class Command extends Component * * @param array $options URL options * - * @return mixed *@throws InvalidConfigException - * * @throws Exception + * + * @return mixed */ public function search(array $options = []): mixed { @@ -94,10 +94,10 @@ public function search(array $options = []): mixed * * @param array $options URL options * - * @return mixed *@throws InvalidConfigException - * * @throws Exception + * + * @return mixed */ public function deleteByQuery(array $options = []): mixed { @@ -131,11 +131,11 @@ public function deleteByQuery(array $options = []): mixed * @param array|string $suggester the suggester body * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html */ public function suggest(array|string $suggester, array $options = []): mixed @@ -161,14 +161,14 @@ public function suggest(array|string $suggester, array $options = []): mixed * @param string $index Index that the document belongs to. * @param string|null $type Type that the document belongs to. * @param array|string $data json string or array of data to store - * @param string|int|null $id the documents' id. If not specified, I'd will be automatically chosen + * @param int|string|null $id the documents' id. If not specified, I'd will be automatically chosen * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html */ public function insert( @@ -203,13 +203,14 @@ public function insert( * * @param string $index Index that the document belongs to. * @param string|null $type Type that the document belongs to. - * @param string|int|null $id the documents' id. + * @param int|string|null $id the documents' id. * @param array $options URL options * - * @return mixed - * * @throws Exception * @throws InvalidConfigException + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html */ public function get(string $index, string|null $type, string|int $id = null, array $options = []): mixed @@ -231,11 +232,11 @@ public function get(string $index, string|null $type, string|int $id = null, arr * @param string[] $ids the documents ids as values in an array. * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html */ public function mget(string $index, ?string $type, array $ids, array $options = []): mixed @@ -256,11 +257,11 @@ public function mget(string $index, ?string $type, array $ids, array $options = * @param string|null $type Type that the document belongs to. * @param string $id the documents' id. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html#_source */ public function getSource(string $index, ?string $type, string $id): mixed @@ -279,11 +280,11 @@ public function getSource(string $index, ?string $type, string $id): mixed * @param string|null $type Type that the document belongs to. * @param string $id the documents' id. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html */ public function exists(string $index, string|null $type, string $id): mixed @@ -303,11 +304,11 @@ public function exists(string $index, string|null $type, string $id): mixed * @param string $id the documents' id. * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html */ public function delete(string $index, string|null $type, string $id, array $options = []): mixed @@ -328,11 +329,11 @@ public function delete(string $index, string|null $type, string $id, array $opti * @param mixed $data the documents' data. * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html */ public function update(string $index, string|null $type, string $id, mixed $data, array $options = []): mixed @@ -359,11 +360,11 @@ public function update(string $index, string|null $type, string $id, mixed $data * @param string $index Index that the document belongs to. * @param array|null $configuration * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html */ public function createIndex(string $index, array $configuration = null): mixed @@ -378,11 +379,11 @@ public function createIndex(string $index, array $configuration = null): mixed * * @param string $index Index that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html */ public function deleteIndex(string $index): mixed @@ -410,11 +411,11 @@ public function deleteAllIndexes(): mixed * * @param string $index Index that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html */ public function indexExists(string $index): mixed @@ -426,11 +427,11 @@ public function indexExists(string $index): mixed * @param string $index Index that the document belongs to. * @param string|null $type Type that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-types-exists.html */ public function typeExists(string $index, string|null $type): mixed @@ -445,10 +446,10 @@ public function typeExists(string $index, string|null $type): mixed /** * @param string $alias * - * @return bool *@throws InvalidConfigException - * * @throws Exception + * + * @return bool */ public function aliasExists(string $alias): bool { @@ -475,11 +476,11 @@ public function getAliasInfo(): array /** * @param string $alias * - * @return array - * * @throws InvalidConfigException - * * @throws Exception + * + * @return array + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-retrieving */ public function getIndexInfoByAlias(string $alias): array @@ -496,10 +497,10 @@ public function getIndexInfoByAlias(string $alias): array /** * @param string $alias * - * @return array *@throws InvalidConfigException - * * @throws Exception + * + * @return array */ public function getIndexesByAlias(string $alias): array { @@ -509,11 +510,11 @@ public function getIndexesByAlias(string $alias): array /** * @param string $index Index that the document belongs to. * - * @return array - * * @throws InvalidConfigException - * * @throws Exception + * + * @return array + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-retrieving */ public function getIndexAliases(string $index): array @@ -532,12 +533,12 @@ public function getIndexAliases(string $index): array * @param string $alias * @param array $aliasParameters * - * @return bool - * * @throws InvalidConfigException - * * @throws Exception * @throws JsonException + * + * @return bool + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#alias-adding */ public function addAlias(string $index, string $alias, array $aliasParameters = []): bool @@ -553,11 +554,11 @@ public function addAlias(string $index, string $alias, array $aliasParameters = * @param string $index Index that the document belongs to. * @param string $alias * - * @return bool - * * @throws InvalidConfigException - * * @throws Exception + * + * @return bool + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#deleting */ public function removeAlias(string $index, string $alias): bool @@ -578,12 +579,12 @@ public function removeAlias(string $index, string $alias): bool * * @param array $actions * - * @return bool - * * @throws InvalidConfigException * @throws JsonException * @throws Exception * + * @return bool + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html#indices-aliases */ public function aliasActions(array $actions): bool @@ -600,11 +601,11 @@ public function aliasActions(array $actions): bool * @param array|string|null $setting * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-update-settings.html */ public function updateSettings(string $index, array|string $setting = null, array $options = []): mixed @@ -649,11 +650,11 @@ public function updateSettings(string $index, array|string $setting = null, arra * @param array|string $setting * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html#update-settings-analysis */ public function updateAnalyzers(string $index, array|string $setting, array $options = []): mixed @@ -672,11 +673,11 @@ public function updateAnalyzers(string $index, array|string $setting, array $opt /** * @param string $index Index that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html */ public function openIndex(string $index): mixed @@ -687,11 +688,11 @@ public function openIndex(string $index): mixed /** * @param string $index Index that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException * @throws Exception * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html */ public function closeIndex(string $index): mixed @@ -702,11 +703,11 @@ public function closeIndex(string $index): mixed /** * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException * @throws Exception * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html */ public function scroll(array $options = []): mixed @@ -728,11 +729,11 @@ public function scroll(array $options = []): mixed /** * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html */ public function clearScroll(array $options = []): mixed @@ -753,11 +754,11 @@ public function clearScroll(array $options = []): mixed /** * @param string $index Index that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html */ public function getIndexStats(string $index = '_all'): mixed @@ -768,11 +769,11 @@ public function getIndexStats(string $index = '_all'): mixed /** * @param string $index Index that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html */ public function getIndexRecoveryStats(string $index = '_all'): mixed @@ -785,11 +786,11 @@ public function getIndexRecoveryStats(string $index = '_all'): mixed /** * @param string $index Index that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clearcache.html */ public function clearIndexCache(string $index): mixed @@ -800,11 +801,11 @@ public function clearIndexCache(string $index): mixed /** * @param string $index Index that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html */ public function flushIndex(string $index = '_all'): mixed @@ -815,11 +816,11 @@ public function flushIndex(string $index = '_all'): mixed /** * @param string $index Index that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html */ public function refreshIndex(string $index): mixed @@ -836,11 +837,11 @@ public function refreshIndex(string $index): mixed * @param array|string|null $mapping * @param array $options URL options * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html */ public function setMapping(string $index, string|null $type, array|string|null $mapping, array $options = []): mixed @@ -864,11 +865,11 @@ public function setMapping(string $index, string|null $type, array|string|null $ * @param string $index Index that the document belongs to. * @param string|null $type Type that the document belongs to. * - * @return mixed - * * @throws InvalidConfigException - * * @throws Exception + * + * @return mixed + * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html */ public function getMapping(string $index = '_all', string $type = null): mixed diff --git a/src/Connection.php b/src/Connection.php index 189ce59..5f37743 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -102,7 +102,7 @@ class Connection extends Component ['http_address' => 'inet[/127.0.0.1:9200]'], ]; /** - * @var string|int|null the active node. Key of one of the [[nodes]]. Will be randomly selected on [[open()]]. + * @var int|string|null the active node. Key of one of the [[nodes]]. Will be randomly selected on [[open()]]. */ public string|int|null $activeNode = null; /** @@ -226,7 +226,7 @@ public function open(): void $this->selectActiveNode(); Yii::debug( - 'Opening connection to Elasticsearch. Nodes in cluster: ' . count($this->nodes) . ', active node: ' . + 'Opening connection to Elasticsearch. Nodes in cluster: ' . count($this->nodes) . ', active node: ' . $this->nodes[$this->activeNode]['http_address'], __CLASS__ ); @@ -306,7 +306,7 @@ public function close(): void } Yii::debug( - 'Closing connection to Elasticsearch. Active node was: ' . + 'Closing connection to Elasticsearch. Active node was: ' . $this->nodes[$this->activeNode]['http']['publish_address'], __CLASS__, ); @@ -344,10 +344,10 @@ public function getDriverName(): string * * @param array $config the configuration for the Command class. * - * @return Command the DB command. - * * @throws InvalidConfigException * @throws Exception + * + * @return Command the DB command. */ public function createCommand(array $config = []): Command { @@ -362,10 +362,10 @@ public function createCommand(array $config = []): Command * * @param array $config the configuration for the [[BulkCommand]] class. * - * @return BulkCommand the DB command. - * * @throws InvalidConfigException * @throws Exception + * + * @return BulkCommand the DB command. */ public function createBulkCommand(array $config = []): BulkCommand { @@ -393,10 +393,10 @@ public function getQueryBuilder(): QueryBuilder * @param string|null $body request body. * @param bool $raw if response body contains JSON and should be decoded. * - * @return mixed response. - * * @throws InvalidConfigException * @throws Exception + * + * @return mixed response. */ public function get(array|string $url, array $options = [], string $body = null, bool $raw = false): mixed { @@ -412,9 +412,10 @@ public function get(array|string $url, array $options = [], string $body = null, * @param array $options URL options. * @param string|null $body request body. * - * @return mixed response. * @throws InvalidConfigException * @throws Exception + * + * @return mixed response. */ public function head(array|string $url, array $options = [], string $body = null): mixed { @@ -431,10 +432,10 @@ public function head(array|string $url, array $options = [], string $body = null * @param string|null $body request body. * @param bool $raw if response body contains JSON and should be decoded. * - * @return mixed response - * * @throws InvalidConfigException * @throws Exception + * + * @return mixed response */ public function post(array|string $url, array $options = [], string $body = null, bool $raw = false): mixed { @@ -451,10 +452,10 @@ public function post(array|string $url, array $options = [], string $body = null * @param string|null $body request body. * @param bool $raw if response body contains JSON and should be decoded. * - * @return mixed response - * * @throws InvalidConfigException * @throws Exception + * + * @return mixed response */ public function put(array|string $url, array $options = [], string $body = null, bool $raw = false): mixed { @@ -471,10 +472,10 @@ public function put(array|string $url, array $options = [], string $body = null, * @param string|null $body request body. * @param bool $raw if response body contains JSON and should be decoded. * - * @return mixed response. - * * @throws InvalidConfigException * @throws Exception + * + * @return mixed response. */ public function delete(array|string $url, array $options = [], string $body = null, bool $raw = false): mixed { @@ -528,10 +529,10 @@ static function ($a) { * @param string|null $requestBody request body. * @param bool $raw if response body contains JSON and should be decoded. * - * @return mixed if request failed. - * * @throws InvalidConfigException * @throws Exception if request failed. + * + * @return mixed if request failed. */ protected function httpRequest( string $method, @@ -642,7 +643,8 @@ protected function httpRequest( curl_setopt_array($this->_curl, $options); if (curl_exec($this->_curl) === false) { - throw new Exception('Elasticsearch request failed: ' . curl_errno($this->_curl) . ' - ' . + throw new Exception( + 'Elasticsearch request failed: ' . curl_errno($this->_curl) . ' - ' . curl_error($this->_curl), [ 'requestMethod' => $method, diff --git a/src/DebugPanel.php b/src/DebugPanel.php index 09f93d7..81806a1 100644 --- a/src/DebugPanel.php +++ b/src/DebugPanel.php @@ -221,7 +221,8 @@ public function save(): mixed $target = $this->module->logTarget; $messages = $target->filterMessages( $target->messages, - Logger::LEVEL_PROFILE, ['yii\elasticsearch\Connection::httpRequest'], + Logger::LEVEL_PROFILE, + ['yii\elasticsearch\Connection::httpRequest'], ); return ['messages' => $messages]; diff --git a/src/ElasticsearchTarget.php b/src/ElasticsearchTarget.php index d93c8bf..2131051 100644 --- a/src/ElasticsearchTarget.php +++ b/src/ElasticsearchTarget.php @@ -20,6 +20,7 @@ use yii\helpers\VarDumper; use yii\log\Logger; use yii\log\Target; + use function array_map; use function implode; diff --git a/src/Query.php b/src/Query.php index c77c88d..c5d7e93 100644 --- a/src/Query.php +++ b/src/Query.php @@ -162,7 +162,7 @@ class Query extends Component implements QueryInterface */ public array|bool|null $source = null; /** - * @var string|array|null The index to retrieve data from. This can be a string representing a single index or an + * @var array|string|null The index to retrieve data from. This can be a string representing a single index or an * array of multiple indexes. * If this is not set, indexes are being queried. * @@ -276,10 +276,10 @@ public function init(): void * If this parameter is not given, the `elasticsearch` application * component will be used. * - * @return Command the created DB command instance. - * * @throws InvalidConfigException * @throws Exception + * + * @return Command the created DB command instance. */ public function createCommand(Connection $db = null): Command { @@ -298,10 +298,10 @@ public function createCommand(Connection $db = null): Command * @param Connection $db the database connection used to execute the query. * If this parameter is not given, the `elasticsearch` application component will be used. * - * @return array the query results. If the query results in nothing, an empty array will be returned. - * * @throws Exception * @throws InvalidConfigException + * + * @return array the query results. If the query results in nothing, an empty array will be returned. */ public function all($db = null): array { @@ -363,11 +363,11 @@ public function populate(array $rows): array * @param Connection $db the database connection used to execute the query. * If this parameter is not given, the `elasticsearch` application component will be used. * - * @return ActiveRecord|array|bool|null the first row (in terms of an array) of the query result. - * False is returned if the query results in nothing. - * * @throws InvalidConfigException * @throws Exception + * + * @return ActiveRecord|array|bool|null the first row (in terms of an array) of the query result. + * False is returned if the query results in nothing. */ public function one($db = null) { @@ -399,10 +399,10 @@ public function one($db = null) * * - [routing](https://www.elastic.co/guide/en/elasticsearch/reference/current/search.html#search-routing) * - * @return array the query results. - * * @throws Exception * @throws InvalidConfigException + * + * @return array the query results. */ public function search(Connection $db = null, array $options = []) { @@ -446,10 +446,10 @@ public function search(Connection $db = null, array $options = []) * If this parameter is not given, the `elasticsearch` application component will be used. * @param array $options The options given with this query. * - * @return array the query results. - * * @throws Exception * @throws InvalidConfigException + * + * @return array the query results. */ public function delete(Connection $db = null, array $options = []): array { @@ -469,11 +469,11 @@ public function delete(Connection $db = null, array $options = []): array * @param Connection|null $db the database connection used to execute the query. * If this parameter is not given, the `elasticsearch` application component will be used. * - * @return string|null the value of the specified attribute in the first record of the query result. - * Null is returned if the query result is empty or the field does not exist. - * * @throws Exception * @throws InvalidConfigException + * + * @return string|null the value of the specified attribute in the first record of the query result. + * Null is returned if the query result is empty or the field does not exist. */ public function scalar(string $field, Connection $db = null): string|null { @@ -509,10 +509,10 @@ public function scalar(string $field, Connection $db = null): string|null * @param Connection|null $db the database connection used to execute the query. * If this parameter is not given, the `elasticsearch` application component will be used. * - * @return array the first column of the query result. An empty array is returned if the query results in nothing. - * * @throws Exception * @throws InvalidConfigException + * + * @return array the first column of the query result. An empty array is returned if the query results in nothing. */ public function column(string $field, Connection $db = null): array { @@ -554,10 +554,10 @@ public function column(string $field, Connection $db = null): array * @param Connection $db the database connection used to execute the query. * If this parameter is not given, the `elasticsearch` application component will be used. * - * @return int number of records. - * * @throws Exception * @throws InvalidConfigException + * + * @return int number of records. */ public function count($q = '*', $db = null): int { @@ -593,10 +593,10 @@ public function count($q = '*', $db = null): int * @param Connection $db the database connection used to execute the query. * If this parameter is not given, the `elasticsearch` application component will be used. * - * @return bool whether the query result contains any row of data. - * * @throws Exception * @throws InvalidConfigException + * + * @return bool whether the query result contains any row of data. */ public function exists($db = null): bool { @@ -726,10 +726,10 @@ public function query(array|string $query): static * @param Connection|null $db the database connection. If not set, the `elasticsearch` application component will be * used. * + * @throws InvalidConfigException + * * @return BatchQueryResult the batch query result. It implements the [[\Iterator]] interface and can be traversed * to retrieve the data in batches. - * - * @throws InvalidConfigException */ public function batch(string $scrollWindow = '1m', Connection $db = null): BatchQueryResult { @@ -761,10 +761,10 @@ public function batch(string $scrollWindow = '1m', Connection $db = null): Batch * @param Connection|null $db the database connection. If not set, the `elasticsearch` application component will be * used. * + * @throws InvalidConfigException + * * @return BatchQueryResult the batch query result. It implements the [[\Iterator]] interface and can be traversed * to retrieve the data in batches. - * - * @throws InvalidConfigException */ public function each(string $scrollWindow = '1m', Connection $db = null): BatchQueryResult { @@ -884,7 +884,7 @@ public function fields(array|string|null $fields): static /** * Sets the source filtering, specifying how the `_source` field of the document should be returned. * - * @param bool|array|string|null $source the source patterns to be selected. + * @param array|bool|string|null $source the source patterns to be selected. * * @return static the query object itself. * diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index f7fbee6..25e4abb 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -41,10 +41,10 @@ public function __construct(public Connection $db, array $config = []) * * @param Query $query the [[Query]] object from which the query will be generated. * + * @throws NotSupportedException + * * @return array the generated SQL statement (the first array element) and the corresponding parameters to be bound * to the SQL statement (the second array element). - * - * @throws NotSupportedException */ public function build(Query $query): array { @@ -206,10 +206,10 @@ public function buildQueryFromWhere($condition): ?array * @param array|string|null $condition the condition specification. Please refer to [[Query::where()]] on how to * specify a condition. * - * @return array|string the generated SQL expression - * * @throws NotSupportedException if string conditions are used in where * @throws InvalidArgumentException if unknown operator is used in a query + * + * @return array|string the generated SQL expression */ public function buildCondition(array|string $condition = null): array|string { @@ -270,9 +270,9 @@ private function buildHashCondition($condition): array } else { $parts[] = ['ids' => ['values' => is_array($value) ? $value : [$value]]]; } - } else if (is_array($value)) { // IN condition + } elseif (is_array($value)) { // IN condition $parts[] = ['terms' => [$attribute => $value]]; - } else if ($value === null) { + } elseif ($value === null) { $emptyFields[] = [ 'exists' => [ 'field' => $attribute ] ]; } else { $parts[] = ['term' => [$attribute => $value]]; @@ -424,7 +424,7 @@ private function buildInCondition($operator, $operands): array ]; } } - } else if (empty($values) && $canBeNull) { + } elseif (empty($values) && $canBeNull) { $filter = [ 'bool' => [ 'must_not' => [ diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 2af89ba..1e77d3b 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -77,7 +77,8 @@ public function testGetAggregations(): void { $provider = new ActiveDataProvider( [ - 'query' => Customer::find()->addAggregate('agg_status', + 'query' => Customer::find()->addAggregate( + 'agg_status', [ 'terms' => [ 'field' => 'status', diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index 432d46a..4a01872 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -75,7 +75,7 @@ protected function setUp(): void 'name' => 'user2', 'address' => 'address2', 'status' => 1, - 'is_active' => true + 'is_active' => true, ], [ '_id' => 3, @@ -590,7 +590,7 @@ static function ($event) use (&$afterFindCalls): void { $ar::class, $ar->getIsNewRecord(), $ar->getPrimaryKey(), - $ar->isRelationPopulated('orders') + $ar->isRelationPopulated('orders'), ]; }, ); diff --git a/tests/data/ar/Order.php b/tests/data/ar/Order.php index 86c4e06..a5a8203 100644 --- a/tests/data/ar/Order.php +++ b/tests/data/ar/Order.php @@ -124,7 +124,8 @@ public static function setUpMapping(Command $command): void { $command->setMapping( static::index(), - static::type(), [ + static::type(), + [ 'properties' => [ 'customer_id' => ['type' => 'integer'], 'total' => ['type' => 'integer'], diff --git a/tests/data/ar/OrderItem.php b/tests/data/ar/OrderItem.php index b807080..1de3cfe 100644 --- a/tests/data/ar/OrderItem.php +++ b/tests/data/ar/OrderItem.php @@ -43,7 +43,8 @@ public static function setUpMapping(Command $command): void { $command->setMapping( static::index(), - static::type(), [ + static::type(), + [ 'properties' => [ 'order_id' => ['type' => 'integer'], 'item_id' => ['type' => 'integer'],