From 6dc652379d54ac623a83847c8240e13d6d8fb60b Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Wed, 18 Dec 2024 10:45:47 +1100 Subject: [PATCH] Address @stof feedback Signed-off-by: Kim Pepper --- UPGRADING.md | 4 ++-- src/OpenSearch/Aws/SigningClientDecorator.php | 5 ----- .../Common/Exceptions/BadMethodCallException.php | 2 +- src/OpenSearch/EndpointInterface.php | 4 +++- src/OpenSearch/Endpoints/AbstractEndpoint.php | 2 +- src/OpenSearch/Namespaces/BooleanRequestWrapper.php | 12 +++++++++--- src/OpenSearch/RequestFactoryInterface.php | 4 ++++ src/OpenSearch/TransportInterface.php | 6 +++++- tests/Endpoints/AbstractEndpointTest.php | 2 +- 9 files changed, 26 insertions(+), 15 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 361098fd..d624fea9 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -1,12 +1,12 @@ - [Upgrading OpenSearch PHP Client](#upgrading-opensearch-php-client) - - [Upgrading to >= 2.0.0](#upgrading-to--200) + - [Upgrading to >= 2.0.0](#upgrading-to--240) - [HTTP Client Auto-Discovery](#http-client-auto-discovery) - [Configuring Guzzle HTTP Client in 2.x](#configuring-guzzle-http-client-in-2x) - [Configuring Symfony HTTP Client in 2.x](#configuring-symfony-http-client-in-2x) # Upgrading OpenSearch PHP Client -## Upgrading to >= 2.0.0 +## Upgrading to >= 2.4.0 openseach-php removes the hard-coded dependency on the [Guzzle HTTP client](https://docs.guzzlephp.org/en/stable/#) and switches to the following PSR interfaces: diff --git a/src/OpenSearch/Aws/SigningClientDecorator.php b/src/OpenSearch/Aws/SigningClientDecorator.php index 58f11764..e54752f3 100644 --- a/src/OpenSearch/Aws/SigningClientDecorator.php +++ b/src/OpenSearch/Aws/SigningClientDecorator.php @@ -18,11 +18,6 @@ public function __construct( protected CredentialsInterface $credentials, protected SignatureInterface $signer, ) { - if (!class_exists(SignatureInterface::class)) { - throw new \RuntimeException( - 'The AWS SDK for PHP must be installed in order to use the AWS signing client.' - ); - } } public function sendRequest(RequestInterface $request): ResponseInterface diff --git a/src/OpenSearch/Common/Exceptions/BadMethodCallException.php b/src/OpenSearch/Common/Exceptions/BadMethodCallException.php index a562f01d..0dfe1fec 100644 --- a/src/OpenSearch/Common/Exceptions/BadMethodCallException.php +++ b/src/OpenSearch/Common/Exceptions/BadMethodCallException.php @@ -21,7 +21,7 @@ namespace OpenSearch\Common\Exceptions; -@trigger_error(__CLASS__ . ' is deprecated in 2.3.2 and will be removed in 3.0.0.', E_USER_DEPRECATED); +@trigger_error(BadMethodCallException::class . ' is deprecated in 2.3.2 and will be removed in 3.0.0.', E_USER_DEPRECATED); /** * BadMethodCallException diff --git a/src/OpenSearch/EndpointInterface.php b/src/OpenSearch/EndpointInterface.php index 6beeb406..f29783df 100644 --- a/src/OpenSearch/EndpointInterface.php +++ b/src/OpenSearch/EndpointInterface.php @@ -67,10 +67,12 @@ public function setId(int|string|null $docID): static; /** * Get the body of the request. */ - public function getBody(): string|iterable|null; + public function getBody(): string|array|null; /** * Set the body of the request. + * + * @param string|iterable|null $body */ public function setBody(string|iterable|null $body): static; diff --git a/src/OpenSearch/Endpoints/AbstractEndpoint.php b/src/OpenSearch/Endpoints/AbstractEndpoint.php index 49b3411b..31c19c09 100644 --- a/src/OpenSearch/Endpoints/AbstractEndpoint.php +++ b/src/OpenSearch/Endpoints/AbstractEndpoint.php @@ -150,7 +150,7 @@ public function setId(int|string|null $docID): static return $this; } - public function getBody(): string|iterable|null + public function getBody(): string|array|null { return $this->body; } diff --git a/src/OpenSearch/Namespaces/BooleanRequestWrapper.php b/src/OpenSearch/Namespaces/BooleanRequestWrapper.php index 4b3ed9b3..1e6f55b5 100644 --- a/src/OpenSearch/Namespaces/BooleanRequestWrapper.php +++ b/src/OpenSearch/Namespaces/BooleanRequestWrapper.php @@ -34,7 +34,10 @@ abstract class BooleanRequestWrapper /** * Send a request with a boolean response. * - * Throwing a client exception will return FALSE, otherwise TRUE is returned. + * @return bool + * Returns FALSE for a 404 error, otherwise TRUE. + * + * @throws \Psr\Http\Client\ClientExceptionInterface */ public static function sendRequest(AbstractEndpoint $endpoint, TransportInterface $transport): bool { @@ -46,8 +49,11 @@ public static function sendRequest(AbstractEndpoint $endpoint, TransportInterfac $endpoint->getBody(), $endpoint->getOptions() ); - } catch (ClientExceptionInterface) { - return false; + } catch (ClientExceptionInterface $e) { + if ($e->getCode() === 404) { + return false; + } + throw $e; } return true; } diff --git a/src/OpenSearch/RequestFactoryInterface.php b/src/OpenSearch/RequestFactoryInterface.php index 291132be..46562496 100644 --- a/src/OpenSearch/RequestFactoryInterface.php +++ b/src/OpenSearch/RequestFactoryInterface.php @@ -8,6 +8,10 @@ interface RequestFactoryInterface { /** * Create a new request. + * + * @param array $params + * @param string|array|null $body + * @param array $headers */ public function createRequest( string $method, diff --git a/src/OpenSearch/TransportInterface.php b/src/OpenSearch/TransportInterface.php index 909c3bc4..5346fee0 100644 --- a/src/OpenSearch/TransportInterface.php +++ b/src/OpenSearch/TransportInterface.php @@ -10,13 +10,17 @@ interface TransportInterface /** * Create a new request. * + * @param array $params + * @param string|array|null $body + * @param array $headers + * * @throws \Psr\Http\Client\ClientExceptionInterface */ public function sendRequest( string $method, string $uri, array $params = [], - mixed $body = null, + string|array|null $body = null, array $headers = [], ): array|string|null; diff --git a/tests/Endpoints/AbstractEndpointTest.php b/tests/Endpoints/AbstractEndpointTest.php index a2da5295..5c28ca69 100644 --- a/tests/Endpoints/AbstractEndpointTest.php +++ b/tests/Endpoints/AbstractEndpointTest.php @@ -31,7 +31,7 @@ */ class AbstractEndpointTest extends TestCase { - private EndpointInterface|MockObject $endpoint; + private EndpointInterface&MockObject $endpoint; protected function setUp(): void {