diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index c612e7edd8..6c604d3a32 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -1,5 +1,7 @@ in(__DIR__.'/src') ->in(__DIR__.'/tests') @@ -8,7 +10,8 @@ return (new PhpCsFixer\Config()) ->setFinder($finder) ->setRules([ - '@PHP71Migration' => true, + '@PHP80Migration' => true, + '@PHP80Migration:risky' => true, '@PhpCsFixer' => true, '@PHPUnit75Migration:risky' => true, '@PSR2' => true, diff --git a/src/AbstractUpdateAction.php b/src/AbstractUpdateAction.php index 6ddbf84163..508f63df84 100644 --- a/src/AbstractUpdateAction.php +++ b/src/AbstractUpdateAction.php @@ -1,5 +1,7 @@ setParam('precision', $precision); diff --git a/src/Aggregation/GeotileGridAggregation.php b/src/Aggregation/GeotileGridAggregation.php index aa41687313..aa2b6ec2cc 100644 --- a/src/Aggregation/GeotileGridAggregation.php +++ b/src/Aggregation/GeotileGridAggregation.php @@ -1,5 +1,7 @@ getName()); + $doc = new Document((string) $id, $data, $this->getName()); $doc->setVersionParams($result); return $doc; diff --git a/src/Index/Recovery.php b/src/Index/Recovery.php index 3869c3fc72..2aaa0e221a 100644 --- a/src/Index/Recovery.php +++ b/src/Index/Recovery.php @@ -1,5 +1,7 @@ get('number_of_replicas') ?? self::DEFAULT_NUMBER_OF_REPLICAS; + return (int) ($this->get('number_of_replicas') ?? self::DEFAULT_NUMBER_OF_REPLICAS); } /** @@ -195,7 +197,7 @@ public function getNumberOfReplicas(): int */ public function getNumberOfShards(): int { - return $this->get('number_of_shards') ?? self::DEFAULT_NUMBER_OF_SHARDS; + return (int) ($this->get('number_of_shards') ?? self::DEFAULT_NUMBER_OF_SHARDS); } /** diff --git a/src/Index/Stats.php b/src/Index/Stats.php index e986500355..93269b5703 100644 --- a/src/Index/Stats.php +++ b/src/Index/Stats.php @@ -1,5 +1,7 @@ setRawProcessor($processor); } else { - throw new \TypeError(\sprintf('Argument 2 passed to %s::__construct() must be of type %s|array, %s given.', self::class, AbstractProcessor::class, \is_object($processor) ? \get_class($processor) : \gettype($processor))); + throw new \TypeError(\sprintf('Argument 2 passed to %s::__construct() must be of type %s|array, %s given.', self::class, AbstractProcessor::class, \is_object($processor) ? $processor::class : \gettype($processor))); } } diff --git a/src/Processor/JoinProcessor.php b/src/Processor/JoinProcessor.php index d3d786b3fa..52ddcf6b1d 100644 --- a/src/Processor/JoinProcessor.php +++ b/src/Processor/JoinProcessor.php @@ -1,5 +1,7 @@ getParam($this->field); diff --git a/src/Query/TermsSet.php b/src/Query/TermsSet.php index ab52d42db0..68032be1ce 100644 --- a/src/Query/TermsSet.php +++ b/src/Query/TermsSet.php @@ -1,5 +1,7 @@ setMinimumShouldMatchScript($minimumShouldMatch); } else { - throw new \TypeError(\sprintf('Argument 3 passed to "%s()" must be of type %s|string, %s given.', __METHOD__, AbstractScript::class, \is_object($minimumShouldMatch) ? \get_class($minimumShouldMatch) : \gettype($minimumShouldMatch))); + throw new \TypeError(\sprintf('Argument 3 passed to "%s()" must be of type %s|string, %s given.', __METHOD__, AbstractScript::class, \is_object($minimumShouldMatch) ? $minimumShouldMatch::class : \gettype($minimumShouldMatch))); } } diff --git a/src/Query/Wildcard.php b/src/Query/Wildcard.php index 1bc20e13d9..e62f4180b2 100644 --- a/src/Query/Wildcard.php +++ b/src/Query/Wildcard.php @@ -1,5 +1,7 @@ asString(), $response->getStatusCode()); } - return new Response($response->getBody(), $response->getStatusCode()); + return new Response((string) $response->getBody(), $response->getStatusCode()); } } diff --git a/src/Result.php b/src/Result.php index a411723e3a..511e8c990f 100644 --- a/src/Result.php +++ b/src/Result.php @@ -1,5 +1,7 @@ getData(); - return \array_map(static function ($name): string { - return (string) $name; - }, \array_keys($data['indices'])); + return \array_map(static fn ($name): string => (string) $name, \array_keys($data['indices'])); } /** diff --git a/src/Suggest.php b/src/Suggest.php index dfe604b84b..1fa1536d9d 100644 --- a/src/Suggest.php +++ b/src/Suggest.php @@ -1,5 +1,7 @@ '%2F' - return false !== \strpos(\strtoupper($requestUri), '%2F'); + return \str_contains(\strtoupper($requestUri), '%2F'); } /** @@ -64,7 +66,7 @@ public static function escapeDateMath($requestUri) $escapedUriSegment = \str_replace(static::$dateMathSymbols, static::$escapedDateMathSymbols, $uriSegment); // '\\{' and '\\}' should not be escaped - if (false !== \strpos($uriSegment, '\\\\')) { + if (\str_contains($uriSegment, '\\\\')) { $escapedUriSegment = \str_replace(['\\\\%7B', '\\\\%7D'], ['\\\\{', '\\\\}'], $escapedUriSegment); } diff --git a/tests/Aggregation/AbstractSimpleAggregationTest.php b/tests/Aggregation/AbstractSimpleAggregationTest.php index 2580fb5822..2e2740917a 100644 --- a/tests/Aggregation/AbstractSimpleAggregationTest.php +++ b/tests/Aggregation/AbstractSimpleAggregationTest.php @@ -1,5 +1,7 @@ _getIndexForTest()->search($query)->getAggregation('date'); $this->fail('Should throw exception to and from parameters in date_range aggregation are interpreted according of the target field'); } catch (ClientResponseException $e) { - $error = \json_decode($e->getResponse()->getBody(), true)['error'] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error'] ?? null; $this->assertSame('search_phase_execution_exception', $error['type']); $this->assertStringStartsWith('failed to parse date field', $error['root_cause'][0]['reason']); diff --git a/tests/Aggregation/DerivativeTest.php b/tests/Aggregation/DerivativeTest.php index 8be63a119f..a0859a7292 100644 --- a/tests/Aggregation/DerivativeTest.php +++ b/tests/Aggregation/DerivativeTest.php @@ -1,5 +1,7 @@ _getHost().':'.$this->_getPort()]; + $config['hosts'] ??= [$this->_getHost().':'.$this->_getPort()]; - $config['transport_config']['node_pool'] = $config['transport_config']['node_pool'] ?? new TraceableSimpleNodePool( + $config['transport_config']['node_pool'] ??= new TraceableSimpleNodePool( new RoundRobin(), new NoResurrect() ); diff --git a/tests/BasePipeline.php b/tests/BasePipeline.php index 6d0b10c2dc..5737fd4e20 100644 --- a/tests/BasePipeline.php +++ b/tests/BasePipeline.php @@ -1,5 +1,7 @@ assertTrue($action->hasSource()); $expected = <<<'JSON' -{"update":{"_id":"1","_index":"index"}} -{"doc":{"foo":"bar"},"doc_as_upsert":true} -JSON; + {"update":{"_id":"1","_index":"index"}} + {"doc":{"foo":"bar"},"doc_as_upsert":true} + JSON; $this->assertSame($expected, \trim((string) $action)); @@ -81,9 +83,9 @@ public function testUpdateDocumentAsUpsert(): void $action->setDocument($document); $expected = <<<'JSON' -{"update":{"_id":"1","_index":"index"}} -{"doc":{"foo":"bar"}} -JSON; + {"update":{"_id":"1","_index":"index"}} + {"doc":{"foo":"bar"}} + JSON; $this->assertSame($expected, \trim((string) $action)); diff --git a/tests/Bulk/ActionTest.php b/tests/Bulk/ActionTest.php index 644bf6440e..c4200f856a 100644 --- a/tests/Bulk/ActionTest.php +++ b/tests/Bulk/ActionTest.php @@ -1,5 +1,7 @@ assertSame($expectedJson, \trim((string) $bulk)); diff --git a/tests/ClientConfigurationTest.php b/tests/ClientConfigurationTest.php index 5566843811..0e32eb5224 100644 --- a/tests/ClientConfigurationTest.php +++ b/tests/ClientConfigurationTest.php @@ -1,5 +1,7 @@ addDocument($doc2); $this->fail('should throw read only exception'); } catch (ClientResponseException $e) { - $error = \json_decode($e->getResponse()->getBody(), true)['error'] ?? null; + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('cluster_block_exception', $error['type']); $this->assertStringContainsString('cluster read-only', $error['reason']); diff --git a/tests/ClusterTest.php b/tests/ClusterTest.php index 88d6beabed..feaba72eea 100644 --- a/tests/ClusterTest.php +++ b/tests/ClusterTest.php @@ -1,5 +1,7 @@ delete(); $this->fail('Should throw exception because you should delete the concrete index and not the alias'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('illegal_argument_exception', $error['type']); $this->assertStringContainsString('specify the corresponding concrete indices instead.', $error['reason']); @@ -349,8 +349,7 @@ public function testSetReadOnly(): void $index->addDocument($doc2); $this->fail('Should throw exception because of read only'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('cluster_block_exception', $error['type']); $this->assertStringContainsString('read-only', $error['reason']); @@ -451,8 +450,7 @@ public function testNotFoundIndex(): void $index->getSettings()->get(); $this->fail('Should throw exception because of index not found'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertSame('index_not_found_exception', $error['type']); } diff --git a/tests/Index/StatsTest.php b/tests/Index/StatsTest.php index 85dce732a9..2e2874e9f0 100644 --- a/tests/Index/StatsTest.php +++ b/tests/Index/StatsTest.php @@ -1,5 +1,7 @@ create($template); try { $indexTemplate->create($template); - } catch (ClientResponseException $ex) { - $response = ResponseConverter::toElastica($ex->getResponse()); - $error = $response->getFullError(); + } catch (ClientResponseException $e) { + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertNotEquals('index_template_already_exists_exception', $error['type']); $this->assertEquals('resource_already_exists_exception', $error['type']); - $this->assertEquals(400, $ex->getResponse()->getStatusCode()); + $this->assertEquals(400, $e->getResponse()->getStatusCode()); } } } diff --git a/tests/IndexTest.php b/tests/IndexTest.php index 74effafbfd..11c0f8bf55 100644 --- a/tests/IndexTest.php +++ b/tests/IndexTest.php @@ -1,5 +1,7 @@ deletePipeline('non_existent_pipeline'); $this->fail('an exception should be raised!'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $result = $response->getFullError(); + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; - $this->assertEquals('resource_not_found_exception', $result['type']); - $this->assertEquals('pipeline [non_existent_pipeline] is missing', $result['reason']); + $this->assertEquals('resource_not_found_exception', $error['type']); + $this->assertEquals('pipeline [non_existent_pipeline] is missing', $error['reason']); } } } diff --git a/tests/PointInTimeTest.php b/tests/PointInTimeTest.php index 3320ea3035..822465e903 100644 --- a/tests/PointInTimeTest.php +++ b/tests/PointInTimeTest.php @@ -1,5 +1,7 @@ 1, 'title' => 'Rodolfo', 'body' => 'Moraes', 'abstract' => 'Lorem'], - ['id' => 2, 'title' => 'Tristan', 'body' => 'Maindron', 'abstract' => 'Dolor'], - ['id' => 3, 'title' => 'Monique', 'body' => 'Maindron', 'abstract' => 'Ipsum'], - ['id' => 4, 'title' => 'John', 'body' => 'not Doe', 'abstract' => 'Consectetur'], + ['id' => '1', 'title' => 'Rodolfo', 'body' => 'Moraes', 'abstract' => 'Lorem'], + ['id' => '2', 'title' => 'Tristan', 'body' => 'Maindron', 'abstract' => 'Dolor'], + ['id' => '3', 'title' => 'Monique', 'body' => 'Maindron', 'abstract' => 'Ipsum'], + ['id' => '4', 'title' => 'John', 'body' => 'not Doe', 'abstract' => 'Consectetur'], ]; /** @@ -143,7 +145,7 @@ private function _generateIndex(): Index ); foreach (self::$data as $key => $docData) { - $index->addDocument(new Document($key, $docData)); + $index->addDocument(new Document((string) $key, $docData)); } // Refresh index diff --git a/tests/Query/ConstantScoreTest.php b/tests/Query/ConstantScoreTest.php index bad3883434..87a1986aab 100644 --- a/tests/Query/ConstantScoreTest.php +++ b/tests/Query/ConstantScoreTest.php @@ -1,5 +1,7 @@ 1, 'name' => 'Rodolfo', 'last_name' => 'Moraes', 'full_name' => 'Rodolfo Moraes'], - ['id' => 2, 'name' => 'Tristan', 'last_name' => 'Maindron', 'full_name' => 'Tristan Maindron'], - ['id' => 3, 'name' => 'Monique', 'last_name' => 'Maindron', 'full_name' => 'Monique Maindron'], - ['id' => 4, 'name' => 'John', 'last_name' => 'not Doe', 'full_name' => 'John not Doe'], + ['id' => '1', 'name' => 'Rodolfo', 'last_name' => 'Moraes', 'full_name' => 'Rodolfo Moraes'], + ['id' => '2', 'name' => 'Tristan', 'last_name' => 'Maindron', 'full_name' => 'Tristan Maindron'], + ['id' => '3', 'name' => 'Monique', 'last_name' => 'Maindron', 'full_name' => 'Monique Maindron'], + ['id' => '4', 'name' => 'John', 'last_name' => 'not Doe', 'full_name' => 'John not Doe'], ]; /** @@ -216,7 +218,7 @@ private function _generateIndex(): Index ); foreach (self::$data as $key => $docData) { - $index->addDocument(new Document($key, $docData)); + $index->addDocument(new Document((string) $key, $docData)); } // Refresh index diff --git a/tests/Query/NestedTest.php b/tests/Query/NestedTest.php index 58e399c3c3..a8be50babd 100644 --- a/tests/Query/NestedTest.php +++ b/tests/Query/NestedTest.php @@ -1,5 +1,7 @@ assertEquals(['query_string' => $expected], $query->toArray()); $fields = []; - $max = \mt_rand(1, 10); + $max = \random_int(1, 10); for ($i = 0; $i < $max; ++$i) { $fields[] = \uniqid(); } @@ -105,14 +106,13 @@ public function testSearchFieldsValidationException(): void try { $index->search($query); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error'] ?? null; $this->assertSame('query_shard_exception', $error['root_cause'][0]['type']); $this->assertStringContainsString('failed to create query', $error['root_cause'][0]['reason']); $this->assertStringContainsString('[fields] parameter in conjunction with [default_field]', $error['failed_shards'][0]['reason']['caused_by']['reason']); - $this->assertEquals(400, $response->getStatus()); + $this->assertEquals(400, $e->getResponse()->getStatusCode()); } } diff --git a/tests/Query/RangeTest.php b/tests/Query/RangeTest.php index 71320a7efa..f687b4cf19 100644 --- a/tests/Query/RangeTest.php +++ b/tests/Query/RangeTest.php @@ -1,5 +1,7 @@ hasMethod('__construct')) { $this->assertEmpty($method->getParameters(), 'Constructor is not defined, but method has some parameters'); } else { diff --git a/tests/QueryBuilder/DSL/AggregationTest.php b/tests/QueryBuilder/DSL/AggregationTest.php index a00b792852..5dd9fa4c63 100644 --- a/tests/QueryBuilder/DSL/AggregationTest.php +++ b/tests/QueryBuilder/DSL/AggregationTest.php @@ -1,5 +1,7 @@ getQueries() as $query) { $this->assertTrue( \method_exists($dsl[0], $query), - 'query "'.$query.'" in '.\get_class($version).' must be defined in '.\get_class($dsl[0]) + 'query "'.$query.'" in '.$version::class.' must be defined in '.\get_class($dsl[0]) ); } foreach ($version->getAggregations() as $aggregation) { $this->assertTrue( \method_exists($dsl[1], $aggregation), - 'aggregation "'.$aggregation.'" in '.\get_class($version).' must be defined in '.\get_class($dsl[2]) + 'aggregation "'.$aggregation.'" in '.$version::class.' must be defined in '.\get_class($dsl[2]) ); } foreach ($version->getSuggesters() as $suggester) { $this->assertTrue( \method_exists($dsl[2], $suggester), - 'suggester "'.$suggester.'" in '.\get_class($version).' must be defined in '.\get_class($dsl[2]) + 'suggester "'.$suggester.'" in '.$version::class.' must be defined in '.\get_class($dsl[2]) ); } foreach ($version->getCollapsers() as $collapser) { $this->assertTrue( \method_exists($dsl[3], $collapser), - 'suggester "'.$collapser.'" in '.\get_class($version).' must be defined in '.\get_class($dsl[3]) + 'suggester "'.$collapser.'" in '.$version::class.' must be defined in '.\get_class($dsl[3]) ); } } diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index ba0660e078..f7d0d28a79 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -1,5 +1,7 @@ getClient()->getLastRequest()->getUri()->getQuery(), $lastRequestQuery); - $lastRequestData = \json_decode($search->getClient()->getLastRequest()->getBody(), true); + $lastRequestData = \json_decode((string) $search->getClient()->getLastRequest()->getBody(), true); $this->assertFalse($result->getResponse()->hasError()); $this->assertCount(5, $result->getResults()); @@ -269,7 +270,7 @@ public function testSearchScrollRequest(): void ]); \parse_str($search->getClient()->getLastRequest()->getUri()->getQuery(), $lastRequestQuery); - $lastRequestData = \json_decode($search->getClient()->getLastRequest()->getBody(), true); + $lastRequestData = \json_decode((string) $search->getClient()->getLastRequest()->getBody(), true); $this->assertFalse($result->getResponse()->hasError()); $this->assertCount(0, $result->getResults()); @@ -686,8 +687,7 @@ public function testIgnoreUnavailableOption(): void $search->search($query); $this->fail('Should raise an Index not found exception'); } catch (ClientResponseException $e) { - $response = ResponseConverter::toElastica($e->getResponse()); - $error = $response->getFullError(); + $error = \json_decode((string) $e->getResponse()->getBody(), true)['error']['root_cause'][0] ?? null; $this->assertEquals('index_not_found_exception', $error['type']); $this->assertEquals('no such index [elastica_7086b4c2ee585bbb6740ece5ed7ece01]', $error['reason']); diff --git a/tests/SnapshotTest.php b/tests/SnapshotTest.php index 6a6169da7f..2082e102f2 100644 --- a/tests/SnapshotTest.php +++ b/tests/SnapshotTest.php @@ -1,5 +1,7 @@ getIndicesWithAlias($aliasName); $this->assertEquals([$indexName], \array_map( - static function ($index) { - return $index->getName(); - }, + static fn ($index) => $index->getName(), $indicesWithAlias )); } diff --git a/tests/Suggest/CompletionTest.php b/tests/Suggest/CompletionTest.php index 58df78ee97..7833319fdb 100644 --- a/tests/Suggest/CompletionTest.php +++ b/tests/Suggest/CompletionTest.php @@ -1,5 +1,7 @@