Skip to content

Commit d34e49e

Browse files
committed
chore: remove unrelated formatting changes
1 parent 314b0e0 commit d34e49e

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

src/Response/Elasticsearch.php

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Elasticsearch B.V licenses this file to you under the MIT License.
1111
* See the LICENSE file in the project root for more information.
1212
*/
13-
declare(strict_types=1);
13+
declare(strict_types = 1);
1414

1515
namespace Elastic\Elasticsearch\Response;
1616

@@ -36,10 +36,11 @@
3636
*/
3737
class Elasticsearch implements ElasticsearchInterface, ResponseInterface, ArrayAccess
3838
{
39+
const HEADER_CHECK = 'X-Elastic-Product';
40+
const PRODUCT_NAME = 'Elasticsearch';
41+
3942
use ProductCheckTrait;
4043
use MessageResponseTrait;
41-
public const HEADER_CHECK = 'X-Elastic-Product';
42-
public const PRODUCT_NAME = 'Elasticsearch';
4344

4445
protected array $asArray;
4546
protected object $asObject;
@@ -65,11 +66,11 @@ public function setResponse(ResponseInterface $response, bool $throwException =
6566
$this->productCheck($response);
6667
// Check for Serverless response
6768
$this->serverless = $this->isServerlessResponse($response);
68-
$this->response = $response;
6969

7070
unset($this->asArray, $this->asObject);
7171
$this->asString = '';
7272

73+
$this->response = $response;
7374
$status = $response->getStatusCode();
7475
if ($throwException && $status > 399 && $status < 500) {
7576
$error = new ClientResponseException(
@@ -107,14 +108,14 @@ public function isServerless(): bool
107108
*/
108109
public function asBool(): bool
109110
{
110-
return $this->response->getStatusCode() >= 200 && $this->response->getStatusCode() < 300;
111+
return $this->response->getStatusCode() >=200 && $this->response->getStatusCode() < 300;
111112
}
112113

113114
/**
114115
* Converts the body content to array, if possible.
115116
* Otherwise, it throws an UnknownContentTypeException
116117
* if Content-Type is not specified or unknown.
117-
*
118+
*
118119
* @throws UnknownContentTypeException
119120
*/
120121
public function asArray(): array
@@ -150,7 +151,7 @@ public function asArray(): array
150151
* Converts the body content to object, if possible.
151152
* Otherwise, it throws an UnknownContentTypeException
152153
* if Content-Type is not specified or unknown.
153-
*
154+
*
154155
* @throws UnknownContentTypeException
155156
*/
156157
public function asObject(): object
@@ -200,7 +201,7 @@ public function __toString(): string
200201

201202
/**
202203
* Access the body content as object properties
203-
*
204+
*
204205
* @see https://www.php.net/manual/en/language.oop5.overloading.php#object.get
205206
*/
206207
public function __get($name)
@@ -210,17 +211,17 @@ public function __get($name)
210211

211212
/**
212213
* ArrayAccess interface
213-
*
214+
*
214215
* @see https://www.php.net/manual/en/class.arrayaccess.php
215216
*/
216217
public function offsetExists($offset): bool
217218
{
218219
return isset($this->asArray()[$offset]);
219220
}
220-
221+
221222
/**
222223
* ArrayAccess interface
223-
*
224+
*
224225
* @see https://www.php.net/manual/en/class.arrayaccess.php
225226
*
226227
* @return mixed
@@ -233,7 +234,7 @@ public function offsetGet($offset)
233234

234235
/**
235236
* ArrayAccess interface
236-
*
237+
*
237238
* @see https://www.php.net/manual/en/class.arrayaccess.php
238239
*/
239240
public function offsetSet($offset, $value): void
@@ -243,7 +244,7 @@ public function offsetSet($offset, $value): void
243244

244245
/**
245246
* ArrayAccess interface
246-
*
247+
*
247248
* @see https://www.php.net/manual/en/class.arrayaccess.php
248249
*/
249250
public function offsetUnset($offset): void
@@ -254,11 +255,11 @@ public function offsetUnset($offset): void
254255
/**
255256
* Map the response body to an object of a specific class
256257
* by default the class is the PHP standard one (stdClass)
257-
*
258+
*
258259
* This mapping works only for ES|QL results (with columns and values)
259260
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/esql.html
260-
*
261-
* @return object[]
261+
*
262+
* @return object[]
262263
*/
263264
public function mapTo(string $class = stdClass::class): array
264265
{
@@ -267,13 +268,13 @@ public function mapTo(string $class = stdClass::class): array
267268
throw new UnknownContentTypeException(sprintf(
268269
"The response is not a valid ES|QL result. I cannot mapTo(\"%s\")",
269270
$class
270-
));
271+
));
271272
}
272273
$iterator = [];
273274
$ncol = count($response['columns']);
274275
foreach ($response['values'] as $value) {
275-
$obj = new $class();
276-
for ($i = 0; $i < $ncol; $i++) {
276+
$obj = new $class;
277+
for ($i=0; $i < $ncol; $i++) {
277278
$field = Utility::formatVariableName($response['columns'][$i]['name']);
278279
if ($class !== stdClass::class && !property_exists($obj, $field)) {
279280
continue;
@@ -309,4 +310,4 @@ public function mapTo(string $class = stdClass::class): array
309310
}
310311
return $iterator;
311312
}
312-
}
313+
}

tests/Response/ElasticsearchTest.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Elasticsearch B.V licenses this file to you under the MIT License.
1111
* See the LICENSE file in the project root for more information.
1212
*/
13-
declare(strict_types=1);
13+
declare(strict_types = 1);
1414

1515
namespace Elastic\Elasticsearch\Tests\Response;
1616

@@ -26,7 +26,6 @@
2626
use PHPUnit\Framework\TestCase;
2727
use Psr\Http\Message\ResponseInterface;
2828
use stdClass;
29-
3029
class ElasticsearchTest extends TestCase
3130
{
3231
protected Psr17Factory $psr17Factory;
@@ -39,7 +38,7 @@ public function setUp(): void
3938
{
4039
$this->psr17Factory = new Psr17Factory();
4140
$this->elasticsearch = new Elasticsearch();
42-
41+
4342
$this->response200 = $this->psr17Factory->createResponse(200)
4443
->withHeader('X-Elastic-Product', 'Elasticsearch')
4544
->withHeader('Content-Type', 'application/json');
@@ -87,8 +86,11 @@ public function testAsBoolIsTrueWith200()
8786

8887
public function testAsBoolIsFalseWith400()
8988
{
90-
$this->elasticsearch->setResponse($this->response400, false);
91-
$this->assertFalse($this->elasticsearch->asBool());
89+
try {
90+
$this->elasticsearch->setResponse($this->response400);
91+
} catch (ClientResponseException $e) {
92+
$this->assertFalse($this->elasticsearch->asBool());
93+
}
9294
}
9395

9496
/**
@@ -139,9 +141,9 @@ public function testSetResponseWith400AndThrowFalseDoesNotThrowException()
139141
$this->elasticsearch->setResponse($this->response400, false);
140142
}
141143

142-
/**
143-
* @doesNotPerformAssertions
144-
*/
144+
/**
145+
* @doesNotPerformAssertions
146+
*/
145147
public function testSetResponseWith500AndThrowFalseDoesNotThrowException()
146148
{
147149
$this->elasticsearch->setResponse($this->response500, false);
@@ -316,7 +318,7 @@ public function testIsServerlessFalseIfNotServerlessResponse()
316318
$this->assertFalse($this->elasticsearch->isServerless());
317319
}
318320

319-
public function testCacheIsClearedOnSetResponse()
321+
public function testCacheIsClearedOnSetResponse(): void
320322
{
321323
$firstBody = $this->psr17Factory->createStream(json_encode(['foo' => 'bar']));
322324
$this->elasticsearch->setResponse($this->response200->withBody($firstBody));
@@ -326,4 +328,4 @@ public function testCacheIsClearedOnSetResponse()
326328
$this->elasticsearch->setResponse($this->response200->withBody($secondBody));
327329
$this->assertSame('baz', $this->elasticsearch->asArray()['foo']);
328330
}
329-
}
331+
}

0 commit comments

Comments
 (0)