diff --git a/.travis.yml b/.travis.yml index e6486006d1..31be0eeeeb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,8 @@ php: - 5.4 - 5.3 - 7.0 + - 7.1 + - 7.2 - hhvm matrix: diff --git a/CHANGELOG.md b/CHANGELOG.md index cff571259e..aa1ae23cbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file based on the - Introduce getFullError() for ResponseSet - Use the above to improve the output of getError() on Response +- In PHP 7.2 count() now raises a warning when an invalid parameter is passed. Only arrays and objects implementing the Countable interface should be passed. Backported from [#1378](https://github.com/ruflin/Elastica/pull/1378) ## [2.3.1](https://github.com/ruflin/Elastica/releases/tag/2.3.1) - 2015-10-17 diff --git a/lib/Elastica/Filter/GeoPolygon.php b/lib/Elastica/Filter/GeoPolygon.php index 86ca2b8025..3eac6c97a8 100644 --- a/lib/Elastica/Filter/GeoPolygon.php +++ b/lib/Elastica/Filter/GeoPolygon.php @@ -53,4 +53,14 @@ public function toArray() ), ); } + + /** + * @inheritdoc + * + * @return int + */ + public function count() + { + return count($this->_key); + } } diff --git a/lib/Elastica/Param.php b/lib/Elastica/Param.php index 098a7421de..c27c439786 100644 --- a/lib/Elastica/Param.php +++ b/lib/Elastica/Param.php @@ -10,7 +10,7 @@ * * @author Nicolas Ruflin */ -class Param implements ArrayableInterface +class Param implements ArrayableInterface, \Countable { /** * Params. @@ -188,4 +188,14 @@ public function getParams() { return $this->_params; } + + /** + * @inheritdoc + * + * @return int + */ + public function count() + { + return count($this->_params); + } } diff --git a/lib/Elastica/Query.php b/lib/Elastica/Query.php index 2cddfeb50e..a91016c1cd 100644 --- a/lib/Elastica/Query.php +++ b/lib/Elastica/Query.php @@ -401,7 +401,7 @@ public function toArray() unset($this->_params['facets']); } - if (isset($this->_params['post_filter']) && 0 === count($this->_params['post_filter'])) { + if (isset($this->_params['post_filter']) && 0 === count(($this->_params['post_filter'])->toArray())) { unset($this->_params['post_filter']); } diff --git a/lib/Elastica/ResultSet.php b/lib/Elastica/ResultSet.php index f1260e4f87..382415eb4a 100644 --- a/lib/Elastica/ResultSet.php +++ b/lib/Elastica/ResultSet.php @@ -297,7 +297,7 @@ public function getQuery() */ public function count() { - return sizeof($this->_results); + return count($this->_results); } /** diff --git a/test/lib/Elastica/Test/Filter/GeoPolygonTest.php b/test/lib/Elastica/Test/Filter/GeoPolygonTest.php index b56f73b04f..0cf36a2933 100644 --- a/test/lib/Elastica/Test/Filter/GeoPolygonTest.php +++ b/test/lib/Elastica/Test/Filter/GeoPolygonTest.php @@ -50,7 +50,8 @@ public function testGeoPoint() $query = new Query(new MatchAll()); $query->setPostFilter($geoFilter); - $this->assertEquals(1, $type->search($query)->count()); + $a = $type->search($query); + $this->assertEquals(1, $a->count()); // Both points should be inside $query = new Query(); diff --git a/test/lib/Elastica/Test/ResponseTest.php b/test/lib/Elastica/Test/ResponseTest.php index 77fc1482b3..6e44abac4f 100644 --- a/test/lib/Elastica/Test/ResponseTest.php +++ b/test/lib/Elastica/Test/ResponseTest.php @@ -200,6 +200,6 @@ public function testGetDataEmpty() Request::GET )->getData(); - $this->assertEquals(0, count($response)); + $this->assertNull($response); } }