diff --git a/.php_cs b/.php_cs index 47a3cdd7fb..3e33866b96 100644 --- a/.php_cs +++ b/.php_cs @@ -25,7 +25,7 @@ $config = Symfony\CS\Config\Config::create() 'no_useless_else', // [contrib] Use dedicated PHPUnit assertions for better error messages. '@PHPUnit60Migration:risky' => true, - 'php_unit_dedicate_assert' => ['target' => 'newest'], + //'php_unit_dedicate_assert' => ['target' => 'newest'], ]) ->finder($finder); diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e88a438bb..d4f4463900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,51 +1,58 @@ # Change Log All notable changes to this project will be documented in this file based on the [Keep a Changelog](http://keepachangelog.com/) Standard. This project adheres to [Semantic Versioning](http://semver.org/). -## [Unreleased](https://github.com/ruflin/Elastica/compare/6.0.2...master) +## [Unreleased](https://github.com/ruflin/Elastica/compare/6.1.0...master) ### Backward Compatibility Breaks -* Made result sets adhere to `\Iterator` interface definition that they implement. Specifically, you need to call `valid()` on the result set before calling `current()`. When using `foreach` this is done by PHP automatically. When `valid` returns false, the return value of `current` is undefined instead of false. +### Bugfixes + +### Added + +### Improvements + +### Deprecated + +## [6.1.0](https://github.com/ruflin/Elastica/compare/6.0.2...6.1.0) + +### Backward Compatibility Breaks + +* Made result sets adhere to `\Iterator` interface definition that they implement. Specifically, you need to call `valid()` on the result set before calling `current()`. When using `foreach` this is done by PHP automatically. When `valid` returns false, the return value of `current` is undefined instead of false. [#1506](https://github.com/ruflin/Elastica/pull/1506) * `\Elastica\ResultSet::next` returns `void` instead of `\Elastica\Result|false` * `\Elastica\Bulk\ResponseSet::current` returns `\Elastica\Bulk\Response` instead of `\Elastica\Bulk\Response|false` * `\Elastica\Multi\ResultSet::current` returns `\Elastica\ResultSet` instead of `\Elastica\ResultSet|false` + +### Added + +* Added a transport class for mocking a HTTP 403 error codes, useful for testing response failures in inheriting clients +* [Field](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-random) param for `Elastica\Query\FunctionScore::addRandomScoreFunction` [#1529](https://github.com/ruflin/Elastica/pull/1529) +* [Index Recovery](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html) : the indices recovery API provides insight into on-going index shard recoveries. It was never been implemented into Elastica. [#1537](https://github.com/ruflin/Elastica/pull/1537) +* add parent_id (reference [#1518](https://github.com/ruflin/Elastica/issues/1518)) in QueryBuilder. [#1533]([#1518](https://github.com/ruflin/Elastica/issues/1533)) +* implemented ```string_distance``` option in Term Suggestion [#1543](https://github.com/ruflin/Elastica/pull/1543) + +### Improvements + +* Using `Elastica\Query\FunctionScore::addRandomScoreFunction` without `$field` parameter is deprecated since ES 6.0 and will fail since ES 7.0 [#1522](https://github.com/ruflin/Elastica/pull/1522) * `Aggreation\Percentiles` updated to a newer version of the Algorithm (T-Digest 3.2) and Percentiles results changed a bit Have a [look at here](https://github.com/elastic/elasticsearch/pull/28305), so updated tests in order not to fail. [#1531]([#1352](https://github.com/ruflin/Elastica/pull/1531)) * `Aggregation\Percentiles` have been updated since [Elasticsearch 2.3](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/search-aggregations-metrics-percentile-aggregation.html). In this version `compression, HDR histogram` changed their implementations. The `missing` field has never been implemented. [#1532](https://github.com/ruflin/Elastica/pull/1532) - - Before + + Before ```json "compression" : 200, - "method" : "hdr", + "method" : "hdr", "number_of_significant_value_digits" : 3 ``` - Now + Now ```json "tdigest": { - "compression" : 200 + "compression" : 200 }, - "hdr": { - "number_of_significant_value_digits" : 3 + "hdr": { + "number_of_significant_value_digits" : 3 } ``` -* Never implemented the method *Missing* on [`Aggregation\Percentiles`](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-aggregations-metrics-percentile-aggregation.html) - -### Bugfixes - -### Added - -* Added a transport class for mocking a HTTP 403 error codes, useful for testing response failures in inheriting clients -* [Field](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-random) param for `Elastica\Query\FunctionScore::addRandomScoreFunction` -* [Index Recovery](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html) : the indices recovery API provides insight into on-going index shard recoveries. It was never been implemented into Elastica. [#1537](https://github.com/ruflin/Elastica/pull/1537) -* add parent_id (reference [#1518](https://github.com/ruflin/Elastica/issues/1518)) in QueryBuilder. [#1533]([#1518](https://github.com/ruflin/Elastica/issues/1533)) -* implemented ```string_distance``` option in Term Suggestion [#1543](https://github.com/ruflin/Elastica/pull/1543) - -### Improvements - -* Using `Elastica\Query\FunctionScore::addRandomScoreFunction` without `$field` parameter is deprecated since ES 6.0 and will fail since ES 7.0 - -### Deprecated - +* Never implemented the method *Missing* on [`Aggregation\Percentiles`](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/search-aggregations-metrics-percentile-aggregation.html) [#1532](https://github.com/ruflin/Elastica/pull/1532) ## [6.0.2](https://github.com/ruflin/Elastica/compare/6.0.1...6.0.2) diff --git a/lib/Elastica/Aggregation/Histogram.php b/lib/Elastica/Aggregation/Histogram.php index 10402ddc2e..cf7631fc56 100644 --- a/lib/Elastica/Aggregation/Histogram.php +++ b/lib/Elastica/Aggregation/Histogram.php @@ -9,9 +9,9 @@ class Histogram extends AbstractSimpleAggregation { /** - * @param string $name the name of this aggregation - * @param string $field the name of the field on which to perform the aggregation - * @param int|string $interval the interval by which documents will be bucketed + * @param string $name the name of this aggregation + * @param string $field the name of the field on which to perform the aggregation + * @param int|string $interval the interval by which documents will be bucketed */ public function __construct($name, $field, $interval) { diff --git a/lib/Elastica/Aggregation/Percentiles.php b/lib/Elastica/Aggregation/Percentiles.php index f8386dafb5..8908d6ec99 100644 --- a/lib/Elastica/Aggregation/Percentiles.php +++ b/lib/Elastica/Aggregation/Percentiles.php @@ -30,7 +30,8 @@ public function __construct($name, $field = null) */ public function setCompression(float $value): Percentiles { - $compression = array('compression' => $value); + $compression = ['compression' => $value]; + return $this->setParam('tdigest', $compression); } @@ -38,20 +39,21 @@ public function setCompression(float $value): Percentiles * Set hdr parameter. * * @param string $key - * @param float $value + * @param float $value * * @return Percentiles $this */ public function setHdr(string $key, float $value): Percentiles { - $compression = array($key => $value); + $compression = [$key => $value]; + return $this->setParam('hdr', $compression); } /** * the keyed flag is set to true which associates a unique string * key with each bucket and returns the ranges as a hash - * rather than an array + * rather than an array. * * @param bool $keyed * @@ -88,7 +90,7 @@ public function addPercent(float $percent): Percentiles /** * Defines how documents that are missing a value should - * be treated + * be treated. * * @param float $missing * diff --git a/lib/Elastica/Index.php b/lib/Elastica/Index.php index b9bcf878f0..ef1278b03a 100644 --- a/lib/Elastica/Index.php +++ b/lib/Elastica/Index.php @@ -3,9 +3,9 @@ use Elastica\Exception\InvalidException; use Elastica\Exception\ResponseException; +use Elastica\Index\Recovery as IndexRecovery; use Elastica\Index\Settings as IndexSettings; use Elastica\Index\Stats as IndexStats; -use Elastica\Index\Recovery as IndexRecovery; use Elastica\ResultSet\BuilderInterface; use Elastica\Script\AbstractScript; use Elasticsearch\Endpoints\AbstractEndpoint; diff --git a/lib/Elastica/Index/Recovery.php b/lib/Elastica/Index/Recovery.php index f2e86eb7b9..916fd89d69 100644 --- a/lib/Elastica/Index/Recovery.php +++ b/lib/Elastica/Index/Recovery.php @@ -87,7 +87,7 @@ protected function getRecoveryData() } /** - * Retrieve the Recovery data + * Retrieve the Recovery data. * * @return $this */ @@ -97,4 +97,4 @@ public function refresh() return $this; } -} \ No newline at end of file +} diff --git a/lib/Elastica/Suggest/Term.php b/lib/Elastica/Suggest/Term.php index 8fd8eea3a7..084c0f930b 100644 --- a/lib/Elastica/Suggest/Term.php +++ b/lib/Elastica/Suggest/Term.php @@ -129,7 +129,7 @@ public function setMaxTermFrequency($max) /** * Which string distance implementation to use for comparing how similar suggested terms are. - * Five possible values can be specified: + * Five possible values can be specified:. * * - internal * - damerau_levenshtein diff --git a/lib/Elastica/Transport/NullTransport.php b/lib/Elastica/Transport/NullTransport.php index 932b5b505f..03bf74167c 100644 --- a/lib/Elastica/Transport/NullTransport.php +++ b/lib/Elastica/Transport/NullTransport.php @@ -17,14 +17,14 @@ class NullTransport extends AbstractTransport { /** - * Response you want to get from the transport + * Response you want to get from the transport. * * @var Response Response */ protected $_response = null; /** - * Set response object the transport returns + * Set response object the transport returns. * * @param \Elastica\Response $response * @@ -36,7 +36,7 @@ public function getResponse() } /** - * Set response object the transport returns + * Set response object the transport returns. * * @param \Elastica\Response $response * @@ -45,13 +45,14 @@ public function getResponse() public function setResponse(Response $response) { $this->_response = $response; + return $this->_response; } /** - * Generate an example response object + * Generate an example response object. * - * @param array $params Hostname, port, path, ... + * @param array $params Hostname, port, path, ... * * @return \Elastica\Response $response */ @@ -72,6 +73,7 @@ public function generateDefaultResponse(array $params) ], 'params' => $params, ]; + return new Response(JSON::stringify($response)); } diff --git a/test/Elastica/Aggregation/PercentilesTest.php b/test/Elastica/Aggregation/PercentilesTest.php index 16a084d0f1..2578c104a5 100644 --- a/test/Elastica/Aggregation/PercentilesTest.php +++ b/test/Elastica/Aggregation/PercentilesTest.php @@ -41,9 +41,9 @@ public function testCompression() 'field' => 'price', 'keyed' => false, 'tdigest' => [ - 'compression' => 100 - ] - ] + 'compression' => 100, + ], + ], ]; $aggr = new Percentiles('price_percentile'); @@ -64,9 +64,9 @@ public function testHdr() 'field' => 'price', 'keyed' => false, 'hdr' => [ - 'number_of_significant_value_digits' => 2.0 - ] - ] + 'number_of_significant_value_digits' => 2.0, + ], + ], ]; $aggr = new Percentiles('price_percentile'); @@ -76,7 +76,7 @@ public function testHdr() $this->assertEquals($expected, $aggr->toArray()); } - + /** * @group functional */ @@ -166,33 +166,33 @@ public function testKeyed() 'values' => [ [ 'key' => 1, - 'value' => 100 + 'value' => 100, ], [ 'key' => 5, - 'value' => 100 + 'value' => 100, ], [ 'key' => 25, - 'value' => 300 + 'value' => 300, ], [ 'key' => 50, - 'value' => 550 + 'value' => 550, ], [ 'key' => 75, - 'value' => 800 + 'value' => 800, ], [ 'key' => 95, - 'value' => 1000 + 'value' => 1000, ], [ 'key' => 99, - 'value' => 1000 - ] - ] + 'value' => 1000, + ], + ], ]; // prepare @@ -236,10 +236,10 @@ public function testMissing() 'field' => 'price', 'keyed' => false, 'hdr' => [ - 'number_of_significant_value_digits' => 2.0 + 'number_of_significant_value_digits' => 2.0, ], - 'missing' => 10 - ] + 'missing' => 10, + ], ]; $aggr = new Percentiles('price_percentile'); diff --git a/test/Elastica/Query/CommonTest.php b/test/Elastica/Query/CommonTest.php index 641c89f930..07f693f373 100644 --- a/test/Elastica/Query/CommonTest.php +++ b/test/Elastica/Query/CommonTest.php @@ -87,7 +87,6 @@ public function testSetBoost() /** * @group unit - */ public function testSetAnalyzer() { diff --git a/test/Elastica/Query/ParentIdTest.php b/test/Elastica/Query/ParentIdTest.php index 7bd3700e29..11451bbbb9 100644 --- a/test/Elastica/Query/ParentIdTest.php +++ b/test/Elastica/Query/ParentIdTest.php @@ -213,12 +213,10 @@ public function testQueryBuilderParentId() $data = $result->getData(); $this->assertEquals($data['text'], 'this is an answer, the 1st'); - $parentId = $queryDSL->parent_id('answer', 2, true); $search = new Search($index->getClient()); $results = $search->search($parentId); $this->assertEquals(2, $results->count()); - } } diff --git a/test/Elastica/Suggest/CompletionTest.php b/test/Elastica/Suggest/CompletionTest.php index 1efcfe85ab..bf16b4571d 100644 --- a/test/Elastica/Suggest/CompletionTest.php +++ b/test/Elastica/Suggest/CompletionTest.php @@ -136,7 +136,6 @@ public function testCompletion() $suggest2 = new Completion('suggestName2', 'fieldName2'); $suggest2->setPrefix('Neverdint'); - $sug = new Suggest(); $sug->addSuggestion($suggest); $sug->addSuggestion($suggest2); @@ -149,20 +148,19 @@ public function testCompletion() 'text' => 'Neavermint', 'offset' => 0, 'length' => 10, - 'options' => [] - ] + 'options' => [], + ], ], 'suggestName2' => [ 0 => [ 'text' => 'Neverdint', 'offset' => 0, 'length' => 9, - 'options' => [] - ] - ] + 'options' => [], + ], + ], ]; - $resultSet = $index->search($query); $this->assertTrue($resultSet->hasSuggests()); diff --git a/test/Elastica/Suggest/TermTest.php b/test/Elastica/Suggest/TermTest.php index 4092899fa6..e93cafd8c1 100644 --- a/test/Elastica/Suggest/TermTest.php +++ b/test/Elastica/Suggest/TermTest.php @@ -97,7 +97,7 @@ public function testDistanceAlgorithm() 'term' => [ 'field' => '_all', 'suggest_mode' => 'popular', - 'string_distance' => 'jaro_winkler' + 'string_distance' => 'jaro_winkler', ], 'text' => 'Girhub', ], @@ -105,7 +105,6 @@ public function testDistanceAlgorithm() ]; $this->assertEquals($expected, $suggest->toArray()); - } /** diff --git a/test/Elastica/TaskTest.php b/test/Elastica/TaskTest.php index e83a698ae6..90e91f45bd 100644 --- a/test/Elastica/TaskTest.php +++ b/test/Elastica/TaskTest.php @@ -38,7 +38,7 @@ public function testIsComplete() { $task = $this->_createTask(); - for ($i = 0; $i < 5; ++$i ) { + for ($i = 0; $i < 5; ++$i) { if ($task->isCompleted()) { break; } diff --git a/test/Elastica/Transport/NullTransportTest.php b/test/Elastica/Transport/NullTransportTest.php index c78712d6bd..e50427e48e 100644 --- a/test/Elastica/Transport/NullTransportTest.php +++ b/test/Elastica/Transport/NullTransportTest.php @@ -16,7 +16,6 @@ */ class NullTransportTest extends BaseTest { - /** @var NullTransport NullTransport */ protected $transport; @@ -102,7 +101,7 @@ public function testResponse() */ public function testGenerateDefaultResponse() { - $params = [ 'blah' => 123 ]; + $params = ['blah' => 123]; $response = $this->transport->generateDefaultResponse($params); $this->assertEquals([], $response->getTransferInfo());