From fbb82dd68ceead0a60dae53c053e060020e6536c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Vannicatte?= Date: Mon, 2 May 2022 10:32:24 +0200 Subject: [PATCH] chore:format PHP --- .github/.cache_version | 2 +- .../.php-cs-fixer.php | 10 +- .../algoliasearch-client-php/composer.json | 86 ++++++------ .../algoliasearch-client-php/lib/Algolia.php | 4 +- .../lib/ApiException.php | 8 +- .../lib/Cache/FileCacheDriver.php | 7 +- .../lib/Configuration/ConfigWithRegion.php | 8 +- .../lib/Exceptions/UnreachableException.php | 3 +- .../lib/Http/GuzzleHttpClient.php | 23 +--- .../lib/Http/HttpClientInterface.php | 6 +- .../lib/Http/Psr7/BufferStream.php | 4 +- .../lib/Http/Psr7/PumpStream.php | 4 +- .../lib/Http/Psr7/Request.php | 18 ++- .../lib/Http/Psr7/Response.php | 10 +- .../lib/Http/Psr7/Stream.php | 52 ++++++-- .../lib/Http/Psr7/Uri.php | 114 ++++++++++------ .../lib/Http/Psr7/UriResolver.php | 74 +++++++--- .../lib/Http/Psr7/functions.php | 4 +- .../lib/ObjectSerializer.php | 126 +++++++++++++++--- .../RequestOptions/RequestOptionsFactory.php | 40 +++--- .../lib/RetryStrategy/ApiWrapper.php | 107 +++++++++++---- .../lib/RetryStrategy/ApiWrapperInterface.php | 15 ++- .../lib/RetryStrategy/ClusterHosts.php | 17 ++- .../lib/RetryStrategy/HostCollection.php | 10 +- .../lib/Support/Helpers.php | 4 +- .../lib/Support/UserAgent.php | 15 ++- config/generation.config.js | 14 +- openapitools.json | 2 +- 28 files changed, 550 insertions(+), 237 deletions(-) diff --git a/.github/.cache_version b/.github/.cache_version index 21a050b43e..d3d9cd8270 100644 --- a/.github/.cache_version +++ b/.github/.cache_version @@ -1 +1 @@ -9.2.2 +9.2.3 diff --git a/clients/algoliasearch-client-php/.php-cs-fixer.php b/clients/algoliasearch-client-php/.php-cs-fixer.php index 90c95dcf68..09ac266976 100644 --- a/clients/algoliasearch-client-php/.php-cs-fixer.php +++ b/clients/algoliasearch-client-php/.php-cs-fixer.php @@ -5,7 +5,7 @@ return $config ->setUsingCache(true) ->setRules([ - 'array_syntax' => [ 'syntax' => 'short' ], + 'array_syntax' => ['syntax' => 'short'], 'blank_line_after_namespace' => false, 'blank_line_after_opening_tag' => true, 'blank_line_before_statement' => true, @@ -43,7 +43,7 @@ 'phpdoc_tag_type' => true, 'protected_to_private' => true, '@PSR2' => true, - 'short_scalar_cast' => true, + 'short_scalar_cast' => true, 'single_blank_line_at_eof' => false, 'single_blank_line_before_namespace' => true, 'single_quote' => true, @@ -57,7 +57,7 @@ ]) ->setFinder( PhpCsFixer\Finder::create() - ->exclude('test') - ->exclude('tests') - ->in(__DIR__) + ->exclude('test') + ->exclude('tests') + ->in(__DIR__) ); diff --git a/clients/algoliasearch-client-php/composer.json b/clients/algoliasearch-client-php/composer.json index 2b05cd1e41..b84aa57709 100644 --- a/clients/algoliasearch-client-php/composer.json +++ b/clients/algoliasearch-client-php/composer.json @@ -1,45 +1,49 @@ { - "name": "algolia/algoliasearch-client-php", - "description": "API powering the features of Algolia.", - "keywords": [ - "openapitools", - "openapi-generator", - "openapi", - "php", - "sdk", - "rest", - "api" - ], - "homepage": "https://openapi-generator.tech", - "license": "unlicense", - "authors": [ - { - "name": "OpenAPI-Generator contributors", - "homepage": "https://openapi-generator.tech" - } - ], - "require": { - "php": "^7.3 || ^8.0", - "ext-curl": "*", - "ext-json": "*", - "ext-mbstring": "*", - "guzzlehttp/guzzle": "^7.3", - "guzzlehttp/psr7": "^2.0", - "psr/http-message": "^1.0", - "psr/log": "^1.0 || ^2.0 || ^3.0", - "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" - }, - "require-dev": { - "friendsofphp/php-cs-fixer": "^3.5.0", - "phpunit/phpunit": "^9.3" - }, - "autoload": { - "psr-4": { "Algolia\\AlgoliaSearch\\" : "lib/" }, - "files": [ - "lib/Http/Psr7/functions.php" - ] + "name": "algolia/algoliasearch-client-php", + "description": "API powering the features of Algolia.", + "keywords": [ + "openapitools", + "openapi-generator", + "openapi", + "php", + "sdk", + "rest", + "api" + ], + "homepage": "https://openapi-generator.tech", + "license": "unlicense", + "authors": [ + { + "name": "OpenAPI-Generator contributors", + "homepage": "https://openapi-generator.tech" + } + ], + "require": { + "php": "^7.3 || ^8.0", + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*", + "guzzlehttp/guzzle": "^7.3", + "guzzlehttp/psr7": "^2.0", + "psr/http-message": "^1.0", + "psr/log": "^1.0 || ^2.0 || ^3.0", + "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.5.0", + "phpunit/phpunit": "^9.3" + }, + "autoload": { + "psr-4": { + "Algolia\\AlgoliaSearch\\": "lib/" }, - "autoload-dev": { - "psr-4": { "Algolia\\AlgoliaSearch\\Test\\" : "test/" } + "files": [ + "lib/Http/Psr7/functions.php" + ] + }, + "autoload-dev": { + "psr-4": { + "Algolia\\AlgoliaSearch\\Test\\": "test/" } + } } diff --git a/clients/algoliasearch-client-php/lib/Algolia.php b/clients/algoliasearch-client-php/lib/Algolia.php index c9aede0df0..9886e42899 100644 --- a/clients/algoliasearch-client-php/lib/Algolia.php +++ b/clients/algoliasearch-client-php/lib/Algolia.php @@ -87,7 +87,9 @@ public static function setLogger(LoggerInterface $logger) public static function getHttpClient() { if (null === self::$httpClient) { - self::setHttpClient(new \Algolia\AlgoliaSearch\Http\GuzzleHttpClient()); + self::setHttpClient( + new \Algolia\AlgoliaSearch\Http\GuzzleHttpClient() + ); } return self::$httpClient; diff --git a/clients/algoliasearch-client-php/lib/ApiException.php b/clients/algoliasearch-client-php/lib/ApiException.php index d484a88eb5..7ff8c3721b 100644 --- a/clients/algoliasearch-client-php/lib/ApiException.php +++ b/clients/algoliasearch-client-php/lib/ApiException.php @@ -41,8 +41,12 @@ class ApiException extends Exception * @param string[]|null $responseHeaders HTTP response header * @param \stdClass|string|null $responseBody HTTP decoded body of the server response either as \stdClass or string */ - public function __construct($message = '', $code = 0, $responseHeaders = [], $responseBody = null) - { + public function __construct( + $message = '', + $code = 0, + $responseHeaders = [], + $responseBody = null + ) { parent::__construct($message, $code); $this->responseHeaders = $responseHeaders; $this->responseBody = $responseBody; diff --git a/clients/algoliasearch-client-php/lib/Cache/FileCacheDriver.php b/clients/algoliasearch-client-php/lib/Cache/FileCacheDriver.php index 86bcba64c9..ecffd3b544 100644 --- a/clients/algoliasearch-client-php/lib/Cache/FileCacheDriver.php +++ b/clients/algoliasearch-client-php/lib/Cache/FileCacheDriver.php @@ -12,7 +12,8 @@ final class FileCacheDriver implements CacheInterface public function __construct($directory) { - $this->directory = rtrim($directory, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR; + $this->directory = + rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; } /** @@ -49,7 +50,7 @@ public function delete($key) public function clear() { $result = true; - foreach (glob($this->directory.self::PREFIX.'*') as $file) { + foreach (glob($this->directory . self::PREFIX . '*') as $file) { $result &= @unlink($file); } @@ -110,7 +111,7 @@ public function has($key) */ private function getFilenameFromKey($key) { - $name = $this->directory.self::PREFIX.$key; + $name = $this->directory . self::PREFIX . $key; return str_replace('\\', '-', $name); } diff --git a/clients/algoliasearch-client-php/lib/Configuration/ConfigWithRegion.php b/clients/algoliasearch-client-php/lib/Configuration/ConfigWithRegion.php index 42e334c1e9..a116c4dfac 100644 --- a/clients/algoliasearch-client-php/lib/Configuration/ConfigWithRegion.php +++ b/clients/algoliasearch-client-php/lib/Configuration/ConfigWithRegion.php @@ -6,8 +6,12 @@ abstract class ConfigWithRegion extends Configuration { - public static function create($appId, $apiKey, $region = null, $allowedRegions = null) - { + public static function create( + $appId, + $apiKey, + $region = null, + $allowedRegions = null + ) { if ($region !== null && !in_array($region, $allowedRegions, true)) { throw new AlgoliaException('Specified region is not allowed.'); } diff --git a/clients/algoliasearch-client-php/lib/Exceptions/UnreachableException.php b/clients/algoliasearch-client-php/lib/Exceptions/UnreachableException.php index 82e89a2c7a..d4b6e24d40 100644 --- a/clients/algoliasearch-client-php/lib/Exceptions/UnreachableException.php +++ b/clients/algoliasearch-client-php/lib/Exceptions/UnreachableException.php @@ -7,7 +7,8 @@ final class UnreachableException extends AlgoliaException public function __construct($message = '', $code = 0, $previous = null) { if (!$message) { - $message = 'Impossible to connect, please check your Algolia Application Id.'; + $message = + 'Impossible to connect, please check your Algolia Application Id.'; } parent::__construct($message, $code, $previous); diff --git a/clients/algoliasearch-client-php/lib/Http/GuzzleHttpClient.php b/clients/algoliasearch-client-php/lib/Http/GuzzleHttpClient.php index 03677d6730..1ddc0874b3 100644 --- a/clients/algoliasearch-client-php/lib/Http/GuzzleHttpClient.php +++ b/clients/algoliasearch-client-php/lib/Http/GuzzleHttpClient.php @@ -19,8 +19,11 @@ public function __construct(GuzzleClient $client = null) $this->client = $client ?: static::buildClient(); } - public function sendRequest(RequestInterface $request, $timeout, $connectTimeout) - { + public function sendRequest( + RequestInterface $request, + $timeout, + $connectTimeout + ) { try { $response = $this->client->send($request, [ 'timeout' => $timeout, @@ -31,21 +34,9 @@ public function sendRequest(RequestInterface $request, $timeout, $connectTimeout return $e->getResponse(); } - return new Response( - 0, - [], - null, - '1.1', - $e->getMessage() - ); + return new Response(0, [], null, '1.1', $e->getMessage()); } catch (ConnectException $e) { - return new Response( - 0, - [], - null, - '1.1', - $e->getMessage() - ); + return new Response(0, [], null, '1.1', $e->getMessage()); } return $response; diff --git a/clients/algoliasearch-client-php/lib/Http/HttpClientInterface.php b/clients/algoliasearch-client-php/lib/Http/HttpClientInterface.php index 1e4985365d..8bc7bc3e6e 100644 --- a/clients/algoliasearch-client-php/lib/Http/HttpClientInterface.php +++ b/clients/algoliasearch-client-php/lib/Http/HttpClientInterface.php @@ -20,5 +20,9 @@ interface HttpClientInterface * * @return ResponseInterface */ - public function sendRequest(RequestInterface $request, $timeout, $connectTimeout); + public function sendRequest( + RequestInterface $request, + $timeout, + $connectTimeout + ); } diff --git a/clients/algoliasearch-client-php/lib/Http/Psr7/BufferStream.php b/clients/algoliasearch-client-php/lib/Http/Psr7/BufferStream.php index b415beaa6a..7e8e88fa3f 100644 --- a/clients/algoliasearch-client-php/lib/Http/Psr7/BufferStream.php +++ b/clients/algoliasearch-client-php/lib/Http/Psr7/BufferStream.php @@ -92,7 +92,9 @@ public function eof() public function tell() { - throw new \RuntimeException('Cannot determine the position of a BufferStream'); + throw new \RuntimeException( + 'Cannot determine the position of a BufferStream' + ); } /** diff --git a/clients/algoliasearch-client-php/lib/Http/Psr7/PumpStream.php b/clients/algoliasearch-client-php/lib/Http/Psr7/PumpStream.php index 86786edb6f..541eec189e 100644 --- a/clients/algoliasearch-client-php/lib/Http/Psr7/PumpStream.php +++ b/clients/algoliasearch-client-php/lib/Http/Psr7/PumpStream.php @@ -47,7 +47,9 @@ public function __construct(callable $source, array $options = []) { $this->source = $source; $this->size = isset($options['size']) ? $options['size'] : null; - $this->metadata = isset($options['metadata']) ? $options['metadata'] : []; + $this->metadata = isset($options['metadata']) + ? $options['metadata'] + : []; $this->buffer = new BufferStream(); } diff --git a/clients/algoliasearch-client-php/lib/Http/Psr7/Request.php b/clients/algoliasearch-client-php/lib/Http/Psr7/Request.php index 43a6ba024c..6749b9eb04 100644 --- a/clients/algoliasearch-client-php/lib/Http/Psr7/Request.php +++ b/clients/algoliasearch-client-php/lib/Http/Psr7/Request.php @@ -80,7 +80,7 @@ public function getRequestTarget() $target = '/'; } if ('' !== $this->uri->getQuery()) { - $target .= '?'.$this->uri->getQuery(); + $target .= '?' . $this->uri->getQuery(); } return $target; @@ -89,7 +89,9 @@ public function getRequestTarget() public function withRequestTarget($requestTarget) { if (preg_match('#\s#', $requestTarget)) { - throw new InvalidArgumentException('Invalid request target provided; cannot contain whitespace'); + throw new InvalidArgumentException( + 'Invalid request target provided; cannot contain whitespace' + ); } $new = clone $this; @@ -141,7 +143,7 @@ private function updateHostFromUri() } if (null !== ($port = $this->uri->getPort())) { - $host .= ':'.$port; + $host .= ':' . $port; } if (isset($this->headerNames['host'])) { @@ -224,7 +226,10 @@ public function withAddedHeader($header, $value) $new = clone $this; if (isset($new->headerNames[$normalized])) { $header = $this->headerNames[$normalized]; - $new->headers[$header] = array_merge($this->headers[$header], $value); + $new->headers[$header] = array_merge( + $this->headers[$header], + $value + ); } else { $new->headerNames[$normalized] = $header; $new->headers[$header] = $value; @@ -277,7 +282,10 @@ private function setHeaders(array $headers) $normalized = mb_strtolower($header); if (isset($this->headerNames[$normalized])) { $header = $this->headerNames[$normalized]; - $this->headers[$header] = array_merge($this->headers[$header], $value); + $this->headers[$header] = array_merge( + $this->headers[$header], + $value + ); } else { $this->headerNames[$normalized] = $header; $this->headers[$header] = $value; diff --git a/clients/algoliasearch-client-php/lib/Http/Psr7/Response.php b/clients/algoliasearch-client-php/lib/Http/Psr7/Response.php index ee338a823b..3c451ea53b 100644 --- a/clients/algoliasearch-client-php/lib/Http/Psr7/Response.php +++ b/clients/algoliasearch-client-php/lib/Http/Psr7/Response.php @@ -225,7 +225,10 @@ public function withAddedHeader($header, $value) $new = clone $this; if (isset($new->headerNames[$normalized])) { $header = $this->headerNames[$normalized]; - $new->headers[$header] = array_merge($this->headers[$header], $value); + $new->headers[$header] = array_merge( + $this->headers[$header], + $value + ); } else { $new->headerNames[$normalized] = $header; $new->headers[$header] = $value; @@ -283,7 +286,10 @@ private function setHeaders(array $headers) $normalized = mb_strtolower($header); if (isset($this->headerNames[$normalized])) { $header = $this->headerNames[$normalized]; - $this->headers[$header] = array_merge($this->headers[$header], $value); + $this->headers[$header] = array_merge( + $this->headers[$header], + $value + ); } else { $this->headerNames[$normalized] = $header; $this->headers[$header] = $value; diff --git a/clients/algoliasearch-client-php/lib/Http/Psr7/Stream.php b/clients/algoliasearch-client-php/lib/Http/Psr7/Stream.php index 818864e06d..245af27075 100644 --- a/clients/algoliasearch-client-php/lib/Http/Psr7/Stream.php +++ b/clients/algoliasearch-client-php/lib/Http/Psr7/Stream.php @@ -28,16 +28,41 @@ class Stream implements StreamInterface /** @var array Hash of readable and writable stream types */ private static $readWriteHash = [ 'read' => [ - 'r' => true, 'w+' => true, 'r+' => true, 'x+' => true, 'c+' => true, - 'rb' => true, 'w+b' => true, 'r+b' => true, 'x+b' => true, - 'c+b' => true, 'rt' => true, 'w+t' => true, 'r+t' => true, - 'x+t' => true, 'c+t' => true, 'a+' => true, + 'r' => true, + 'w+' => true, + 'r+' => true, + 'x+' => true, + 'c+' => true, + 'rb' => true, + 'w+b' => true, + 'r+b' => true, + 'x+b' => true, + 'c+b' => true, + 'rt' => true, + 'w+t' => true, + 'r+t' => true, + 'x+t' => true, + 'c+t' => true, + 'a+' => true, ], 'write' => [ - 'w' => true, 'w+' => true, 'rw' => true, 'r+' => true, 'x+' => true, - 'c+' => true, 'wb' => true, 'w+b' => true, 'r+b' => true, - 'x+b' => true, 'c+b' => true, 'w+t' => true, 'r+t' => true, - 'x+t' => true, 'c+t' => true, 'a' => true, 'a+' => true, + 'w' => true, + 'w+' => true, + 'rw' => true, + 'r+' => true, + 'x+' => true, + 'c+' => true, + 'wb' => true, + 'w+b' => true, + 'r+b' => true, + 'x+b' => true, + 'c+b' => true, + 'w+t' => true, + 'r+t' => true, + 'x+t' => true, + 'c+t' => true, + 'a' => true, + 'a+' => true, ], ]; @@ -213,7 +238,12 @@ public function seek($offset, $whence = SEEK_SET) throw new \RuntimeException('Stream is not seekable'); } if (-1 === fseek($this->stream, $offset, $whence)) { - throw new \RuntimeException('Unable to seek to stream position '.$offset.' with whence '.var_export($whence, true)); + throw new \RuntimeException( + 'Unable to seek to stream position ' . + $offset . + ' with whence ' . + var_export($whence, true) + ); } } @@ -247,7 +277,9 @@ public function write($string) throw new \RuntimeException('Stream is detached'); } if (!$this->writable) { - throw new \RuntimeException('Cannot write to a non-writable stream'); + throw new \RuntimeException( + 'Cannot write to a non-writable stream' + ); } // We can't know the size after writing anything diff --git a/clients/algoliasearch-client-php/lib/Http/Psr7/Uri.php b/clients/algoliasearch-client-php/lib/Http/Psr7/Uri.php index 9d532477ac..be00f82fbe 100644 --- a/clients/algoliasearch-client-php/lib/Http/Psr7/Uri.php +++ b/clients/algoliasearch-client-php/lib/Http/Psr7/Uri.php @@ -75,7 +75,9 @@ public function __construct($uri = '') if ('' !== $uri) { $parts = parse_url($uri); if (false === $parts) { - throw new \InvalidArgumentException("Unable to parse URI: $uri"); + throw new \InvalidArgumentException( + "Unable to parse URI: $uri" + ); } $this->applyParts($parts); } @@ -118,27 +120,32 @@ public function __toString() * * @see https://tools.ietf.org/html/rfc3986#section-5.3 */ - public static function composeComponents($scheme, $authority, $path, $query, $fragment) - { + public static function composeComponents( + $scheme, + $authority, + $path, + $query, + $fragment + ) { $uri = ''; // weak type checks to also accept null until we can add scalar type hints if ('' !== $scheme) { - $uri .= $scheme.':'; + $uri .= $scheme . ':'; } if ('' !== $authority || 'file' === $scheme) { - $uri .= '//'.$authority; + $uri .= '//' . $authority; } $uri .= $path; if ('' !== $query) { - $uri .= '?'.$query; + $uri .= '?' . $query; } if ('' !== $fragment) { - $uri .= '#'.$fragment; + $uri .= '#' . $fragment; } return $uri; @@ -154,8 +161,9 @@ public static function composeComponents($scheme, $authority, $path, $query, $fr */ public static function isDefaultPort(UriInterface $uri) { - return null === $uri->getPort() - || (isset(self::$defaultPorts[$uri->getScheme()]) && $uri->getPort() === self::$defaultPorts[$uri->getScheme()]); + return null === $uri->getPort() || + (isset(self::$defaultPorts[$uri->getScheme()]) && + $uri->getPort() === self::$defaultPorts[$uri->getScheme()]); } /** @@ -207,10 +215,10 @@ public static function isAbsolutePathReference(UriInterface $uri) { $path = $uri->getPath(); - return '' === $uri->getScheme() - && '' === $uri->getAuthority() - && isset($path[0]) - && '/' === $path[0]; + return '' === $uri->getScheme() && + '' === $uri->getAuthority() && + isset($path[0]) && + '/' === $path[0]; } /** @@ -226,9 +234,9 @@ public static function isRelativePathReference(UriInterface $uri) { $path = $uri->getPath(); - return '' === $uri->getScheme() - && '' === $uri->getAuthority() - && (!isset($path[0]) || '/' !== $path[0]); + return '' === $uri->getScheme() && + '' === $uri->getAuthority() && + (!isset($path[0]) || '/' !== $path[0]); } /** @@ -245,18 +253,23 @@ public static function isRelativePathReference(UriInterface $uri) * * @see https://tools.ietf.org/html/rfc3986#section-4.4 */ - public static function isSameDocumentReference(UriInterface $uri, UriInterface $base = null) - { + public static function isSameDocumentReference( + UriInterface $uri, + UriInterface $base = null + ) { if (null !== $base) { $uri = UriResolver::resolve($base, $uri); - return ($uri->getScheme() === $base->getScheme()) - && ($uri->getAuthority() === $base->getAuthority()) - && ($uri->getPath() === $base->getPath()) - && ($uri->getQuery() === $base->getQuery()); + return $uri->getScheme() === $base->getScheme() && + $uri->getAuthority() === $base->getAuthority() && + $uri->getPath() === $base->getPath() && + $uri->getQuery() === $base->getQuery(); } - return '' === $uri->getScheme() && '' === $uri->getAuthority() && '' === $uri->getPath() && '' === $uri->getQuery(); + return '' === $uri->getScheme() && + '' === $uri->getAuthority() && + '' === $uri->getPath() && + '' === $uri->getQuery(); } /** @@ -313,7 +326,9 @@ public static function withoutQueryValue(UriInterface $uri, $key) } $decodedKey = rawurldecode($key); - $result = array_filter(explode('&', $current), function ($part) use ($decodedKey) { + $result = array_filter(explode('&', $current), function ($part) use ( + $decodedKey + ) { $parts = explode('=', $part); return rawurldecode($parts[0]) !== $decodedKey; @@ -345,7 +360,9 @@ public static function withQueryValue(UriInterface $uri, $key, $value) $result = []; } else { $decodedKey = rawurldecode($key); - $result = array_filter(explode('&', $current), function ($part) use ($decodedKey) { + $result = array_filter(explode('&', $current), function ( + $part + ) use ($decodedKey) { $parts = explode('=', $part); return rawurldecode($parts[0]) !== $decodedKey; @@ -358,7 +375,7 @@ public static function withQueryValue(UriInterface $uri, $key, $value) $key = strtr($key, self::$replaceQuery); if (null !== $value) { - $result[] = $key.'='.strtr($value, self::$replaceQuery); + $result[] = $key . '=' . strtr($value, self::$replaceQuery); } else { $result[] = $key; } @@ -394,11 +411,11 @@ public function getAuthority() { $authority = $this->host; if ('' !== $this->userInfo) { - $authority = $this->userInfo.'@'.$authority; + $authority = $this->userInfo . '@' . $authority; } if (null !== $this->port) { - $authority .= ':'.$this->port; + $authority .= ':' . $this->port; } return $authority; @@ -454,7 +471,7 @@ public function withUserInfo($user, $password = null) { $info = $user; if ('' !== $password) { - $info .= ':'.$password; + $info .= ':' . $password; } if ($this->userInfo === $info) { @@ -569,7 +586,7 @@ private function applyParts(array $parts) ? $this->filterQueryAndFragment($parts['fragment']) : ''; if (isset($parts['pass'])) { - $this->userInfo .= ':'.$parts['pass']; + $this->userInfo .= ':' . $parts['pass']; } $this->removeDefaultPort(); @@ -625,7 +642,9 @@ private function filterPort($port) $port = (int) $port; if (1 > $port || 0xffff < $port) { - throw new \InvalidArgumentException(sprintf('Invalid port: %d. Must be between 1 and 65535', $port)); + throw new \InvalidArgumentException( + sprintf('Invalid port: %d. Must be between 1 and 65535', $port) + ); } return $port; @@ -655,7 +674,10 @@ private function filterPath($path) } return preg_replace_callback( - '/(?:[^'.self::$charUnreserved.self::$charSubDelims.'%:@\/]++|%(?![A-Fa-f0-9]{2}))/', + '/(?:[^' . + self::$charUnreserved . + self::$charSubDelims . + '%:@\/]++|%(?![A-Fa-f0-9]{2}))/', [$this, 'rawurlencodeMatchZero'], $path ); @@ -674,11 +696,16 @@ private function filterPath($path) private function filterQueryAndFragment($str) { if (!is_string($str)) { - throw new \InvalidArgumentException('Query and fragment must be a string'); + throw new \InvalidArgumentException( + 'Query and fragment must be a string' + ); } return preg_replace_callback( - '/(?:[^'.self::$charUnreserved.self::$charSubDelims.'%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/', + '/(?:[^' . + self::$charUnreserved . + self::$charSubDelims . + '%:@\/\?]++|%(?![A-Fa-f0-9]{2}))/', [$this, 'rawurlencodeMatchZero'], $str ); @@ -691,25 +718,32 @@ private function rawurlencodeMatchZero(array $match) private function validateState() { - if ('' === $this->host && ('http' === $this->scheme || 'https' === $this->scheme)) { + if ( + '' === $this->host && + ('http' === $this->scheme || 'https' === $this->scheme) + ) { $this->host = self::HTTP_DEFAULT_HOST; } if ('' === $this->getAuthority()) { if (0 === mb_strpos($this->path, '//')) { - throw new \InvalidArgumentException('The path of a URI without an authority must not start with two slashes "//"'); + throw new \InvalidArgumentException( + 'The path of a URI without an authority must not start with two slashes "//"' + ); } $parts = explode('/', $this->path, 2); if ('' === $this->scheme && false !== mb_strpos($parts[0], ':')) { - throw new \InvalidArgumentException('A relative URI must not have a path beginning with a segment containing a colon'); + throw new \InvalidArgumentException( + 'A relative URI must not have a path beginning with a segment containing a colon' + ); } } elseif (isset($this->path[0]) && '/' !== $this->path[0]) { @trigger_error( - 'The path of a URI with an authority must start with a slash "/" or be empty. Automagically fixing the URI '. - 'by adding a leading slash to the path is deprecated since version 1.4 and will throw an exception instead.', + 'The path of a URI with an authority must start with a slash "/" or be empty. Automagically fixing the URI ' . + 'by adding a leading slash to the path is deprecated since version 1.4 and will throw an exception instead.', E_USER_DEPRECATED ); - $this->path = '/'.$this->path; + $this->path = '/' . $this->path; //throw new \InvalidArgumentException('The path of a URI with an authority must start with a slash "/" or be empty'); } } diff --git a/clients/algoliasearch-client-php/lib/Http/Psr7/UriResolver.php b/clients/algoliasearch-client-php/lib/Http/Psr7/UriResolver.php index 048328fe60..299aceb5e5 100644 --- a/clients/algoliasearch-client-php/lib/Http/Psr7/UriResolver.php +++ b/clients/algoliasearch-client-php/lib/Http/Psr7/UriResolver.php @@ -45,7 +45,7 @@ public static function removeDotSegments($path) if ('/' === $path[0] && (!isset($newPath[0]) || '/' !== $newPath[0])) { // Re-add the leading slash if necessary for cases like "/.." - $newPath = '/'.$newPath; + $newPath = '/' . $newPath; } elseif ('' !== $newPath && ('.' === $segment || '..' === $segment)) { // Add the trailing slash if necessary // If newPath is not empty, then $segment must be set and is the last segment from the foreach @@ -84,20 +84,28 @@ public static function resolve(UriInterface $base, UriInterface $rel) $targetAuthority = $base->getAuthority(); if ('' === $rel->getPath()) { $targetPath = $base->getPath(); - $targetQuery = '' !== $rel->getQuery() ? $rel->getQuery() : $base->getQuery(); + $targetQuery = + '' !== $rel->getQuery() + ? $rel->getQuery() + : $base->getQuery(); } else { $path = $rel->getPath(); if ('/' === $path[0]) { $targetPath = $rel->getPath(); } else { if ('' !== $targetAuthority && '' === $base->getPath()) { - $targetPath = '/'.$rel->getPath(); + $targetPath = '/' . $rel->getPath(); } else { $lastSlashPos = mb_strrpos($base->getPath(), '/'); if (false === $lastSlashPos) { $targetPath = $rel->getPath(); } else { - $targetPath = mb_substr($base->getPath(), 0, $lastSlashPos + 1).$rel->getPath(); + $targetPath = + mb_substr( + $base->getPath(), + 0, + $lastSlashPos + 1 + ) . $rel->getPath(); } } } @@ -106,13 +114,15 @@ public static function resolve(UriInterface $base, UriInterface $rel) } } - return new Uri(Uri::composeComponents( - $base->getScheme(), - $targetAuthority, - $targetPath, - $targetQuery, - $rel->getFragment() - )); + return new Uri( + Uri::composeComponents( + $base->getScheme(), + $targetAuthority, + $targetPath, + $targetQuery, + $rel->getFragment() + ) + ); } /** @@ -143,8 +153,11 @@ public static function resolve(UriInterface $base, UriInterface $rel) */ public static function relativize(UriInterface $base, UriInterface $target) { - if ('' !== $target->getScheme() && - ($base->getScheme() !== $target->getScheme() || '' === $target->getAuthority() && '' !== $base->getAuthority()) + if ( + '' !== $target->getScheme() && + ($base->getScheme() !== $target->getScheme() || + ('' === $target->getAuthority() && + '' !== $base->getAuthority())) ) { return $target; } @@ -156,17 +169,27 @@ public static function relativize(UriInterface $base, UriInterface $target) return $target; } - if ('' !== $target->getAuthority() && $base->getAuthority() !== $target->getAuthority()) { + if ( + '' !== $target->getAuthority() && + $base->getAuthority() !== $target->getAuthority() + ) { return $target->withScheme(''); } // We must remove the path before removing the authority because if the path starts with two slashes, the URI // would turn invalid. And we also cannot set a relative path before removing the authority, as that is also // invalid. - $emptyPathUri = $target->withScheme('')->withPath('')->withUserInfo('')->withPort(null)->withHost(''); + $emptyPathUri = $target + ->withScheme('') + ->withPath('') + ->withUserInfo('') + ->withPort(null) + ->withHost(''); if ($base->getPath() !== $target->getPath()) { - return $emptyPathUri->withPath(self::getRelativePath($base, $target)); + return $emptyPathUri->withPath( + self::getRelativePath($base, $target) + ); } if ($base->getQuery() === $target->getQuery()) { @@ -180,27 +203,36 @@ public static function relativize(UriInterface $base, UriInterface $target) $segments = explode('/', $target->getPath()); $lastSegment = end($segments); - return $emptyPathUri->withPath('' === $lastSegment ? './' : $lastSegment); + return $emptyPathUri->withPath( + '' === $lastSegment ? './' : $lastSegment + ); } return $emptyPathUri; } - private static function getRelativePath(UriInterface $base, UriInterface $target) - { + private static function getRelativePath( + UriInterface $base, + UriInterface $target + ) { $sourceSegments = explode('/', $base->getPath()); $targetSegments = explode('/', $target->getPath()); array_pop($sourceSegments); $targetLastSegment = array_pop($targetSegments); foreach ($sourceSegments as $i => $segment) { - if (isset($targetSegments[$i]) && $segment === $targetSegments[$i]) { + if ( + isset($targetSegments[$i]) && + $segment === $targetSegments[$i] + ) { unset($sourceSegments[$i], $targetSegments[$i]); } else { break; } } $targetSegments[] = $targetLastSegment; - $relativePath = str_repeat('../', count($sourceSegments)).implode('/', $targetSegments); + $relativePath = + str_repeat('../', count($sourceSegments)) . + implode('/', $targetSegments); // A reference to am empty last segment or an empty first sub-segment must be prefixed with "./". // This also applies to a segment with a colon character (e.g., "file:colon") that cannot be used diff --git a/clients/algoliasearch-client-php/lib/Http/Psr7/functions.php b/clients/algoliasearch-client-php/lib/Http/Psr7/functions.php index 646e75341b..539833014e 100644 --- a/clients/algoliasearch-client-php/lib/Http/Psr7/functions.php +++ b/clients/algoliasearch-client-php/lib/Http/Psr7/functions.php @@ -46,7 +46,9 @@ function stream_for($resource = '', array $options = []) return new PumpStream($resource, $options); } - throw new \InvalidArgumentException('Invalid resource type: '.gettype($resource)); + throw new \InvalidArgumentException( + 'Invalid resource type: ' . gettype($resource) + ); } /** diff --git a/clients/algoliasearch-client-php/lib/ObjectSerializer.php b/clients/algoliasearch-client-php/lib/ObjectSerializer.php index e59a9ce0e3..87ad5039e7 100644 --- a/clients/algoliasearch-client-php/lib/ObjectSerializer.php +++ b/clients/algoliasearch-client-php/lib/ObjectSerializer.php @@ -32,14 +32,19 @@ public static function setDateTimeFormat($format) * * @return scalar|object|array|null serialized form of $data */ - public static function sanitizeForSerialization($data, $type = null, $format = null) - { + public static function sanitizeForSerialization( + $data, + $type = null, + $format = null + ) { if (is_scalar($data) || null === $data) { return $data; } if ($data instanceof \DateTime) { - return ($format === 'date') ? $data->format('Y-m-d') : $data->format(self::$dateTimeFormat); + return $format === 'date' + ? $data->format('Y-m-d') + : $data->format(self::$dateTimeFormat); } if (is_array($data)) { @@ -57,7 +62,30 @@ public static function sanitizeForSerialization($data, $type = null, $format = n foreach ($data::openAPITypes() as $property => $openAPIType) { $getter = $data::getters()[$property]; $value = $data->$getter(); - if ($value !== null && !in_array($openAPIType, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + if ( + $value !== null && + !in_array( + $openAPIType, + [ + '\DateTime', + '\SplFileObject', + 'array', + 'bool', + 'boolean', + 'byte', + 'double', + 'float', + 'int', + 'integer', + 'mixed', + 'number', + 'object', + 'string', + 'void', + ], + true + ) + ) { $callable = [$openAPIType, 'getAllowableEnumValues']; if (is_callable($callable)) { /** array $callable */ @@ -65,12 +93,20 @@ public static function sanitizeForSerialization($data, $type = null, $format = n if (!in_array($value, $allowedEnumTypes, true)) { $imploded = implode("', '", $allowedEnumTypes); - throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); + throw new \InvalidArgumentException( + "Invalid value for enum '$openAPIType', must be one of: '$imploded'" + ); } } } if ($value !== null) { - $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); + $values[ + $data::attributeMap()[$property] + ] = self::sanitizeForSerialization( + $value, + $openAPIType, + $formats[$property] + ); } } } else { @@ -183,7 +219,8 @@ public static function toFormValue($value) */ public static function toString($value) { - if ($value instanceof \DateTime) { // datetime in ISO8601 format + if ($value instanceof \DateTime) { + // datetime in ISO8601 format return $value->format(self::$dateTimeFormat); } elseif (is_bool($value)) { return $value ? 'true' : 'false'; @@ -202,12 +239,19 @@ public static function toString($value) * * @return string */ - public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false) - { - if ($allowCollectionFormatMulti && ('multi' === $style)) { + public static function serializeCollection( + array $collection, + $style, + $allowCollectionFormatMulti = false + ) { + if ($allowCollectionFormatMulti && 'multi' === $style) { // http_build_query() almost does the job for us. We just // need to fix the result of multidimensional arrays. - return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&')); + return preg_replace( + '/%5B[0-9]+%5D=/', + '=', + http_build_query($collection, '', '&') + ); } switch ($style) { case 'pipeDelimited': @@ -223,7 +267,7 @@ public static function serializeCollection(array $collection, $style, $allowColl case 'simple': case 'csv': - // Deliberate fall through. CSV is default format. + // Deliberate fall through. CSV is default format. default: return implode(',', $collection); } @@ -261,7 +305,8 @@ public static function deserialize($data, $class, $httpHeaders = null) return $values; } - if (preg_match('/^(array<|map\[)/', $class)) { // for associative array e.g. array + if (preg_match('/^(array<|map\[)/', $class)) { + // for associative array e.g. array $data = is_string($data) ? json_decode($data) : $data; settype($data, 'array'); $inner = mb_substr($class, 4, -1); @@ -270,7 +315,11 @@ public static function deserialize($data, $class, $httpHeaders = null) $subClass_array = explode(',', $inner, 2); $subClass = $subClass_array[1]; foreach ($data as $key => $value) { - $deserialized[$key] = self::deserialize($value, $subClass, null); + $deserialized[$key] = self::deserialize( + $value, + $subClass, + null + ); } } @@ -310,7 +359,29 @@ public static function deserialize($data, $class, $httpHeaders = null) } /** @psalm-suppress ParadoxicalCondition */ - if (in_array($class, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + if ( + in_array( + $class, + [ + '\DateTime', + '\SplFileObject', + 'array', + 'bool', + 'boolean', + 'byte', + 'double', + 'float', + 'int', + 'integer', + 'mixed', + 'number', + 'object', + 'string', + 'void', + ], + true + ) + ) { settype($data, $class); return $data; @@ -320,7 +391,9 @@ public static function deserialize($data, $class, $httpHeaders = null) if (!in_array($data, $class::getAllowableEnumValues(), true)) { $imploded = implode("', '", $class::getAllowableEnumValues()); - throw new \InvalidArgumentException("Invalid value for enum '$class', must be one of: '$imploded'"); + throw new \InvalidArgumentException( + "Invalid value for enum '$class', must be one of: '$imploded'" + ); } return $data; @@ -328,8 +401,13 @@ public static function deserialize($data, $class, $httpHeaders = null) $data = is_string($data) ? json_decode($data) : $data; // If a discriminator is defined and points to a valid subclass, use it. $discriminator = $class::DISCRIMINATOR; - if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { - $subclass = '\Algolia\AlgoliaSearch\Model\\' . $data->{$discriminator}; + if ( + !empty($discriminator) && + isset($data->{$discriminator}) && + is_string($data->{$discriminator}) + ) { + $subclass = + '\Algolia\AlgoliaSearch\Model\\' . $data->{$discriminator}; if (is_subclass_of($subclass, $class)) { $class = $subclass; } @@ -340,13 +418,19 @@ public static function deserialize($data, $class, $httpHeaders = null) foreach ($instance::openAPITypes() as $property => $type) { $propertySetter = $instance::setters()[$property]; - if (!isset($propertySetter) || !isset($data->{$instance::attributeMap()[$property]})) { + if ( + !isset($propertySetter) || + !isset($data->{$instance::attributeMap()[$property]}) + ) { continue; } if (isset($data->{$instance::attributeMap()[$property]})) { - $propertyValue = $data->{$instance::attributeMap()[$property]}; - $instance->$propertySetter(self::deserialize($propertyValue, $type, null)); + $propertyValue = + $data->{$instance::attributeMap()[$property]}; + $instance->$propertySetter( + self::deserialize($propertyValue, $type, null) + ); } } diff --git a/clients/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php b/clients/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php index 5f23b630b8..434b70631e 100644 --- a/clients/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php +++ b/clients/algoliasearch-client-php/lib/RequestOptions/RequestOptionsFactory.php @@ -16,11 +16,7 @@ final class RequestOptionsFactory 'getVersion', ]; - private $validHeaders = [ - 'Content-type', - 'User-Agent', - 'createIfNotExists', - ]; + private $validHeaders = ['Content-type', 'User-Agent', 'createIfNotExists']; public function __construct(Configuration $config) { @@ -44,10 +40,14 @@ public function create($options, $defaults = []) } elseif ($options instanceof RequestOptions) { $defaults = $this->create($defaults); $options->addDefaultHeaders($defaults->getHeaders()); - $options->addDefaultQueryParameters($defaults->getQueryParameters()); + $options->addDefaultQueryParameters( + $defaults->getQueryParameters() + ); $options->addDefaultBodyParameters($defaults->getBody()); } else { - throw new \InvalidArgumentException('RequestOptions can only be created from array or from RequestOptions object'); + throw new \InvalidArgumentException( + 'RequestOptions can only be created from array or from RequestOptions object' + ); } return $options->addDefaultHeaders($this->config->getDefaultHeaders()); @@ -57,9 +57,7 @@ public function createBodyLess($options, $defaults = []) { $options = $this->create($options, $defaults); - return $options - ->addQueryParameters($options->getBody()) - ->setBody([]); + return $options->addQueryParameters($options->getBody())->setBody([]); } private function normalize($options) @@ -68,9 +66,9 @@ private function normalize($options) 'headers' => [ 'X-Algolia-Application-Id' => $this->config->getAppId(), 'X-Algolia-API-Key' => $this->config->getAlgoliaApiKey(), - 'User-Agent' => $this->config->getUserAgent() !== null ? - $this->config->getUserAgent() : - UserAgent::get(), + 'User-Agent' => $this->config->getUserAgent() !== null + ? $this->config->getUserAgent() + : UserAgent::get(), 'Content-Type' => 'application/json', ], 'query' => [], @@ -83,7 +81,13 @@ private function normalize($options) foreach ($options as $optionName => $value) { $type = $this->getOptionType($optionName); - if (in_array($type, ['readTimeout', 'writeTimeout', 'connectTimeout'], true)) { + if ( + in_array( + $type, + ['readTimeout', 'writeTimeout', 'connectTimeout'], + true + ) + ) { $normalized[$type] = $value; } else { $normalized[$type][$optionName] = $value; @@ -112,7 +116,13 @@ private function getOptionType($optionName) return 'headers'; } elseif (in_array($optionName, $this->validQueryParameters, true)) { return 'query'; - } elseif (in_array($optionName, ['connectTimeout', 'readTimeout', 'writeTimeout'], true)) { + } elseif ( + in_array( + $optionName, + ['connectTimeout', 'readTimeout', 'writeTimeout'], + true + ) + ) { return $optionName; } diff --git a/clients/algoliasearch-client-php/lib/RetryStrategy/ApiWrapper.php b/clients/algoliasearch-client-php/lib/RetryStrategy/ApiWrapper.php index e008c5e32b..2400c98a59 100644 --- a/clients/algoliasearch-client-php/lib/RetryStrategy/ApiWrapper.php +++ b/clients/algoliasearch-client-php/lib/RetryStrategy/ApiWrapper.php @@ -57,7 +57,8 @@ public function __construct( ) { $this->http = $http; $this->clusterHosts = $clusterHosts; - $this->requestOptionsFactory = $RqstOptsFactory ?: new RequestOptionsFactory($config); + $this->requestOptionsFactory = + $RqstOptsFactory ?: new RequestOptionsFactory($config); $this->logger = $logger ?: Algolia::getLogger(); if (defined('JSON_UNESCAPED_UNICODE')) { // `JSON_UNESCAPED_UNICODE` is introduced in PHP 5.4.0 @@ -65,12 +66,22 @@ public function __construct( } } - public function read($method, $path, $requestOptions = [], $defaultRequestOptions = []) - { + public function read( + $method, + $path, + $requestOptions = [], + $defaultRequestOptions = [] + ) { if ('GET' === mb_strtoupper($method)) { - $requestOptions = $this->requestOptionsFactory->createBodyLess($requestOptions, $defaultRequestOptions); + $requestOptions = $this->requestOptionsFactory->createBodyLess( + $requestOptions, + $defaultRequestOptions + ); } else { - $requestOptions = $this->requestOptionsFactory->create($requestOptions, $defaultRequestOptions); + $requestOptions = $this->requestOptionsFactory->create( + $requestOptions, + $defaultRequestOptions + ); } return $this->request( @@ -82,13 +93,24 @@ public function read($method, $path, $requestOptions = [], $defaultRequestOption ); } - public function write($method, $path, $data = [], $requestOptions = [], $defaultRequestOptions = []) - { + public function write( + $method, + $path, + $data = [], + $requestOptions = [], + $defaultRequestOptions = [] + ) { if ('DELETE' === mb_strtoupper($method)) { - $requestOptions = $this->requestOptionsFactory->createBodyLess($requestOptions, $defaultRequestOptions); + $requestOptions = $this->requestOptionsFactory->createBodyLess( + $requestOptions, + $defaultRequestOptions + ); $data = []; } else { - $requestOptions = $this->requestOptionsFactory->create($requestOptions, $defaultRequestOptions); + $requestOptions = $this->requestOptionsFactory->create( + $requestOptions, + $defaultRequestOptions + ); } return $this->request( @@ -120,8 +142,14 @@ public function send($method, $path, $requestOptions = [], $hosts = null) ); } - private function request($method, $path, RequestOptions $requestOptions, $hosts, $timeout, $data = []) - { + private function request( + $method, + $path, + RequestOptions $requestOptions, + $hosts, + $timeout, + $data = [] + ) { $uri = $this->createUri($path) ->withQuery($requestOptions->getBuiltQueryParameters()) ->withScheme('https'); @@ -165,9 +193,13 @@ private function request($method, $path, RequestOptions $requestOptions, $hosts, return $responseBody; } catch (RetriableException $e) { - $this->log(LogLevel::DEBUG, 'Host failed.', array_merge($logParams, [ - 'description' => $e->getMessage(), - ])); + $this->log( + LogLevel::DEBUG, + 'Host failed.', + array_merge($logParams, [ + 'description' => $e->getMessage(), + ]) + ); $this->clusterHosts->failed($host); } catch (BadRequestException $e) { @@ -190,19 +222,37 @@ private function request($method, $path, RequestOptions $requestOptions, $hosts, throw new UnreachableException(); } - private function handleResponse(ResponseInterface $response, RequestInterface $request) - { + private function handleResponse( + ResponseInterface $response, + RequestInterface $request + ) { $body = (string) $response->getBody(); $statusCode = $response->getStatusCode(); - if (0 === $statusCode || ($statusCode >= 100 && $statusCode < 200) || $statusCode >= 500) { + if ( + 0 === $statusCode || + ($statusCode >= 100 && $statusCode < 200) || + $statusCode >= 500 + ) { $reason = $response->getReasonPhrase(); - if (null === $response->getReasonPhrase() || '' === $response->getReasonPhrase()) { - $reason = $statusCode >= 500 ? 'Internal Server Error' : 'Unreachable Host'; + if ( + null === $response->getReasonPhrase() || + '' === $response->getReasonPhrase() + ) { + $reason = + $statusCode >= 500 + ? 'Internal Server Error' + : 'Unreachable Host'; } - throw new RetriableException('Retriable failure on '.$request->getUri()->getHost().': '.$reason, $statusCode); + throw new RetriableException( + 'Retriable failure on ' . + $request->getUri()->getHost() . + ': ' . + $reason, + $statusCode + ); } $responseArray = Helpers::json_decode($body, true); @@ -210,9 +260,12 @@ private function handleResponse(ResponseInterface $response, RequestInterface $r if (404 === $statusCode) { throw new NotFoundException($responseArray['message'], $statusCode); } elseif ($statusCode >= 400) { - throw new BadRequestException($responseArray['message'], $statusCode); + throw new BadRequestException( + $responseArray['message'], + $statusCode + ); } elseif (2 !== (int) ($statusCode / 100)) { - throw new AlgoliaException($statusCode.': '.$body, $statusCode); + throw new AlgoliaException($statusCode . ': ' . $body, $statusCode); } return $responseArray; @@ -226,7 +279,9 @@ private function createUri($uri) return new Uri($uri); } - throw new \InvalidArgumentException('URI must be a string or UriInterface'); + throw new \InvalidArgumentException( + 'URI must be a string or UriInterface' + ); } private function createRequest( @@ -244,7 +299,9 @@ private function createRequest( } else { $body = \json_encode($body, $this->jsonOptions); if (JSON_ERROR_NONE !== json_last_error()) { - throw new \InvalidArgumentException('json_encode error: '.json_last_error_msg()); + throw new \InvalidArgumentException( + 'json_encode error: ' . json_last_error_msg() + ); } } } @@ -258,6 +315,6 @@ private function createRequest( */ private function log($level, $message, array $context = []) { - $this->logger->log($level, 'Algolia API client: '.$message, $context); + $this->logger->log($level, 'Algolia API client: ' . $message, $context); } } diff --git a/clients/algoliasearch-client-php/lib/RetryStrategy/ApiWrapperInterface.php b/clients/algoliasearch-client-php/lib/RetryStrategy/ApiWrapperInterface.php index 9d2ba6f822..347e69e236 100644 --- a/clients/algoliasearch-client-php/lib/RetryStrategy/ApiWrapperInterface.php +++ b/clients/algoliasearch-client-php/lib/RetryStrategy/ApiWrapperInterface.php @@ -4,9 +4,20 @@ interface ApiWrapperInterface { - public function read($method, $path, $requestOptions = [], $defaultRequestOptions = []); + public function read( + $method, + $path, + $requestOptions = [], + $defaultRequestOptions = [] + ); - public function write($method, $path, $data = [], $requestOptions = [], $defaultRequestOptions = []); + public function write( + $method, + $path, + $data = [], + $requestOptions = [], + $defaultRequestOptions = [] + ); public function send($method, $path, $requestOptions = [], $hosts = null); } diff --git a/clients/algoliasearch-client-php/lib/RetryStrategy/ClusterHosts.php b/clients/algoliasearch-client-php/lib/RetryStrategy/ClusterHosts.php index da3852e220..e5c4f759a4 100644 --- a/clients/algoliasearch-client-php/lib/RetryStrategy/ClusterHosts.php +++ b/clients/algoliasearch-client-php/lib/RetryStrategy/ClusterHosts.php @@ -47,19 +47,22 @@ public static function create($read, $write = null) $write = array_fill_keys($write, 0); } - return new static(HostCollection::create($read), HostCollection::create($write)); + return new static( + HostCollection::create($read), + HostCollection::create($write) + ); } public static function createFromAppId($applicationId) { $read = $write = [ - $applicationId.'-1.algolianet.com' => 0, - $applicationId.'-2.algolianet.com' => 0, - $applicationId.'-3.algolianet.com' => 0, + $applicationId . '-1.algolianet.com' => 0, + $applicationId . '-2.algolianet.com' => 0, + $applicationId . '-3.algolianet.com' => 0, ]; - $read[$applicationId.'-dsn.algolia.net'] = 10; - $write[$applicationId.'.algolia.net'] = 10; + $read[$applicationId . '-dsn.algolia.net'] = 10; + $write[$applicationId . '.algolia.net'] = 10; return static::create($read, $write); } @@ -130,7 +133,7 @@ public function setCacheKey($cacheKey) private function getUrls($type) { $urls = $this->{$type}->getUrls(); - $lashHashName = 'last'.ucfirst($type).'Hash'; + $lashHashName = 'last' . ucfirst($type) . 'Hash'; if (Algolia::isCacheEnabled()) { $hash = sha1(implode('-', $urls)); diff --git a/clients/algoliasearch-client-php/lib/RetryStrategy/HostCollection.php b/clients/algoliasearch-client-php/lib/RetryStrategy/HostCollection.php index 1f2c76d220..c3ef2c7bdf 100644 --- a/clients/algoliasearch-client-php/lib/RetryStrategy/HostCollection.php +++ b/clients/algoliasearch-client-php/lib/RetryStrategy/HostCollection.php @@ -31,9 +31,11 @@ public function get() // We pass the result through array_values because sometimes // we need to make sure you can access the first element // via $result[0] - return array_values(array_filter($this->hosts, function (Host $host) { - return $host->isUp(); - })); + return array_values( + array_filter($this->hosts, function (Host $host) { + return $host->isUp(); + }) + ); } public function getUrls() @@ -79,7 +81,7 @@ private function sort() return 0; } - return ($prioA > $prioB) ? -1 : 1; + return $prioA > $prioB ? -1 : 1; }); } } diff --git a/clients/algoliasearch-client-php/lib/Support/Helpers.php b/clients/algoliasearch-client-php/lib/Support/Helpers.php index 33716920e4..41ef66b58e 100644 --- a/clients/algoliasearch-client-php/lib/Support/Helpers.php +++ b/clients/algoliasearch-client-php/lib/Support/Helpers.php @@ -54,7 +54,9 @@ public static function json_decode($json, $assoc = false, $depth = 512) { $data = \json_decode($json, $assoc, $depth); if (JSON_ERROR_NONE !== json_last_error()) { - throw new \InvalidArgumentException('json_decode error: '.json_last_error_msg()); + throw new \InvalidArgumentException( + 'json_decode error: ' . json_last_error_msg() + ); } return $data; diff --git a/clients/algoliasearch-client-php/lib/Support/UserAgent.php b/clients/algoliasearch-client-php/lib/Support/UserAgent.php index 6be12e5f53..64c19ff3a1 100644 --- a/clients/algoliasearch-client-php/lib/Support/UserAgent.php +++ b/clients/algoliasearch-client-php/lib/Support/UserAgent.php @@ -28,10 +28,13 @@ public static function addCustomUserAgent($segment, $version) private static function getComputedValue() { $ua = []; - $segments = array_merge(self::getDefaultSegments(), self::$customSegments); + $segments = array_merge( + self::getDefaultSegments(), + self::$customSegments + ); foreach ($segments as $segment => $version) { - $ua[] = $segment.' ('.$version.')'; + $ua[] = $segment . ' (' . $version . ')'; } return implode('; ', $ua); @@ -42,7 +45,10 @@ private static function getDefaultSegments() $segments = []; $segments['Algolia for PHP'] = Algolia::VERSION; - $segments['PHP'] = rtrim(str_replace(PHP_EXTRA_VERSION, '', PHP_VERSION), '-'); + $segments['PHP'] = rtrim( + str_replace(PHP_EXTRA_VERSION, '', PHP_VERSION), + '-' + ); if (defined('HHVM_VERSION')) { $segments['HHVM'] = HHVM_VERSION; } @@ -50,7 +56,8 @@ private static function getDefaultSegments() if (defined('\GuzzleHttp\ClientInterface::VERSION')) { $segments['Guzzle'] = \GuzzleHttp\ClientInterface::VERSION; } else { - $segments['Guzzle'] = \GuzzleHttp\ClientInterface::MAJOR_VERSION; + $segments['Guzzle'] = + \GuzzleHttp\ClientInterface::MAJOR_VERSION; } } diff --git a/config/generation.config.js b/config/generation.config.js index 932a267224..7cba74f46c 100644 --- a/config/generation.config.js +++ b/config/generation.config.js @@ -28,9 +28,17 @@ module.exports = { '!clients/algoliasearch-client-javascript/packages/client-common/**', // PHP - '!clients/algoliasearch-client-php/lib/Configuration/*', - 'clients/algoliasearch-client-php/lib/*.php', - 'clients/algoliasearch-client-php/lib/Api/*', + '!clients/algoliasearch-client-php/*', + '!clients/algoliasearch-client-php/.*', + '!clients/algoliasearch-client-php/lib/*', + '!clients/algoliasearch-client-php/lib/Cache/**', + '!clients/algoliasearch-client-php/lib/Exceptions/**', + '!clients/algoliasearch-client-php/lib/Http/**', + '!clients/algoliasearch-client-php/lib/Log/**', + '!clients/algoliasearch-client-php/lib/RequestOptions/**', + '!clients/algoliasearch-client-php/lib/RetryStrategy/**', + '!clients/algoliasearch-client-php/lib/Support/**', + '!clients/algoliasearch-client-php/lib/Configuration/ConfigWithRegion.php', 'clients/algoliasearch-client-php/lib/Configuration/Configuration.php', ], }; diff --git a/openapitools.json b/openapitools.json index 200e448107..ed44e0202a 100644 --- a/openapitools.json +++ b/openapitools.json @@ -395,7 +395,7 @@ "additionalProperties": { "packageName": "algoliasearch-client-java-2", "packageVersion": "0.0.1", - "experimentalHost": "predict-api-oslcbws3zq-ew.a.run.app" + "experimentalHost": "predict-api-432xa6wemq-ew.a.run.app" } }, "php-search": {