Skip to content

Commit 136e366

Browse files
p365labsruflin
authored andcommitted
implement Countable on Objects (#1378)
1 parent b2c37db commit 136e366

File tree

10 files changed

+66
-6
lines changed

10 files changed

+66
-6
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ branches:
1414
env:
1515
- TARGET="70"
1616
- TARGET="71"
17+
- TARGET="72"
1718

1819
before_install:
1920
# check running "docker engine" and "docker-compose" version on travis

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ All notable changes to this project will be documented in this file based on the
6262

6363
- Added `Query\SpanContaining`, `Query\SpanWithin` and `Query\SpanNot` [#1319](https://github.com/ruflin/Elastica/pull/1319)
6464
- Implemented [Pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/pipeline.html) and [Processors](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest-processors.html). [#1373](https://github.com/ruflin/Elastica/pull/1373)
65+
- 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. [#1378](https://github.com/ruflin/Elastica/pull/1378)
6566

6667

6768
## [5.3.0](https://github.com/ruflin/Elastica/compare/5.2.1...5.3.0)

env/elastica/Docker72

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This image is the base image for the Elastica development and includes all parts which rarely change
2+
# PHP 7 Docker file with Composer installed
3+
FROM php:7.2-rc
4+
MAINTAINER Nicolas Ruflin <[email protected]>
5+
6+
RUN apt-get update && apt-get install -y \
7+
cloc \
8+
git \
9+
graphviz \
10+
libxslt-dev \
11+
nano \
12+
13+
zip unzip \
14+
wget
15+
# XSL and Graphviz for PhpDocumentor
16+
17+
RUN docker-php-ext-install sockets xsl
18+
19+
RUN rm -r /var/lib/apt/lists/*
20+
21+
## PHP Configuration
22+
23+
RUN echo "memory_limit=1024M" >> /usr/local/etc/php/conf.d/memory-limit.ini
24+
RUN echo "date.timezone=UTC" >> /usr/local/etc/php/conf.d/timezone.ini
25+
26+
# Install and setup composer
27+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
28+
ENV COMPOSER_HOME /root/composer
29+
30+
# Add composer bin to the environment
31+
ENV PATH=/root/composer/vendor/bin:$PATH
32+
33+
COPY composer.json /root/composer/
34+
35+
# Install development tools, prefer source removed as automatic fallback now
36+
RUN composer global install

lib/Elastica/Param.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* @author Nicolas Ruflin <[email protected]>
1212
*/
13-
class Param implements ArrayableInterface
13+
class Param implements ArrayableInterface, \Countable
1414
{
1515
/**
1616
* Params.
@@ -180,4 +180,14 @@ public function getParams()
180180
{
181181
return $this->_params;
182182
}
183+
184+
/**
185+
* @inheritdoc
186+
*
187+
* @return int
188+
*/
189+
public function count()
190+
{
191+
return count($this->_params);
192+
}
183193
}

lib/Elastica/Query.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function toArray()
330330
$this->setQuery(new MatchAll());
331331
}
332332

333-
if (isset($this->_params['post_filter']) && 0 === count($this->_params['post_filter'])) {
333+
if (isset($this->_params['post_filter']) && 0 === count(($this->_params['post_filter'])->toArray())) {
334334
unset($this->_params['post_filter']);
335335
}
336336

lib/Elastica/Query/GeoPolygon.php

+11
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,15 @@ public function toArray()
5353
],
5454
];
5555
}
56+
57+
/**
58+
* @inheritdoc
59+
*
60+
* @return int
61+
*/
62+
public function count()
63+
{
64+
return count($this->_key);
65+
}
66+
5667
}

lib/Elastica/ResultSet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function getQuery()
220220
*/
221221
public function count()
222222
{
223-
return sizeof($this->_results);
223+
return count($this->_results);
224224
}
225225

226226
/**

test/Elastica/Query/GeoPolygonTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public function testGeoPoint()
4949

5050
$query = new Query(new MatchAll());
5151
$query->setPostFilter($geoQuery);
52-
$this->assertEquals(1, $type->search($query)->count());
52+
$a = $type->search($query);
53+
$this->assertEquals(1, $a->count());
5354

5455
// Both points should be inside
5556
$query = new Query();

test/Elastica/QueryBuilder/VersionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private function assertVersions(Version $version, array $dsl)
4747
foreach ($version->getSuggesters() as $suggester) {
4848
$this->assertTrue(
4949
method_exists($dsl[2], $suggester),
50-
'suggester "'.$suggester.'" in '.get_class($version).' must be defined in '.get_class($dsl[3])
50+
'suggester "'.$suggester.'" in '.get_class($version).' must be defined in '.get_class($dsl[2])
5151
);
5252
}
5353
}

test/Elastica/ResponseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,6 @@ public function testGetDataEmpty()
236236
$this->assertContains('non-existent-type', $error['reason']);
237237
}
238238

239-
$this->assertEquals(0, count($response));
239+
$this->assertNull($response);
240240
}
241241
}

0 commit comments

Comments
 (0)