Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing @throws annotation to Client::request and related methods #2152

Merged
merged 6 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
* Added support for PHP 8.2 [#2136](https://github.com/ruflin/Elastica/pull/2136)
* Added missing `@throws` annotations to Client::request and related methods [#2152](https://github.com/ruflin/Elastica/pull/2152)
### Changed
* Updated `php-cs-fixer` to `3.13.2` [#2143](https://github.com/ruflin/Elastica/pull/2143)
* Modernize code using `match` expression [#2141](https://github.com/ruflin/Elastica/pull/2141)
Expand Down
13 changes: 11 additions & 2 deletions src/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Elastica\Bulk\Action\AbstractDocument as AbstractDocumentAction;
use Elastica\Bulk\Response as BulkResponse;
use Elastica\Bulk\ResponseSet;
use Elastica\Exception\Bulk\ResponseException;
use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
use Elastica\Exception\ClientException;
use Elastica\Exception\ConnectionException;
use Elastica\Exception\InvalidException;
use Elastica\Exception\RequestEntityTooLargeException;
use Elastica\Exception\ResponseException;
use Elastica\Script\AbstractScript;

class Bulk
Expand Down Expand Up @@ -274,6 +276,13 @@ public function toArray(): array
return $data;
}

/**
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
* @throws BulkResponseException
* @throws InvalidException
*/
public function send(): ResponseSet
{
$response = $this->_client->request($this->getPath(), Request::POST, (string) $this, $this->_requestParams, Request::NDJSON_CONTENT_TYPE);
Expand All @@ -282,7 +291,7 @@ public function send(): ResponseSet
}

/**
* @throws ResponseException
* @throws BulkResponseException
* @throws InvalidException
*/
protected function _processResponse(Response $response): ResponseSet
Expand Down
48 changes: 46 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Elastica\Bulk\Action;
use Elastica\Bulk\ResponseSet;
use Elastica\Exception\Bulk\ResponseException as BulkResponseException;
use Elastica\Exception\ClientException;
use Elastica\Exception\ConnectionException;
use Elastica\Exception\InvalidException;
Expand Down Expand Up @@ -86,6 +87,10 @@ public function __construct($config = [], ?callable $callback = null, ?LoggerInt

/**
* Get current version.
*
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
*/
public function getVersion(): string
{
Expand Down Expand Up @@ -203,7 +208,11 @@ public function removeHeader(string $header): self
*
* @param array|Document[] $docs Array of Elastica\Document
*
* @throws InvalidException If docs is empty
* @throws InvalidException If docs is empty
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
* @throws BulkResponseException
*/
public function updateDocuments(array $docs, array $requestParams = []): ResponseSet
{
Expand Down Expand Up @@ -232,7 +241,11 @@ public function updateDocuments(array $docs, array $requestParams = []): Respons
*
* @param array|Document[] $docs Array of Elastica\Document
*
* @throws InvalidException If docs is empty
* @throws InvalidException If docs is empty
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
* @throws BulkResponseException
*/
public function addDocuments(array $docs, array $requestParams = []): ResponseSet
{
Expand Down Expand Up @@ -260,6 +273,10 @@ public function addDocuments(array $docs, array $requestParams = []): ResponseSe
* @param array $options array of query params to use for query. For possible options check es api
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
*
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
*/
public function updateDocument($id, $data, $index, array $options = []): Response
{
Expand Down Expand Up @@ -321,6 +338,10 @@ public function updateDocument($id, $data, $index, array $options = []): Respons
* @param array|Document[] $docs
*
* @throws InvalidException
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
* @throws BulkResponseException
*/
public function deleteDocuments(array $docs, array $requestParams = []): ResponseSet
{
Expand Down Expand Up @@ -434,6 +455,10 @@ public function setConnections(array $connections)
* @param bool|string $routing Optional routing key for all ids
*
* @throws InvalidException
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
* @throws BulkResponseException
*/
public function deleteIds(array $ids, $index, $routing = false): ResponseSet
{
Expand Down Expand Up @@ -478,6 +503,9 @@ public function deleteIds(array $ids, $index, $routing = false): ResponseSet
*
* @throws ResponseException
* @throws InvalidException
* @throws ClientException
* @throws ConnectionException
* @throws BulkResponseException
*/
public function bulk(array $params): ResponseSet
{
Expand Down Expand Up @@ -542,6 +570,10 @@ public function request(string $path, string $method = Request::GET, $data = [],

/**
* Makes calls to the elasticsearch server with usage official client Endpoint.
*
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
*/
public function requestEndpoint(AbstractEndpoint $endpoint): Response
{
Expand All @@ -559,6 +591,10 @@ public function requestEndpoint(AbstractEndpoint $endpoint): Response
* @param array $args OPTIONAL Optional arguments
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html
*
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
*/
public function forcemergeAll($args = []): Response
{
Expand All @@ -572,6 +608,10 @@ public function forcemergeAll($args = []): Response
* Closes the given PointInTime.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html#close-point-in-time-api
*
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
*/
public function closePointInTime(string $pointInTimeId): Response
{
Expand All @@ -585,6 +625,10 @@ public function closePointInTime(string $pointInTimeId): Response
* Refreshes all search indices.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html
*
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
*/
public function refreshAll(): Response
{
Expand Down
7 changes: 7 additions & 0 deletions src/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Elastica\Cluster\Health;
use Elastica\Cluster\Settings;
use Elastica\Exception\ClientException;
use Elastica\Exception\ConnectionException;
use Elastica\Exception\ResponseException;
use Elasticsearch\Endpoints\Cluster\State;

/**
Expand Down Expand Up @@ -47,6 +50,10 @@ public function __construct(Client $client)

/**
* Refreshes all cluster information (state).
*
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
*/
public function refresh(): void
{
Expand Down
7 changes: 7 additions & 0 deletions src/Cluster/Health.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Elastica\Client;
use Elastica\Cluster\Health\Index;
use Elastica\Exception\ClientException;
use Elastica\Exception\ConnectionException;
use Elastica\Exception\ResponseException;

/**
* Elastic cluster health.
Expand Down Expand Up @@ -175,6 +178,10 @@ public function getIndices(): array

/**
* Retrieves the health data from the cluster.
*
* @throws ClientException
* @throws ConnectionException
* @throws ResponseException
*/
protected function _retrieveHealthData(): array
{
Expand Down
Loading