Skip to content

Commit d6974ec

Browse files
committed
implement Countable on Objects
1 parent 038fc0d commit d6974ec

File tree

10 files changed

+69
-6
lines changed

10 files changed

+69
-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
@@ -39,6 +39,7 @@ All notable changes to this project will be documented in this file based on the
3939

4040
- Added `Query\SpanContaining`, `Query\SpanWithin` and `Query\SpanNot` [#1319](https://github.com/ruflin/Elastica/pull/1319)
4141
- 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)
42+
- 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.
4243

4344
### Improvements
4445

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

+10
Original file line numberDiff line numberDiff line change
@@ -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/AbstractQuery.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
*
99
* @author Nicolas Ruflin <[email protected]>
1010
*/
11-
abstract class AbstractQuery extends Param
11+
abstract class AbstractQuery extends Param implements \Countable
1212
{
1313
}

lib/Elastica/Response.php

+14
Original file line numberDiff line numberDiff line change
@@ -361,4 +361,18 @@ public function getJsonBigintConversion()
361361
{
362362
return $this->_jsonBigintConversion;
363363
}
364+
365+
// /**
366+
// * @inheritdoc
367+
// *
368+
// * @return int
369+
// */
370+
// public function count()
371+
// {
372+
// if (null == $this->_response) {
373+
// return 0;
374+
// }
375+
//
376+
// return count($this->_response);
377+
// }
364378
}

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ 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+
var_dump($a);
54+
$this->assertEquals(1, $a->count());
5355

5456
// Both points should be inside
5557
$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-2
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ public function testGetDataEmpty()
236236
$this->assertContains('non-existent-type', $error['reason']);
237237
}
238238

239-
240-
$this->assertEquals(0, count($response));
239+
$this->assertNull($response);
241240
}
242241
}

0 commit comments

Comments
 (0)