From 43b1ddd94eb345a1c87d8a8f747875884ea4d023 Mon Sep 17 00:00:00 2001 From: Karel Souffriau Date: Wed, 14 Jan 2015 12:28:28 +0100 Subject: [PATCH] A Little Housekeeping --- lib/Elastica/AbstractUpdateAction.php | 52 +++++----- .../Aggregation/AbstractAggregation.php | 6 +- .../Aggregation/AbstractSimpleAggregation.php | 9 +- lib/Elastica/Aggregation/Avg.php | 4 +- lib/Elastica/Aggregation/Cardinality.php | 4 +- lib/Elastica/Aggregation/DateHistogram.php | 16 +-- lib/Elastica/Aggregation/DateRange.php | 4 +- lib/Elastica/Aggregation/ExtendedStats.php | 3 +- lib/Elastica/Aggregation/Filter.php | 10 +- lib/Elastica/Aggregation/GeoDistance.php | 19 ++-- lib/Elastica/Aggregation/GeohashGrid.php | 12 +-- .../Aggregation/GlobalAggregation.php | 3 +- lib/Elastica/Aggregation/Histogram.php | 17 ++-- lib/Elastica/Aggregation/IpRange.php | 14 +-- lib/Elastica/Aggregation/Max.php | 3 +- lib/Elastica/Aggregation/Min.php | 3 +- lib/Elastica/Aggregation/Missing.php | 6 +- lib/Elastica/Aggregation/Nested.php | 4 +- lib/Elastica/Aggregation/Range.php | 11 +-- lib/Elastica/Aggregation/ReverseNested.php | 4 +- lib/Elastica/Aggregation/Stats.php | 3 +- lib/Elastica/Aggregation/Sum.php | 3 +- lib/Elastica/Aggregation/Terms.php | 28 +++--- lib/Elastica/Aggregation/ValueCount.php | 6 +- lib/Elastica/Bulk.php | 74 +++++++------- lib/Elastica/Bulk/Action.php | 34 ++++--- lib/Elastica/Bulk/Action/AbstractDocument.php | 37 ++++--- lib/Elastica/Bulk/Action/DeleteDocument.php | 4 +- lib/Elastica/Bulk/Action/IndexDocument.php | 4 +- lib/Elastica/Bulk/Action/UpdateDocument.php | 10 +- lib/Elastica/Bulk/Response.php | 4 +- lib/Elastica/Bulk/ResponseSet.php | 2 +- lib/Elastica/Client.php | 98 +++++++++---------- lib/Elastica/Cluster.php | 7 +- lib/Elastica/Cluster/Health.php | 1 + lib/Elastica/Cluster/Settings.php | 38 +++---- lib/Elastica/Connection.php | 41 ++++---- lib/Elastica/Connection/ConnectionPool.php | 44 ++++----- .../Connection/Strategy/CallbackStrategy.php | 15 ++- .../Connection/Strategy/RoundRobin.php | 5 +- lib/Elastica/Connection/Strategy/Simple.php | 12 +-- .../Connection/Strategy/StrategyFactory.php | 12 +-- .../Connection/Strategy/StrategyInterface.php | 2 +- lib/Elastica/Document.php | 61 ++++++------ .../Bulk/Response/ActionException.php | 8 +- .../Exception/Bulk/ResponseException.php | 7 +- .../Exception/Connection/GuzzleException.php | 6 +- .../Exception/Connection/HttpException.php | 4 +- .../Exception/Connection/ThriftException.php | 6 +- .../Exception/ConnectionException.php | 2 +- .../Exception/ElasticsearchException.php | 8 +- .../PartialShardFailureException.php | 4 +- lib/Elastica/Exception/ResponseException.php | 5 +- lib/Elastica/Facet/AbstractFacet.php | 12 +-- lib/Elastica/Facet/DateHistogram.php | 2 +- lib/Elastica/Facet/GeoCluster.php | 28 ++++-- lib/Elastica/Facet/GeoDistance.php | 10 +- lib/Elastica/Facet/Histogram.php | 14 +-- lib/Elastica/Facet/Range.php | 12 +-- lib/Elastica/Facet/Statistical.php | 6 +- lib/Elastica/Facet/Terms.php | 16 +-- lib/Elastica/Facet/TermsStats.php | 30 +++--- lib/Elastica/Filter/AbstractFilter.php | 6 +- lib/Elastica/Filter/AbstractGeoDistance.php | 15 ++- lib/Elastica/Filter/AbstractMulti.php | 4 +- lib/Elastica/Filter/Bool.php | 18 ++-- lib/Elastica/Filter/Exists.php | 2 +- lib/Elastica/Filter/GeoBoundingBox.php | 6 +- lib/Elastica/Filter/GeoDistance.php | 12 +-- lib/Elastica/Filter/GeoDistanceRange.php | 8 +- lib/Elastica/Filter/GeoPolygon.php | 5 +- lib/Elastica/Filter/GeoShapePreIndexed.php | 8 +- lib/Elastica/Filter/GeoShapeProvided.php | 6 +- lib/Elastica/Filter/GeohashCell.php | 15 ++- lib/Elastica/Filter/HasChild.php | 8 +- lib/Elastica/Filter/HasParent.php | 6 +- lib/Elastica/Filter/Ids.php | 14 +-- lib/Elastica/Filter/Indices.php | 16 +-- lib/Elastica/Filter/Limit.php | 4 +- lib/Elastica/Filter/Nested.php | 2 +- lib/Elastica/Filter/Prefix.php | 4 +- lib/Elastica/Filter/Query.php | 2 +- lib/Elastica/Filter/Range.php | 4 +- lib/Elastica/Filter/Regexp.php | 8 +- lib/Elastica/Filter/Term.php | 6 +- lib/Elastica/Filter/Terms.php | 33 ++++--- lib/Elastica/Filter/Type.php | 6 +- lib/Elastica/Index.php | 58 +++++------ lib/Elastica/Index/Settings.php | 50 +++++----- lib/Elastica/Index/Stats.php | 3 +- lib/Elastica/Index/Status.php | 6 +- lib/Elastica/JSON.php | 2 +- lib/Elastica/Log.php | 12 +-- lib/Elastica/Multi/ResultSet.php | 15 +-- lib/Elastica/Multi/Search.php | 24 ++--- lib/Elastica/Node.php | 7 +- lib/Elastica/Node/Info.php | 22 +++-- lib/Elastica/Node/Stats.php | 4 +- lib/Elastica/Param.php | 25 ++--- lib/Elastica/Percolator.php | 47 ++++----- lib/Elastica/Query.php | 59 +++++------ lib/Elastica/Query/AbstractQuery.php | 1 + lib/Elastica/Query/Bool.php | 14 +-- lib/Elastica/Query/Boosting.php | 8 +- lib/Elastica/Query/Builder.php | 6 +- lib/Elastica/Query/Common.php | 40 ++++---- lib/Elastica/Query/ConstantScore.php | 7 +- lib/Elastica/Query/DisMax.php | 1 + lib/Elastica/Query/Filtered.php | 5 +- lib/Elastica/Query/FunctionScore.php | 83 ++++++++-------- lib/Elastica/Query/Fuzzy.php | 23 +++-- lib/Elastica/Query/FuzzyLikeThis.php | 18 ++-- lib/Elastica/Query/HasChild.php | 7 +- lib/Elastica/Query/HasParent.php | 9 +- lib/Elastica/Query/Ids.php | 11 ++- lib/Elastica/Query/Match.php | 58 +++++------ lib/Elastica/Query/MoreLikeThis.php | 26 ++--- lib/Elastica/Query/MultiMatch.php | 28 +++--- lib/Elastica/Query/Nested.php | 4 +- lib/Elastica/Query/Prefix.php | 8 +- lib/Elastica/Query/QueryString.php | 41 ++++---- lib/Elastica/Query/Range.php | 4 +- lib/Elastica/Query/Simple.php | 2 +- lib/Elastica/Query/SimpleQueryString.php | 12 +-- lib/Elastica/Query/Term.php | 8 +- lib/Elastica/Query/Terms.php | 11 ++- lib/Elastica/Query/TopChildren.php | 5 +- lib/Elastica/Query/Wildcard.php | 6 +- lib/Elastica/QueryBuilder.php | 4 +- lib/Elastica/QueryBuilder/DSL/Aggregation.php | 66 ++++++------- lib/Elastica/QueryBuilder/DSL/Filter.php | 94 +++++++++--------- lib/Elastica/QueryBuilder/DSL/Query.php | 42 ++++---- lib/Elastica/QueryBuilder/Facade.php | 10 +- lib/Elastica/QueryBuilder/Version.php | 3 +- .../QueryBuilder/Version/Version090.php | 2 +- .../QueryBuilder/Version/Version100.php | 2 +- .../QueryBuilder/Version/Version110.php | 6 +- .../QueryBuilder/Version/Version120.php | 6 +- .../QueryBuilder/Version/Version130.php | 6 +- .../QueryBuilder/Version/Version140.php | 7 +- lib/Elastica/Request.php | 20 ++-- lib/Elastica/Rescore/AbstractRescore.php | 9 +- lib/Elastica/Rescore/Query.php | 6 +- lib/Elastica/Response.php | 13 ++- lib/Elastica/Result.php | 14 +-- lib/Elastica/ResultSet.php | 54 +++++----- lib/Elastica/ScanAndScroll.php | 35 ++++--- lib/Elastica/Script.php | 2 +- lib/Elastica/ScriptFields.php | 3 +- lib/Elastica/Search.php | 52 +++++----- lib/Elastica/SearchableInterface.php | 6 +- lib/Elastica/Snapshot.php | 65 ++++++------ lib/Elastica/Status.php | 6 +- lib/Elastica/Suggest.php | 14 ++- lib/Elastica/Suggest/AbstractSuggest.php | 13 +-- .../AbstractCandidateGenerator.php | 4 +- .../CandidateGenerator/DirectGenerator.php | 25 +++-- lib/Elastica/Suggest/Phrase.php | 44 ++++----- lib/Elastica/Suggest/Term.php | 31 +++--- lib/Elastica/Transport/AbstractTransport.php | 12 +-- lib/Elastica/Transport/Guzzle.php | 27 +++-- lib/Elastica/Transport/Http.php | 15 ++- lib/Elastica/Transport/HttpAdapter.php | 18 ++-- lib/Elastica/Transport/Memcache.php | 10 +- lib/Elastica/Transport/Null.php | 16 +-- lib/Elastica/Transport/Thrift.php | 31 +++--- lib/Elastica/Type.php | 67 ++++++------- lib/Elastica/Type/AbstractType.php | 6 +- lib/Elastica/Type/Mapping.php | 41 ++++---- lib/Elastica/Util.php | 24 ++--- 170 files changed, 1442 insertions(+), 1416 deletions(-) diff --git a/lib/Elastica/AbstractUpdateAction.php b/lib/Elastica/AbstractUpdateAction.php index 883284aedb..0f7c0203d4 100644 --- a/lib/Elastica/AbstractUpdateAction.php +++ b/lib/Elastica/AbstractUpdateAction.php @@ -20,7 +20,7 @@ class AbstractUpdateAction extends Param /** * Sets the id of the document. * - * @param string $id + * @param string $id * @return \Elastica\Document */ public function setId($id) @@ -49,7 +49,7 @@ public function hasId() /** * Sets lifetime of document * - * @param string $ttl + * @param string $ttl * @return \Elastica\Document */ public function setTtl($ttl) @@ -76,7 +76,7 @@ public function hasTtl() /** * Sets the document type name * - * @param string $type Type name + * @param string $type Type name * @return \Elastica\Document Current object */ public function setType($type) @@ -85,13 +85,14 @@ public function setType($type) $this->setIndex($type->getIndex()); $type = $type->getName(); } + return $this->setParam('_type', $type); } /** * Return document type name * - * @return string Document type name + * @return string Document type name * @throws \Elastica\Exception\InvalidException */ public function getType() @@ -102,7 +103,7 @@ public function getType() /** * Sets the document index name * - * @param string $index Index name + * @param string $index Index name * @return \Elastica\Document Current object */ public function setIndex($index) @@ -110,13 +111,14 @@ public function setIndex($index) if ($index instanceof Index) { $index = $index->getName(); } + return $this->setParam('_index', $index); } /** * Get the document index name * - * @return string Index name + * @return string Index name * @throws \Elastica\Exception\InvalidException */ public function getIndex() @@ -127,7 +129,7 @@ public function getIndex() /** * Sets the version of a document for use with optimistic concurrency control * - * @param int $version Document version + * @param int $version Document version * @return \Elastica\Document Current object * @link http://www.elasticsearch.org/blog/2011/02/08/versioning.html */ @@ -158,7 +160,7 @@ public function hasVersion() * Sets the version_type of a document * Default in ES is internal, but you can set to external to use custom versioning * - * @param int $versionType Document version type + * @param int $versionType Document version type * @return \Elastica\Document Current object * @link http://www.elasticsearch.org/guide/reference/api/index_.html */ @@ -188,7 +190,7 @@ public function hasVersionType() /** * Sets parent document id * - * @param string|int $parent Parent document id + * @param string|int $parent Parent document id * @return \Elastica\Document Current object * @link http://www.elasticsearch.org/guide/reference/mapping/parent-field.html */ @@ -218,7 +220,7 @@ public function hasParent() /** * Set operation type * - * @param string $opType Only accept create + * @param string $opType Only accept create * @return \Elastica\Document Current object */ public function setOpType($opType) @@ -246,7 +248,7 @@ public function hasOpType() /** * Set percolate query param * - * @param string $value percolator filter + * @param string $value percolator filter * @return \Elastica\Document */ public function setPercolate($value = '*') @@ -275,7 +277,7 @@ public function hasPercolate() /** * Set routing query param * - * @param string $value routing + * @param string $value routing * @return \Elastica\Document */ public function setRouting($value) @@ -302,7 +304,7 @@ public function hasRouting() } /** - * @param array|string $fields + * @param array|string $fields * @return \Elastica\Document */ public function setFields($fields) @@ -310,6 +312,7 @@ public function setFields($fields) if (is_array($fields)) { $fields = implode(',', $fields); } + return $this->setParam('_fields', (string) $fields); } @@ -338,7 +341,7 @@ public function hasFields() } /** - * @param int $num + * @param int $num * @return \Elastica\Document */ public function setRetryOnConflict($num) @@ -363,7 +366,7 @@ public function hasRetryOnConflict() } /** - * @param string $timestamp + * @param string $timestamp * @return \Elastica\Document */ public function setTimestamp($timestamp) @@ -388,7 +391,7 @@ public function hasTimestamp() } /** - * @param bool $refresh + * @param bool $refresh * @return \Elastica\Document */ public function setRefresh($refresh = true) @@ -413,7 +416,7 @@ public function hasRefresh() } /** - * @param string $timeout + * @param string $timeout * @return \Elastica\Document */ public function setTimeout($timeout) @@ -438,7 +441,7 @@ public function hasTimeout() } /** - * @param string $timeout + * @param string $timeout * @return \Elastica\Document */ public function setConsistency($timeout) @@ -463,7 +466,7 @@ public function hasConsistency() } /** - * @param string $timeout + * @param string $timeout * @return \Elastica\Document */ public function setReplication($timeout) @@ -488,7 +491,7 @@ public function hasReplication() } /** - * @param \Elastica\Document|array $data + * @param \Elastica\Document|array $data * @return \Elastica\Document */ public function setUpsert($data) @@ -516,8 +519,8 @@ public function hasUpsert() } /** - * @param array $fields if empty array all options will be returned, field names can be either with underscored either without, i.e. _percolate, routing - * @param bool $withUnderscore should option keys contain underscore prefix + * @param array $fields if empty array all options will be returned, field names can be either with underscored either without, i.e. _percolate, routing + * @param bool $withUnderscore should option keys contain underscore prefix * @return array */ public function getOptions(array $fields = array(), $withUnderscore = false) @@ -525,7 +528,7 @@ public function getOptions(array $fields = array(), $withUnderscore = false) if (!empty($fields)) { $data = array(); foreach ($fields as $field) { - $key = '_' . ltrim($field, '_'); + $key = '_'.ltrim($field, '_'); if ($this->hasParam($key) && '' !== (string) $this->getParam($key)) { $data[$key] = $this->getParam($key); } @@ -539,6 +542,7 @@ public function getOptions(array $fields = array(), $withUnderscore = false) unset($data[$key]); } } + return $data; } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/AbstractAggregation.php b/lib/Elastica/Aggregation/AbstractAggregation.php index ba092620ec..501d9a3db8 100644 --- a/lib/Elastica/Aggregation/AbstractAggregation.php +++ b/lib/Elastica/Aggregation/AbstractAggregation.php @@ -56,7 +56,7 @@ public function getAggs() /** * Add a sub-aggregation - * @param AbstractAggregation $aggregation + * @param AbstractAggregation $aggregation * @throws \Elastica\Exception\InvalidException * @return AbstractAggregation */ @@ -67,6 +67,7 @@ public function addAggregation(AbstractAggregation $aggregation) } $this->_aggs[$aggregation->getName()] = $aggregation->toArray(); + return $this; } @@ -78,11 +79,12 @@ public function toArray() $array = parent::toArray(); if (array_key_exists('global_aggregation', $array)) { // compensate for class name GlobalAggregation - $array = array('global' => new \stdClass); + $array = array('global' => new \stdClass()); } if (sizeof($this->_aggs)) { $array['aggs'] = $this->_aggs; } + return $array; } } diff --git a/lib/Elastica/Aggregation/AbstractSimpleAggregation.php b/lib/Elastica/Aggregation/AbstractSimpleAggregation.php index e06754abfe..5c4b76bc63 100644 --- a/lib/Elastica/Aggregation/AbstractSimpleAggregation.php +++ b/lib/Elastica/Aggregation/AbstractSimpleAggregation.php @@ -2,14 +2,13 @@ namespace Elastica\Aggregation; - use Elastica\Script; abstract class AbstractSimpleAggregation extends AbstractAggregation { /** * Set the field for this aggregation - * @param string $field the name of the document field on which to perform this aggregation + * @param string $field the name of the document field on which to perform this aggregation * @return AbstractSimpleAggregation */ public function setField($field) @@ -19,15 +18,17 @@ public function setField($field) /** * Set a script for this aggregation - * @param string|Script $script + * @param string|Script $script * @return AbstractSimpleAggregation */ public function setScript($script) { if ($script instanceof Script) { $params = array_merge($this->getParams(), $script->toArray()); + return $this->setParams($params); } + return $this->setParam('script', $script); } -} +} diff --git a/lib/Elastica/Aggregation/Avg.php b/lib/Elastica/Aggregation/Avg.php index 0d6019109b..c7c3a5b363 100644 --- a/lib/Elastica/Aggregation/Avg.php +++ b/lib/Elastica/Aggregation/Avg.php @@ -2,7 +2,6 @@ namespace Elastica\Aggregation; - /** * Class Avg * @package Elastica\Aggregation @@ -10,5 +9,4 @@ */ class Avg extends AbstractSimpleAggregation { - -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Cardinality.php b/lib/Elastica/Aggregation/Cardinality.php index 061ddafa5d..24711c1863 100644 --- a/lib/Elastica/Aggregation/Cardinality.php +++ b/lib/Elastica/Aggregation/Cardinality.php @@ -2,7 +2,6 @@ namespace Elastica\Aggregation; - /** * Class Cardinality * @package Elastica\Aggregation @@ -10,5 +9,4 @@ */ class Cardinality extends AbstractSimpleAggregation { - -} +} diff --git a/lib/Elastica/Aggregation/DateHistogram.php b/lib/Elastica/Aggregation/DateHistogram.php index 889fa429ea..f88aed5ec9 100644 --- a/lib/Elastica/Aggregation/DateHistogram.php +++ b/lib/Elastica/Aggregation/DateHistogram.php @@ -11,7 +11,7 @@ class DateHistogram extends Histogram { /** * Set pre-rounding based on interval - * @param string $preZone + * @param string $preZone * @return DateHistogram */ public function setPreZone($preZone) @@ -21,7 +21,7 @@ public function setPreZone($preZone) /** * Set post-rounding based on interval - * @param string $postZone + * @param string $postZone * @return DateHistogram */ public function setPostZone($postZone) @@ -31,7 +31,7 @@ public function setPostZone($postZone) /** * Set pre-zone adjustment for larger time intervals (day and above) - * @param string $adjust + * @param string $adjust * @return DateHistogram */ public function setPreZoneAdjustLargeInterval($adjust) @@ -41,7 +41,7 @@ public function setPreZoneAdjustLargeInterval($adjust) /** * Adjust for granularity of date data - * @param int $factor set to 1000 if date is stored in seconds rather than milliseconds + * @param int $factor set to 1000 if date is stored in seconds rather than milliseconds * @return DateHistogram */ public function setFactor($factor) @@ -51,7 +51,7 @@ public function setFactor($factor) /** * Set the offset for pre-rounding - * @param string $offset "1d", for example + * @param string $offset "1d", for example * @return DateHistogram */ public function setPreOffset($offset) @@ -61,7 +61,7 @@ public function setPreOffset($offset) /** * Set the offset for post-rounding - * @param string $offset "1d", for example + * @param string $offset "1d", for example * @return DateHistogram */ public function setPostOffset($offset) @@ -72,11 +72,11 @@ public function setPostOffset($offset) /** * Set the format for returned bucket key_as_string values * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-aggregations-bucket-daterange-aggregation.html#date-format-pattern - * @param string $format see link for formatting options + * @param string $format see link for formatting options * @return DateHistogram */ public function setFormat($format) { return $this->setParam("format", $format); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/DateRange.php b/lib/Elastica/Aggregation/DateRange.php index 37aca87bbc..9835033a50 100644 --- a/lib/Elastica/Aggregation/DateRange.php +++ b/lib/Elastica/Aggregation/DateRange.php @@ -11,11 +11,11 @@ class DateRange extends Range { /** * Set the formatting for the returned date values - * @param string $format see documentation for formatting options + * @param string $format see documentation for formatting options * @return Range */ public function setFormat($format) { return $this->setParam('format', $format); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/ExtendedStats.php b/lib/Elastica/Aggregation/ExtendedStats.php index 4aef8a3207..2808e99d1c 100644 --- a/lib/Elastica/Aggregation/ExtendedStats.php +++ b/lib/Elastica/Aggregation/ExtendedStats.php @@ -9,5 +9,4 @@ */ class ExtendedStats extends AbstractSimpleAggregation { - -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Filter.php b/lib/Elastica/Aggregation/Filter.php index c2326ffebc..291d4e6c6e 100644 --- a/lib/Elastica/Aggregation/Filter.php +++ b/lib/Elastica/Aggregation/Filter.php @@ -2,7 +2,6 @@ namespace Elastica\Aggregation; - use Elastica\Filter\AbstractFilter; /** @@ -14,7 +13,7 @@ class Filter extends AbstractAggregation { /** * Set the filter for this aggregation - * @param AbstractFilter $filter + * @param AbstractFilter $filter * @return Filter */ public function setFilter(AbstractFilter $filter) @@ -28,14 +27,13 @@ public function setFilter(AbstractFilter $filter) public function toArray() { $array = array( - "filter" => $this->getParam("filter") + "filter" => $this->getParam("filter"), ); - if($this->_aggs) - { + if ($this->_aggs) { $array['aggs'] = $this->_aggs; } return $array; } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/GeoDistance.php b/lib/Elastica/Aggregation/GeoDistance.php index 76c871ea0a..8c49cc488d 100644 --- a/lib/Elastica/Aggregation/GeoDistance.php +++ b/lib/Elastica/Aggregation/GeoDistance.php @@ -16,8 +16,8 @@ class GeoDistance extends AbstractAggregation const DISTANCE_TYPE_PLANE = "plane"; /** - * @param string $name the name if this aggregation - * @param string $field the field on which to perform this aggregation + * @param string $name the name if this aggregation + * @param string $field the field on which to perform this aggregation * @param string|array $origin the point from which distances will be calculated */ public function __construct($name, $field, $origin) @@ -28,7 +28,7 @@ public function __construct($name, $field, $origin) /** * Set the field for this aggregation - * @param string $field the name of the document field on which to perform this aggregation + * @param string $field the name of the document field on which to perform this aggregation * @return GeoDistance */ public function setField($field) @@ -38,7 +38,7 @@ public function setField($field) /** * Set the origin point from which distances will be calculated - * @param string|array $origin valid formats are array("lat" => 52.3760, "lon" => 4.894), "52.3760, 4.894", and array(4.894, 52.3760) + * @param string|array $origin valid formats are array("lat" => 52.3760, "lon" => 4.894), "52.3760, 4.894", and array(4.894, 52.3760) * @return GeoDistance */ public function setOrigin($origin) @@ -48,8 +48,8 @@ public function setOrigin($origin) /** * Add a distance range to this aggregation - * @param int $fromValue a distance - * @param int $toValue a distance + * @param int $fromValue a distance + * @param int $toValue a distance * @return GeoDistance * @throws \Elastica\Exception\InvalidException */ @@ -65,12 +65,13 @@ public function addRange($fromValue = null, $toValue = null) if (!is_null($toValue)) { $range['to'] = $toValue; } + return $this->addParam("ranges", $range); } /** * Set the unit of distance measure for this aggregation - * @param string $unit defaults to km + * @param string $unit defaults to km * @return GeoDistance */ public function setUnit($unit) @@ -80,11 +81,11 @@ public function setUnit($unit) /** * Set the method by which distances will be calculated - * @param string $distanceType see DISTANCE_TYPE_* constants for options. Defaults to sloppy_arc. + * @param string $distanceType see DISTANCE_TYPE_* constants for options. Defaults to sloppy_arc. * @return GeoDistance */ public function setDistanceType($distanceType) { return $this->setParam("distance_type", $distanceType); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/GeohashGrid.php b/lib/Elastica/Aggregation/GeohashGrid.php index 840198c3ce..86f6f502df 100644 --- a/lib/Elastica/Aggregation/GeohashGrid.php +++ b/lib/Elastica/Aggregation/GeohashGrid.php @@ -10,7 +10,7 @@ class GeohashGrid extends AbstractAggregation { /** - * @param string $name the name of this aggregation + * @param string $name the name of this aggregation * @param string $field the field on which to perform this aggregation */ public function __construct($name, $field) @@ -21,7 +21,7 @@ public function __construct($name, $field) /** * Set the field for this aggregation - * @param string $field the name of the document field on which to perform this aggregation + * @param string $field the name of the document field on which to perform this aggregation * @return GeohashGrid */ public function setField($field) @@ -31,7 +31,7 @@ public function setField($field) /** * Set the precision for this aggregation - * @param int $precision an integer between 1 and 12, inclusive. Defaults to 5. + * @param int $precision an integer between 1 and 12, inclusive. Defaults to 5. * @return GeohashGrid */ public function setPrecision($precision) @@ -41,7 +41,7 @@ public function setPrecision($precision) /** * Set the maximum number of buckets to return - * @param int $size defaults to 10,000 + * @param int $size defaults to 10,000 * @return GeohashGrid */ public function setSize($size) @@ -51,11 +51,11 @@ public function setSize($size) /** * Set the number of results returned from each shard - * @param int $shardSize + * @param int $shardSize * @return GeohashGrid */ public function setShardSize($shardSize) { return $this->setParam("shard_size", $shardSize); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/GlobalAggregation.php b/lib/Elastica/Aggregation/GlobalAggregation.php index 72b5688082..1affb204ec 100644 --- a/lib/Elastica/Aggregation/GlobalAggregation.php +++ b/lib/Elastica/Aggregation/GlobalAggregation.php @@ -9,5 +9,4 @@ */ class GlobalAggregation extends AbstractAggregation { - -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Histogram.php b/lib/Elastica/Aggregation/Histogram.php index 26fa7c4431..7d4aa8d2e8 100644 --- a/lib/Elastica/Aggregation/Histogram.php +++ b/lib/Elastica/Aggregation/Histogram.php @@ -10,9 +10,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 $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 $interval the interval by which documents will be bucketed */ public function __construct($name, $field, $interval) { @@ -21,10 +21,9 @@ public function __construct($name, $field, $interval) $this->setInterval($interval); } - /** * Set the interval by which documents will be bucketed - * @param int $interval + * @param int $interval * @return Histogram */ public function setInterval($interval) @@ -34,8 +33,8 @@ public function setInterval($interval) /** * Set the bucket sort order - * @param string $order "_count", "_term", or the name of a sub-aggregation or sub-aggregation response field - * @param string $direction "asc" or "desc" + * @param string $order "_count", "_term", or the name of a sub-aggregation or sub-aggregation response field + * @param string $direction "asc" or "desc" * @return Histogram */ public function setOrder($order, $direction) @@ -45,11 +44,11 @@ public function setOrder($order, $direction) /** * Set the minimum number of documents which must fall into a bucket in order for the bucket to be returned - * @param int $count set to 0 to include empty buckets + * @param int $count set to 0 to include empty buckets * @return Histogram */ public function setMinimumDocumentCount($count) { return $this->setParam("min_doc_count", $count); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/IpRange.php b/lib/Elastica/Aggregation/IpRange.php index 18e60bfbc5..9b58ff8312 100644 --- a/lib/Elastica/Aggregation/IpRange.php +++ b/lib/Elastica/Aggregation/IpRange.php @@ -2,7 +2,6 @@ namespace Elastica\Aggregation; - use Elastica\Exception\InvalidException; /** @@ -13,7 +12,7 @@ class IpRange extends AbstractAggregation { /** - * @param string $name the name of this aggregation + * @param string $name the name of this aggregation * @param string $field the field on which to perform this aggregation */ public function __construct($name, $field) @@ -24,7 +23,7 @@ public function __construct($name, $field) /** * Set the field for this aggregation - * @param string $field the name of the document field on which to perform this aggregation + * @param string $field the name of the document field on which to perform this aggregation * @return IpRange */ public function setField($field) @@ -34,8 +33,8 @@ public function setField($field) /** * Add an ip range to this aggregation - * @param string $fromValue a valid ipv4 address. Low end of this range, exclusive (greater than) - * @param string $toValue a valid ipv4 address. High end of this range, exclusive (less than) + * @param string $fromValue a valid ipv4 address. Low end of this range, exclusive (greater than) + * @param string $toValue a valid ipv4 address. High end of this range, exclusive (less than) * @return IpRange * @throws \Elastica\Exception\InvalidException */ @@ -51,16 +50,17 @@ public function addRange($fromValue = null, $toValue = null) if (!is_null($toValue)) { $range['to'] = $toValue; } + return $this->addParam('ranges', $range); } /** * Add an ip range in the form of a CIDR mask - * @param string $mask a valid CIDR mask + * @param string $mask a valid CIDR mask * @return IpRange */ public function addMaskRange($mask) { return $this->addParam("ranges", array("mask" => $mask)); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Max.php b/lib/Elastica/Aggregation/Max.php index 25031b04eb..2ff528149f 100644 --- a/lib/Elastica/Aggregation/Max.php +++ b/lib/Elastica/Aggregation/Max.php @@ -9,5 +9,4 @@ */ class Max extends AbstractSimpleAggregation { - -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Min.php b/lib/Elastica/Aggregation/Min.php index 60aabb5652..02be6c568e 100644 --- a/lib/Elastica/Aggregation/Min.php +++ b/lib/Elastica/Aggregation/Min.php @@ -9,5 +9,4 @@ */ class Min extends AbstractSimpleAggregation { - -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Missing.php b/lib/Elastica/Aggregation/Missing.php index b882aba04c..8c233c23ad 100644 --- a/lib/Elastica/Aggregation/Missing.php +++ b/lib/Elastica/Aggregation/Missing.php @@ -10,7 +10,7 @@ class Missing extends AbstractAggregation { /** - * @param string $name the name of this aggregation + * @param string $name the name of this aggregation * @param string $field the field on which to perform this aggregation */ public function __construct($name, $field) @@ -21,11 +21,11 @@ public function __construct($name, $field) /** * Set the field for this aggregation - * @param string $field the name of the document field on which to perform this aggregation + * @param string $field the name of the document field on which to perform this aggregation * @return Missing */ public function setField($field) { return $this->setParam('field', $field); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Nested.php b/lib/Elastica/Aggregation/Nested.php index afbb8373d2..1945d8440c 100644 --- a/lib/Elastica/Aggregation/Nested.php +++ b/lib/Elastica/Aggregation/Nested.php @@ -21,11 +21,11 @@ public function __construct($name, $path) /** * Set the nested path for this aggregation - * @param string $path + * @param string $path * @return Nested */ public function setPath($path) { return $this->setParam("path", $path); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Range.php b/lib/Elastica/Aggregation/Range.php index b6cfc22975..543033c772 100644 --- a/lib/Elastica/Aggregation/Range.php +++ b/lib/Elastica/Aggregation/Range.php @@ -1,7 +1,6 @@ setParam('keyed', (bool)$keyed); + return $this->setParam('keyed', (bool) $keyed); } } diff --git a/lib/Elastica/Aggregation/ReverseNested.php b/lib/Elastica/Aggregation/ReverseNested.php index d4056f130c..d641dec7e3 100644 --- a/lib/Elastica/Aggregation/ReverseNested.php +++ b/lib/Elastica/Aggregation/ReverseNested.php @@ -26,7 +26,7 @@ public function __construct($name, $path = null) /** * Set the nested path for this aggregation * - * @param string $path + * @param string $path * @return ReverseNested */ public function setPath($path) @@ -43,7 +43,7 @@ public function toArray() // ensure we have an object for the reverse_nested key. // if we don't have a path, then this would otherwise get encoded as an empty array, which is invalid. - $array['reverse_nested'] = (object)$array['reverse_nested']; + $array['reverse_nested'] = (object) $array['reverse_nested']; return $array; } diff --git a/lib/Elastica/Aggregation/Stats.php b/lib/Elastica/Aggregation/Stats.php index 18c903e961..fa699d105e 100644 --- a/lib/Elastica/Aggregation/Stats.php +++ b/lib/Elastica/Aggregation/Stats.php @@ -9,5 +9,4 @@ */ class Stats extends AbstractSimpleAggregation { - -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Sum.php b/lib/Elastica/Aggregation/Sum.php index 4d1ef4de07..3d2fec8ca6 100644 --- a/lib/Elastica/Aggregation/Sum.php +++ b/lib/Elastica/Aggregation/Sum.php @@ -9,5 +9,4 @@ */ class Sum extends AbstractSimpleAggregation { - -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/Terms.php b/lib/Elastica/Aggregation/Terms.php index 9ede855c82..b45f72a6af 100644 --- a/lib/Elastica/Aggregation/Terms.php +++ b/lib/Elastica/Aggregation/Terms.php @@ -11,8 +11,8 @@ class Terms extends AbstractSimpleAggregation { /** * Set the bucket sort order - * @param string $order "_count", "_term", or the name of a sub-aggregation or sub-aggregation response field - * @param string $direction "asc" or "desc" + * @param string $order "_count", "_term", or the name of a sub-aggregation or sub-aggregation response field + * @param string $direction "asc" or "desc" * @return Terms */ public function setOrder($order, $direction) @@ -22,7 +22,7 @@ public function setOrder($order, $direction) /** * Set the minimum number of documents in which a term must appear in order to be returned in a bucket - * @param int $count + * @param int $count * @return Terms */ public function setMinimumDocumentCount($count) @@ -32,8 +32,8 @@ public function setMinimumDocumentCount($count) /** * Filter documents to include based on a regular expression - * @param string $pattern a regular expression - * @param string $flags Java Pattern flags + * @param string $pattern a regular expression + * @param string $flags Java Pattern flags * @return Terms */ public function setInclude($pattern, $flags = null) @@ -41,16 +41,17 @@ public function setInclude($pattern, $flags = null) if (is_null($flags)) { return $this->setParam("include", $pattern); } + return $this->setParam("include", array( "pattern" => $pattern, - "flags" => $flags + "flags" => $flags, )); } /** * Filter documents to exclude based on a regular expression - * @param string $pattern a regular expression - * @param string $flags Java Pattern flags + * @param string $pattern a regular expression + * @param string $flags Java Pattern flags * @return Terms */ public function setExclude($pattern, $flags = null) @@ -58,15 +59,16 @@ public function setExclude($pattern, $flags = null) if (is_null($flags)) { return $this->setParam("exclude", $pattern); } + return $this->setParam("exclude", array( "pattern" => $pattern, - "flags" => $flags + "flags" => $flags, )); } /** * Sets the amount of terms to be returned. - * @param int $size The amount of terms to be returned. + * @param int $size The amount of terms to be returned. * @return \Elastica\Aggregation\Terms */ public function setSize($size) @@ -76,7 +78,7 @@ public function setSize($size) /** * Sets how many terms the coordinating node will request from each shard. - * @param int $shard_size The amount of terms to be returned. + * @param int $shard_size The amount of terms to be returned. * @return \Elastica\Aggregation\Terms */ public function setShardSize($shard_size) @@ -87,11 +89,11 @@ public function setShardSize($shard_size) /** * Instruct Elasticsearch to use direct field data or ordinals of the field values to execute this aggregation. * The execution hint will be ignored if it is not applicable. - * @param string $hint map or ordinals + * @param string $hint map or ordinals * @return Terms */ public function setExecutionHint($hint) { return $this->setParam("execution_hint", $hint); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Aggregation/ValueCount.php b/lib/Elastica/Aggregation/ValueCount.php index 36fb2a2c6b..977896db31 100644 --- a/lib/Elastica/Aggregation/ValueCount.php +++ b/lib/Elastica/Aggregation/ValueCount.php @@ -10,7 +10,7 @@ class ValueCount extends AbstractAggregation { /** - * @param string $name the name of this aggregation + * @param string $name the name of this aggregation * @param string $field the field on which to perform this aggregation */ public function __construct($name, $field) @@ -21,11 +21,11 @@ public function __construct($name, $field) /** * Set the field for this aggregation - * @param string $field the name of the document field on which to perform this aggregation + * @param string $field the name of the document field on which to perform this aggregation * @return ValueCount */ public function setField($field) { return $this->setParam('field', $field); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Bulk.php b/lib/Elastica/Bulk.php index 439fa56654..d2c527ea4b 100644 --- a/lib/Elastica/Bulk.php +++ b/lib/Elastica/Bulk.php @@ -2,15 +2,9 @@ namespace Elastica; -use Elastica\Document; use Elastica\Exception\Bulk\ResponseException as BulkResponseException; use Elastica\Exception\Bulk\UdpException; use Elastica\Exception\InvalidException; -use Elastica\Request; -use Elastica\Response; -use Elastica\Client; -use Elastica\Index; -use Elastica\Type; use Elastica\Bulk\Action; use Elastica\Bulk\Action\AbstractDocument as AbstractDocumentAction; use Elastica\Bulk\ResponseSet; @@ -57,7 +51,7 @@ public function __construct(Client $client) } /** - * @param string|\Elastica\Index $index + * @param string|\Elastica\Index $index * @return \Elastica\Bulk */ public function setIndex($index) @@ -88,7 +82,7 @@ public function hasIndex() } /** - * @param string|\Elastica\Type $type + * @param string|\Elastica\Type $type * @return \Elastica\Bulk */ public function setType($type) @@ -126,27 +120,29 @@ public function getPath() { $path = ''; if ($this->hasIndex()) { - $path .= $this->getIndex() . '/'; + $path .= $this->getIndex().'/'; if ($this->hasType()) { - $path .= $this->getType() . '/'; + $path .= $this->getType().'/'; } } $path .= '_bulk'; + return $path; } /** - * @param \Elastica\Bulk\Action $action + * @param \Elastica\Bulk\Action $action * @return \Elastica\Bulk */ public function addAction(Action $action) { $this->_actions[] = $action; + return $this; } /** - * @param \Elastica\Bulk\Action[] $actions + * @param \Elastica\Bulk\Action[] $actions * @return \Elastica\Bulk */ public function addActions(array $actions) @@ -167,8 +163,8 @@ public function getActions() } /** - * @param \Elastica\Document $document - * @param string $opType + * @param \Elastica\Document $document + * @param string $opType * @return \Elastica\Bulk */ public function addDocument(Document $document, $opType = null) @@ -179,8 +175,8 @@ public function addDocument(Document $document, $opType = null) } /** - * @param \Elastica\Document[] $documents - * @param string $opType + * @param \Elastica\Document[] $documents + * @param string $opType * @return \Elastica\Bulk */ public function addDocuments(array $documents, $opType = null) @@ -193,8 +189,8 @@ public function addDocuments(array $documents, $opType = null) } /** - * @param \Elastica\Script $data - * @param string $opType + * @param \Elastica\Script $data + * @param string $opType * @return \Elastica\Bulk */ public function addScript(Script $script, $opType = null) @@ -205,8 +201,8 @@ public function addScript(Script $script, $opType = null) } /** - * @param \Elastica\Document[] $scripts - * @param string $opType + * @param \Elastica\Document[] $scripts + * @param string $opType * @return \Elastica\Bulk */ public function addScripts(array $scripts, $opType = null) @@ -219,23 +215,22 @@ public function addScripts(array $scripts, $opType = null) } /** - * @param \Elastica\Script|\Elastica\Document\array $data - * @param string $opType + * @param \Elastica\Script|\Elastica\Document\array $data + * @param string $opType * @return \Elastica\Bulk */ public function addData($data, $opType = null) { - if(!is_array($data)){ + if (!is_array($data)) { $data = array($data); } - foreach ($data as $actionData){ - - if ($actionData instanceOf Script) { + foreach ($data as $actionData) { + if ($actionData instanceof Script) { $this->addScript($actionData, $opType); - }else if ($actionData instanceof Document) { + } elseif ($actionData instanceof Document) { $this->addDocument($actionData, $opType); - }else{ + } else { throw new \InvalidArgumentException("Data should be a Document, a Script or an array containing Documents and/or Scripts"); } } @@ -244,7 +239,7 @@ public function addData($data, $opType = null) } /** - * @param array $data + * @param array $data * @return \Elastica\Bulk * @throws \Elastica\Exception\InvalidException */ @@ -285,7 +280,8 @@ public function addRawData(array $data) * @var string $name name of the parameter * @var string $value value of the parameter */ - public function setRequestParam($name, $value) { + public function setRequestParam($name, $value) + { $this->_requestParams[ $name ] = $value; } @@ -294,8 +290,9 @@ public function setRequestParam($name, $value) { * Requires Elasticsearch version >= 0.90.8. * @var string $time timeout in Elasticsearch time format */ - public function setShardTimeout($time) { - $this->setRequestParam( 'timeout', $time ); + public function setShardTimeout($time) + { + $this->setRequestParam('timeout', $time); } /** @@ -313,8 +310,9 @@ public function toString() { $data = ''; foreach ($this->getActions() as $action) { - $data.= $action->toString(); + $data .= $action->toString(); } + return $data; } @@ -329,6 +327,7 @@ public function toArray() $data[] = $row; } } + return $data; } @@ -346,7 +345,7 @@ public function send() } /** - * @param \Elastica\Response $response + * @param \Elastica\Response $response * @throws Exception\Bulk\ResponseException * @throws Exception\InvalidException * @return \Elastica\Bulk\ResponseSet @@ -361,9 +360,8 @@ protected function _processResponse(Response $response) if (isset($responseData['items']) && is_array($responseData['items'])) { foreach ($responseData['items'] as $key => $item) { - if (!isset($actions[$key])) { - throw new InvalidException('No response found for action #' . $key); + throw new InvalidException('No response found for action #'.$key); } $action = $actions[$key]; @@ -399,8 +397,8 @@ protected function _processResponse(Response $response) } /** - * @param string $host - * @param int $port + * @param string $host + * @param int $port * @throws \Elastica\Exception\Bulk\UdpException */ public function sendUdp($host = null, $port = null) diff --git a/lib/Elastica/Bulk/Action.php b/lib/Elastica/Bulk/Action.php index 7922ec1319..bf79a5d5fa 100644 --- a/lib/Elastica/Bulk/Action.php +++ b/lib/Elastica/Bulk/Action.php @@ -21,7 +21,7 @@ class Action self::OP_TYPE_CREATE, self::OP_TYPE_INDEX, self::OP_TYPE_DELETE, - self::OP_TYPE_UPDATE + self::OP_TYPE_UPDATE, ); /** @@ -41,8 +41,8 @@ class Action /** * @param string $opType - * @param array $metadata - * @param array $source + * @param array $metadata + * @param array $source */ public function __construct($opType = self::OP_TYPE_INDEX, array $metadata = array(), array $source = array()) { @@ -52,7 +52,7 @@ public function __construct($opType = self::OP_TYPE_INDEX, array $metadata = arr } /** - * @param string $type + * @param string $type * @return \Elastica\Bulk\Action */ public function setOpType($type) @@ -71,7 +71,7 @@ public function getOpType() } /** - * @param array $metadata + * @param array $metadata * @return \Elastica\Bulk\Action */ public function setMetadata(array $metadata) @@ -98,7 +98,7 @@ public function getActionMetadata() } /** - * @param array $source + * @param array $source * @return \Elastica\Bulk\Action */ public function setSource($source) @@ -125,7 +125,7 @@ public function hasSource() } /** - * @param string|\Elastica\Index $index + * @param string|\Elastica\Index $index * @return \Elastica\Bulk\Action */ public function setIndex($index) @@ -139,7 +139,7 @@ public function setIndex($index) } /** - * @param string|\Elastica\Type $type + * @param string|\Elastica\Type $type * @return \Elastica\Bulk\Action */ public function setType($type) @@ -154,7 +154,7 @@ public function setType($type) } /** - * @param string $id + * @param string $id * @return \Elastica\Bulk\Action */ public function setId($id) @@ -165,7 +165,7 @@ public function setId($id) } /** - * @param string $routing + * @param string $routing * @return \Elastica\Bulk\Action */ public function setRouting($routing) @@ -184,6 +184,7 @@ public function toArray() if ($this->hasSource()) { $data[] = $this->getSource(); } + return $data; } @@ -192,24 +193,25 @@ public function toArray() */ public function toString() { - $string = JSON::stringify($this->getActionMetadata(), JSON_FORCE_OBJECT) . Bulk::DELIMITER; + $string = JSON::stringify($this->getActionMetadata(), JSON_FORCE_OBJECT).Bulk::DELIMITER; if ($this->hasSource()) { $source = $this->getSource(); if (is_string($source)) { - $string.= $source; + $string .= $source; } elseif (is_array($source) && array_key_exists('doc', $source) && is_string($source['doc'])) { $docAsUpsert = (isset($source['doc_as_upsert'])) ? ', "doc_as_upsert": '.$source['doc_as_upsert'] : ''; - $string.= '{"doc": '.$source['doc'].$docAsUpsert.'}'; + $string .= '{"doc": '.$source['doc'].$docAsUpsert.'}'; } else { - $string.= JSON::stringify($source, 'JSON_ELASTICSEARCH'); + $string .= JSON::stringify($source, 'JSON_ELASTICSEARCH'); } - $string.= Bulk::DELIMITER; + $string .= Bulk::DELIMITER; } + return $string; } /** - * @param string $opType + * @param string $opType * @return bool */ public static function isValidOpType($opType) diff --git a/lib/Elastica/Bulk/Action/AbstractDocument.php b/lib/Elastica/Bulk/Action/AbstractDocument.php index 545e695c5a..8947632a9b 100644 --- a/lib/Elastica/Bulk/Action/AbstractDocument.php +++ b/lib/Elastica/Bulk/Action/AbstractDocument.php @@ -23,7 +23,7 @@ public function __construct($document) } /** - * @param \Elastica\Document $document + * @param \Elastica\Document $document * @return \Elastica\Bulk\Action\AbstractDocument */ public function setDocument(Document $document) @@ -38,7 +38,7 @@ public function setDocument(Document $document) } /** - * @param \Elastica\Script $script + * @param \Elastica\Script $script * @return \Elastica\Bulk\Action\AbstractDocument */ public function setScript(Script $script) @@ -56,21 +56,17 @@ public function setScript(Script $script) } /** - * @param \Elastica\Script|\Elastica\Document $data + * @param \Elastica\Script|\Elastica\Document $data * @throws \InvalidArgumentException * @return \Elastica\Bulk\Action\AbstractDocument */ public function setData($data) { if ($data instanceof Script) { - $this->setScript($data); - - }else if ($data instanceof Document) { - + } elseif ($data instanceof Document) { $this->setDocument($data); - - }else{ + } else { throw new \InvalidArgumentException("Data should be a Document or a Script."); } @@ -87,7 +83,7 @@ public function getDocument() return $this->_data; } - return null; + return; } /** @@ -100,7 +96,7 @@ public function getScript() return $this->_data; } - return null; + return; } /** @@ -112,23 +108,23 @@ public function getData() } /** - * @param \Elastica\AbstractUpdateAction $source + * @param \Elastica\AbstractUpdateAction $source * @return array */ abstract protected function _getMetadata(AbstractUpdateAction $source); /** - * @param \Elastica\Document|\Elastica\Script $data - * @param string $opType + * @param \Elastica\Document|\Elastica\Script $data + * @param string $opType * @return \Elastica\Bulk\Action\AbstractDocument */ public static function create($data, $opType = null) { - //Check type - if (!($data instanceof Document) && !($data instanceof Script)) { - throw new \InvalidArgumentException("The data needs to be a Document or a Script."); - } - + //Check type + if (!($data instanceof Document) && !($data instanceof Script)) { + throw new \InvalidArgumentException("The data needs to be a Document or a Script."); + } + if (null === $opType && $data->hasOpType()) { $opType = $data->getOpType(); } @@ -137,7 +133,7 @@ public static function create($data, $opType = null) if ($data instanceof Script) { if ($opType === null) { $opType = self::OP_TYPE_UPDATE; - } else if ($opType != self::OP_TYPE_UPDATE) { + } elseif ($opType != self::OP_TYPE_UPDATE) { throw new \InvalidArgumentException("Scripts can only be used with the update operation type."); } } @@ -157,6 +153,7 @@ public static function create($data, $opType = null) $action = new IndexDocument($data); break; } + return $action; } } diff --git a/lib/Elastica/Bulk/Action/DeleteDocument.php b/lib/Elastica/Bulk/Action/DeleteDocument.php index 572f80b667..2c70a09f10 100644 --- a/lib/Elastica/Bulk/Action/DeleteDocument.php +++ b/lib/Elastica/Bulk/Action/DeleteDocument.php @@ -12,7 +12,7 @@ class DeleteDocument extends AbstractDocument protected $_opType = self::OP_TYPE_DELETE; /** - * @param \Elastica\AbstractUpdateAction $action + * @param \Elastica\AbstractUpdateAction $action * @return array */ protected function _getMetadata(AbstractUpdateAction $action) @@ -24,7 +24,7 @@ protected function _getMetadata(AbstractUpdateAction $action) 'version', 'version_type', 'routing', - 'parent' + 'parent', ); $metadata = $action->getOptions($params, true); diff --git a/lib/Elastica/Bulk/Action/IndexDocument.php b/lib/Elastica/Bulk/Action/IndexDocument.php index d405563ebd..dc1763189c 100644 --- a/lib/Elastica/Bulk/Action/IndexDocument.php +++ b/lib/Elastica/Bulk/Action/IndexDocument.php @@ -14,7 +14,7 @@ class IndexDocument extends AbstractDocument protected $_opType = self::OP_TYPE_INDEX; /** - * @param \Elastica\Document $document + * @param \Elastica\Document $document * @return \Elastica\Bulk\Action\IndexDocument */ public function setDocument(Document $document) @@ -27,7 +27,7 @@ public function setDocument(Document $document) } /** - * @param \Elastica\AbstractUpdateAction $source + * @param \Elastica\AbstractUpdateAction $source * @return array */ protected function _getMetadata(AbstractUpdateAction $action) diff --git a/lib/Elastica/Bulk/Action/UpdateDocument.php b/lib/Elastica/Bulk/Action/UpdateDocument.php index 4c1dbaa449..f9ea341eb0 100644 --- a/lib/Elastica/Bulk/Action/UpdateDocument.php +++ b/lib/Elastica/Bulk/Action/UpdateDocument.php @@ -18,7 +18,7 @@ class UpdateDocument extends IndexDocument /** * Set the document for this bulk update action. - * @param \Elastica\Document $document + * @param \Elastica\Document $document * @return \Elastica\Bulk\Action\UpdateDocument */ public function setDocument(Document $document) @@ -28,10 +28,8 @@ public function setDocument(Document $document) $source = array('doc' => $document->getData()); if ($document->getDocAsUpsert()) { - $source['doc_as_upsert'] = true; - - }else if ($document->hasUpsert()) { - + $source['doc_as_upsert'] = true; + } elseif ($document->hasUpsert()) { $upsert = $document->getUpsert()->getData(); if (!empty($upsert)) { @@ -45,7 +43,7 @@ public function setDocument(Document $document) } /** - * @param \Elastica\Script $script + * @param \Elastica\Script $script * @return \Elastica\Bulk\Action\AbstractDocument */ public function setScript(Script $script) diff --git a/lib/Elastica/Bulk/Response.php b/lib/Elastica/Bulk/Response.php index 5abd1850c5..73afb68f50 100644 --- a/lib/Elastica/Bulk/Response.php +++ b/lib/Elastica/Bulk/Response.php @@ -17,9 +17,9 @@ class Response extends BaseResponse protected $_opType; /** - * @param array|string $responseData + * @param array|string $responseData * @param \Elastica\Bulk\Action $action - * @param string $opType + * @param string $opType */ public function __construct($responseData, Action $action, $opType) { diff --git a/lib/Elastica/Bulk/ResponseSet.php b/lib/Elastica/Bulk/ResponseSet.php index 9fd835e44a..0eefb1f524 100644 --- a/lib/Elastica/Bulk/ResponseSet.php +++ b/lib/Elastica/Bulk/ResponseSet.php @@ -17,7 +17,7 @@ class ResponseSet extends BaseResponse implements \Iterator, \Countable protected $_position = 0; /** - * @param \Elastica\Response $response + * @param \Elastica\Response $response * @param \Elastica\Bulk\Response[] $bulkResponses */ public function __construct(BaseResponse $response, array $bulkResponses) diff --git a/lib/Elastica/Client.php b/lib/Elastica/Client.php index 20ba8632fe..a1b4483c2d 100644 --- a/lib/Elastica/Client.php +++ b/lib/Elastica/Client.php @@ -2,7 +2,6 @@ namespace Elastica; -use Elastica\Bulk; use Elastica\Bulk\Action; use Elastica\Exception\ConnectionException; use Elastica\Exception\InvalidException; @@ -85,7 +84,7 @@ public function __construct(array $config = array(), $callback = null) protected function _initConnections() { $connections = array(); - + foreach ($this->getConfig('connections') as $connection) { $connections[] = Connection::create($this->_prepareConnectionParams($connection)); } @@ -100,7 +99,7 @@ protected function _initConnections() if (empty($connections)) { $connections[] = Connection::create($this->_prepareConnectionParams($this->getConfig())); } - + if (!isset($this->_config['connectionStrategy'])) { if ($this->getConfig('roundRobin') === true) { $this->setConfigValue('connectionStrategy', 'RoundRobin'); @@ -108,16 +107,16 @@ protected function _initConnections() $this->setConfigValue('connectionStrategy', 'Simple'); } } - + $strategy = Connection\Strategy\StrategyFactory::create($this->getConfig('connectionStrategy')); - + $this->_connectionPool = new Connection\ConnectionPool($connections, $strategy, $this->_callback); } /** * Creates a Connection params array from a Client or server config array. * - * @param array $config + * @param array $config * @return array */ protected function _prepareConnectionParams(array $config) @@ -138,7 +137,7 @@ protected function _prepareConnectionParams(array $config) /** * Sets specific config values (updates and keeps default values) * - * @param array $config Params + * @param array $config Params * @return \Elastica\Client */ public function setConfig(array $config) @@ -154,9 +153,9 @@ public function setConfig(array $config) * Returns a specific config key or the whole * config array if not set * - * @param string $key Config key + * @param string $key Config key * @throws \Elastica\Exception\InvalidException - * @return array|string Config value + * @return array|string Config value */ public function getConfig($key = '') { @@ -165,7 +164,7 @@ public function getConfig($key = '') } if (!array_key_exists($key, $this->_config)) { - throw new InvalidException('Config key is not set: ' . $key); + throw new InvalidException('Config key is not set: '.$key); } return $this->_config[$key]; @@ -174,8 +173,8 @@ public function getConfig($key = '') /** * Sets / overwrites a specific config value * - * @param string $key Key to set - * @param mixed $value Value + * @param string $key Key to set + * @param mixed $value Value * @return \Elastica\Client Client object */ public function setConfigValue($key, $value) @@ -184,8 +183,8 @@ public function setConfigValue($key, $value) } /** - * @param array|string $keys config key or path of config keys - * @param mixed $default default value will be returned if key was not found + * @param array|string $keys config key or path of config keys + * @param mixed $default default value will be returned if key was not found * @return mixed */ public function getConfigValue($keys, $default = null) @@ -198,13 +197,14 @@ public function getConfigValue($keys, $default = null) return $default; } } + return $value; } /** * Returns the index for the given connection * - * @param string $name Index name to create connection to + * @param string $name Index name to create connection to * @return \Elastica\Index Index for the given name */ public function getIndex($name) @@ -215,8 +215,8 @@ public function getIndex($name) /** * Adds a HTTP Header * - * @param string $header The HTTP Header - * @param string $headerValue The HTTP Header Value + * @param string $header The HTTP Header + * @param string $headerValue The HTTP Header Value * @throws \Elastica\Exception\InvalidException If $header or $headerValue is not a string */ public function addHeader($header, $headerValue) @@ -231,7 +231,7 @@ public function addHeader($header, $headerValue) /** * Remove a HTTP Header * - * @param string $header The HTTP Header to remove + * @param string $header The HTTP Header to remove * @throws \Elastica\Exception\InvalidException IF $header is not a string */ public function removeHeader($header) @@ -253,11 +253,12 @@ public function removeHeader($header) * documents can belong to any type and index * * @param array|\Elastica\Document[] $docs Array of Elastica\Document - * @return \Elastica\Bulk\ResponseSet Response object + * @return \Elastica\Bulk\ResponseSet Response object * @throws \Elastica\Exception\InvalidException If docs is empty * @link http://www.elasticsearch.org/guide/reference/api/bulk.html */ - public function updateDocuments(array $docs) { + public function updateDocuments(array $docs) + { if (empty($docs)) { throw new InvalidException('Array has to consist of at least one element'); } @@ -277,7 +278,7 @@ public function updateDocuments(array $docs) { * documents can belong to any type and index * * @param array|\Elastica\Document[] $docs Array of Elastica\Document - * @return \Elastica\Bulk\ResponseSet Response object + * @return \Elastica\Bulk\ResponseSet Response object * @throws \Elastica\Exception\InvalidException If docs is empty * @link http://www.elasticsearch.org/guide/reference/api/bulk.html */ @@ -297,23 +298,21 @@ public function addDocuments(array $docs) /** * Update document, using update script. Requires elasticsearch >= 0.19.0 * - * @param int $id document id + * @param int $id document id * @param array|\Elastica\Script|\Elastica\Document $data raw data for request body - * @param string $index index to update - * @param string $type type of index to update - * @param array $options array of query params to use for query. For possible options check es api + * @param string $index index to update + * @param string $type type of index to update + * @param array $options array of query params to use for query. For possible options check es api * @return \Elastica\Response * @link http://www.elasticsearch.org/guide/reference/api/update.html */ public function updateDocument($id, $data, $index, $type, array $options = array()) { - $path = $index . '/' . $type . '/' . $id . '/_update'; + $path = $index.'/'.$type.'/'.$id.'/_update'; if ($data instanceof Script) { $requestData = $data->toArray(); - } elseif ($data instanceof Document) { - $requestData = array('doc' => $data->getData()); if ($data->getDocAsUpsert()) { @@ -349,7 +348,6 @@ public function updateDocument($id, $data, $index, $type, array $options = array //If an upsert document exists if ($data instanceof Script || $data instanceof Document) { - if ($data->hasUpsert()) { $requestData['upsert'] = $data->getUpsert()->getData(); } @@ -381,7 +379,7 @@ public function updateDocument($id, $data, $index, $type, array $options = array /** * @param \Elastica\Response $response * @param \Elastica\Document $document - * @param string $fields Array of field names to be populated or '_source' if whole document data should be updated + * @param string $fields Array of field names to be populated or '_source' if whole document data should be updated */ protected function _populateDocumentFieldsFromResponse(Response $response, Document $document, $fields) { @@ -407,7 +405,7 @@ protected function _populateDocumentFieldsFromResponse(Response $response, Docum /** * Bulk deletes documents * - * @param array|\Elastica\Document[] $docs + * @param array|\Elastica\Document[] $docs * @return \Elastica\Bulk\ResponseSet * @throws \Elastica\Exception\InvalidException */ @@ -456,7 +454,7 @@ public function addConnection(Connection $connection) /** * Determines whether a valid connection is available for use. - * + * * @return bool */ public function hasConnection() @@ -480,9 +478,8 @@ public function getConnections() { return $this->_connectionPool->getConnections(); } - + /** - * * @return \Connection\Strategy\StrategyInterface */ public function getConnectionStrategy() @@ -504,10 +501,10 @@ public function setConnections(array $connections) /** * Deletes documents with the given ids, index, type from the index * - * @param array $ids Document ids - * @param string|\Elastica\Index $index Index name - * @param string|\Elastica\Type $type Type of documents - * @param string|false $routing Optional routing key for all ids + * @param array $ids Document ids + * @param string|\Elastica\Index $index Index name + * @param string|\Elastica\Type $type Type of documents + * @param string|false $routing Optional routing key for all ids * @throws \Elastica\Exception\InvalidException * @return \Elastica\Bulk\ResponseSet Response object * @link http://www.elasticsearch.org/guide/reference/api/bulk.html @@ -548,10 +545,10 @@ public function deleteIds(array $ids, $index, $type, $routing = false) * array('delete' => array('_index' => 'test', '_type' => 'user', '_id' => '2')) * ); * - * @param array $params Parameter array + * @param array $params Parameter array * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\InvalidException - * @return \Elastica\Bulk\ResponseSet Response object + * @return \Elastica\Bulk\ResponseSet Response object * @link http://www.elasticsearch.org/guide/reference/api/bulk.html */ public function bulk(array $params) @@ -572,12 +569,12 @@ public function bulk(array $params) * * It's possible to make any REST query directly over this method * - * @param string $path Path to call - * @param string $method Rest method to use (GET, POST, DELETE, PUT) - * @param array $data OPTIONAL Arguments as array - * @param array $query OPTIONAL Query params + * @param string $path Path to call + * @param string $method Rest method to use (GET, POST, DELETE, PUT) + * @param array $data OPTIONAL Arguments as array + * @param array $query OPTIONAL Query params * @throws Exception\ConnectionException|\Exception - * @return \Elastica\Response Response object + * @return \Elastica\Response Response object */ public function request($path, $method = Request::GET, $data = array(), array $query = array()) { @@ -593,15 +590,14 @@ public function request($path, $method = Request::GET, $data = array(), array $q $this->_lastResponse = $response; return $response; - } catch (ConnectionException $e) { $this->_connectionPool->onFail($connection, $e, $this); // In case there is no valid connection left, throw exception which caused the disabling of the connection. - if (!$this->hasConnection()) - { + if (!$this->hasConnection()) { throw $e; } + return $this->request($path, $method, $data, $query); } } @@ -609,7 +605,7 @@ public function request($path, $method = Request::GET, $data = array(), array $q /** * Optimizes all search indices * - * @param array $args OPTIONAL Optional arguments + * @param array $args OPTIONAL Optional arguments * @return \Elastica\Response Response object * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-optimize.html */ @@ -632,7 +628,7 @@ public function refreshAll() /** * logging * - * @param string|\Elastica\Request $context + * @param string|\Elastica\Request $context * @throws Exception\RuntimeException */ protected function _log($context) @@ -672,7 +668,7 @@ public function getLastResponse() /** * set Logger * - * @param LoggerInterface $logger + * @param LoggerInterface $logger * @return $this */ public function setLogger(LoggerInterface $logger) diff --git a/lib/Elastica/Cluster.php b/lib/Elastica/Cluster.php index ac5acf76f5..c2565dffe6 100644 --- a/lib/Elastica/Cluster.php +++ b/lib/Elastica/Cluster.php @@ -1,6 +1,7 @@ _client->request($path, Request::POST); } diff --git a/lib/Elastica/Cluster/Health.php b/lib/Elastica/Cluster/Health.php index 18c77cfcde..a73bf0f32b 100644 --- a/lib/Elastica/Cluster/Health.php +++ b/lib/Elastica/Cluster/Health.php @@ -1,6 +1,7 @@ set( array( 'persistent' => array( - $key => $value - ) + $key => $value, + ), ) ); } @@ -123,8 +125,8 @@ public function setPersistent($key, $value) /** * Sets transient settings * - * @param string $key - * @param string $value + * @param string $key + * @param string $value * @return \Elastica\Response */ public function setTransient($key, $value) @@ -132,8 +134,8 @@ public function setTransient($key, $value) return $this->set( array( 'transient' => array( - $key => $value - ) + $key => $value, + ), ) ); } @@ -143,8 +145,8 @@ public function setTransient($key, $value) * * Second param can be used to set it persistent * - * @param bool $readOnly - * @param bool $persistent + * @param bool $readOnly + * @param bool $persistent * @return \Elastica\Response $response */ public function setReadOnly($readOnly = true, $persistent = false) @@ -163,7 +165,7 @@ public function setReadOnly($readOnly = true, $persistent = false) /** * Set settings for cluster * - * @param array $settings Raw settings (including persistent or transient) + * @param array $settings Raw settings (including persistent or transient) * @return \Elastica\Response */ public function set(array $settings) @@ -184,8 +186,8 @@ public function getClient() /** * Sends settings request * - * @param array $data OPTIONAL Data array - * @param string $method OPTIONAL Transfer method (default = \Elastica\Request::GET) + * @param array $data OPTIONAL Data array + * @param string $method OPTIONAL Transfer method (default = \Elastica\Request::GET) * @return \Elastica\Response Response object */ public function request(array $data = array(), $method = Request::GET) diff --git a/lib/Elastica/Connection.php b/lib/Elastica/Connection.php index b9d910c992..739cea46f1 100644 --- a/lib/Elastica/Connection.php +++ b/lib/Elastica/Connection.php @@ -1,6 +1,7 @@ hasParam('port')?$this->getParam('port'):self::DEFAULT_PORT; + return $this->hasParam('port') ? $this->getParam('port') : self::DEFAULT_PORT; } /** - * @param int $port + * @param int $port * @return \Elastica\Connection */ public function setPort($port) @@ -74,11 +75,11 @@ public function setPort($port) */ public function getHost() { - return $this->hasParam('host')?$this->getParam('host'):self::DEFAULT_HOST; + return $this->hasParam('host') ? $this->getParam('host') : self::DEFAULT_HOST; } /** - * @param string $host + * @param string $host * @return \Elastica\Connection */ public function setHost($host) @@ -91,7 +92,7 @@ public function setHost($host) */ public function getProxy() { - return $this->hasParam('proxy')?$this->getParam('proxy'):null; + return $this->hasParam('proxy') ? $this->getParam('proxy') : null; } /** @@ -99,7 +100,7 @@ public function getProxy() * empty string to disable proxy and proxy string to set actual http proxy. * * @see http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTPROXY - * @param string|null $proxy + * @param string|null $proxy * @return \Elastica\Connection */ public function setProxy($proxy) @@ -112,11 +113,11 @@ public function setProxy($proxy) */ public function getTransport() { - return $this->hasParam('transport')?$this->getParam('transport'):self::DEFAULT_TRANSPORT; + return $this->hasParam('transport') ? $this->getParam('transport') : self::DEFAULT_TRANSPORT; } /** - * @param string|array $transport + * @param string|array $transport * @return \Elastica\Connection */ public function setTransport($transport) @@ -129,11 +130,11 @@ public function setTransport($transport) */ public function getPath() { - return $this->hasParam('path')?$this->getParam('path'):''; + return $this->hasParam('path') ? $this->getParam('path') : ''; } /** - * @param string $path + * @param string $path * @return \Elastica\Connection */ public function setPath($path) @@ -142,7 +143,7 @@ public function setPath($path) } /** - * @param int $timeout Timeout in seconds + * @param int $timeout Timeout in seconds * @return \Elastica\Connection */ public function setTimeout($timeout) @@ -155,13 +156,13 @@ public function setTimeout($timeout) */ public function getTimeout() { - return (int) $this->hasParam('timeout')?$this->getParam('timeout'):self::TIMEOUT; + return (int) $this->hasParam('timeout') ? $this->getParam('timeout') : self::TIMEOUT; } /** * Enables a connection * - * @param bool $enabled OPTIONAL (default = true) + * @param bool $enabled OPTIONAL (default = true) * @return \Elastica\Connection */ public function setEnabled($enabled = true) @@ -195,11 +196,11 @@ public function getTransportObject() */ public function isPersistent() { - return (bool) $this->hasParam('persistent')?$this->getParam('persistent'):true; + return (bool) $this->hasParam('persistent') ? $this->getParam('persistent') : true; } /** - * @param array $config + * @param array $config * @return \Elastica\Connection */ public function setConfig(array $config) @@ -208,8 +209,8 @@ public function setConfig(array $config) } /** - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value * @return \Elastica\Connection */ public function addConfig($key, $value) @@ -234,9 +235,9 @@ public function hasConfig($key) * Returns a specific config key or the whole * config array if not set * - * @param string $key Config key + * @param string $key Config key * @throws \Elastica\Exception\InvalidException - * @return array|string Config value + * @return array|string Config value */ public function getConfig($key = '') { @@ -246,7 +247,7 @@ public function getConfig($key = '') } if (!array_key_exists($key, $config)) { - throw new InvalidException('Config key is not set: ' . $key); + throw new InvalidException('Config key is not set: '.$key); } return $config[$key]; diff --git a/lib/Elastica/Connection/ConnectionPool.php b/lib/Elastica/Connection/ConnectionPool.php index 66b2adaa22..312a17e601 100644 --- a/lib/Elastica/Connection/ConnectionPool.php +++ b/lib/Elastica/Connection/ConnectionPool.php @@ -16,39 +16,39 @@ class ConnectionPool { /** * Connections array - * + * * @var array|\Elastica\Connection[] */ protected $_connections; - + /** * Strategy for connection - * + * * @var \Elastica\Connection\Strategy\StrategyInterface */ protected $_strategy; - + /** * Callback function called on connection fail - * + * * @var callback */ protected $_callback; - + /** - * @param array $connections + * @param array $connections * @param \Elastica\Connection\Strategy\StrategyInterface $strategy - * @param callback $callback + * @param callback $callback */ public function __construct(array $connections, StrategyInterface $strategy, $callback = null) { $this->_connections = $connections; - + $this->_strategy = $strategy; - + $this->_callback = $callback; } - + /** * @param \Elastica\Connection $connection */ @@ -56,7 +56,7 @@ public function addConnection(Connection $connection) { $this->_connections[] = $connection; } - + /** * @param array|\Elastica\Connection[] $connections */ @@ -64,7 +64,7 @@ public function setConnections(array $connections) { $this->_connections = $connections; } - + /** * @return boolean */ @@ -75,10 +75,10 @@ public function hasConnection() return true; } } - + return false; } - + /** * @return array */ @@ -86,7 +86,7 @@ public function getConnections() { return $this->_connections; } - + /** * @return \Elastica\Connection * @throws \Elastica\Exception\ClientException @@ -95,23 +95,23 @@ public function getConnection() { return $this->_strategy->getConnection($this->getConnections()); } - + /** * @param \Elastica\Connection $connection - * @param \Exception $e - * @param Client $client + * @param \Exception $e + * @param Client $client */ public function onFail(Connection $connection, Exception $e, Client $client) { $connection->setEnabled(false); - + if ($this->_callback) { call_user_func($this->_callback, $connection, $e, $client); } } - + /** - * + * * @return \Elastica\Connection\Strategy\StrategyInterface */ public function getStrategy() diff --git a/lib/Elastica/Connection/Strategy/CallbackStrategy.php b/lib/Elastica/Connection/Strategy/CallbackStrategy.php index 7ea7cf9eae..cc612be298 100644 --- a/lib/Elastica/Connection/Strategy/CallbackStrategy.php +++ b/lib/Elastica/Connection/Strategy/CallbackStrategy.php @@ -11,14 +11,13 @@ */ class CallbackStrategy implements StrategyInterface { - /** - * @var Closure + * @var Closure */ protected $_callback; - + /** - * @param Closure $callback + * @param Closure $callback * @throws \Elastica\Exception\InvalidException */ public function __construct($callback) @@ -26,19 +25,19 @@ public function __construct($callback) if (!self::isValid($callback)) { throw new InvalidException(sprintf('Callback should be a Closure, %s given!', gettype($callback))); } - + $this->_callback = $callback; } - + /** - * @param array|\Elastica\Connection[] $connections + * @param array|\Elastica\Connection[] $connections * @return \Elastica\Connection */ public function getConnection($connections) { return $this->_callback->__invoke($connections); } - + /** * @return boolean */ diff --git a/lib/Elastica/Connection/Strategy/RoundRobin.php b/lib/Elastica/Connection/Strategy/RoundRobin.php index 9cbf8c86e9..ea781efc7f 100644 --- a/lib/Elastica/Connection/Strategy/RoundRobin.php +++ b/lib/Elastica/Connection/Strategy/RoundRobin.php @@ -9,16 +9,15 @@ */ class RoundRobin extends Simple { - /** - * @param array|\Elastica\Connection[] $connections + * @param array|\Elastica\Connection[] $connections * @return \Elastica\Connection * @throws \Elastica\Exception\ClientException */ public function getConnection($connections) { shuffle($connections); - + return parent::getConnection($connections); } } diff --git a/lib/Elastica/Connection/Strategy/Simple.php b/lib/Elastica/Connection/Strategy/Simple.php index f2b182a99e..9b2f0687d3 100644 --- a/lib/Elastica/Connection/Strategy/Simple.php +++ b/lib/Elastica/Connection/Strategy/Simple.php @@ -2,7 +2,6 @@ namespace Elastica\Connection\Strategy; -use Elastica\Connection\Strategy\StrategyInterface; use Elastica\Exception\ClientException; /** @@ -12,20 +11,19 @@ */ class Simple implements StrategyInterface { - /** - * @param array|\Elastica\Connection[] $connections + * @param array|\Elastica\Connection[] $connections * @return \Elastica\Connection * @throws \Elastica\Exception\ClientException */ public function getConnection($connections) { foreach ($connections as $connection) { - if ($connection->isEnabled()) { - return $connection; - } + if ($connection->isEnabled()) { + return $connection; + } } - + throw new ClientException('No enabled connection'); } } diff --git a/lib/Elastica/Connection/Strategy/StrategyFactory.php b/lib/Elastica/Connection/Strategy/StrategyFactory.php index fbdb44e664..29248c25af 100644 --- a/lib/Elastica/Connection/Strategy/StrategyFactory.php +++ b/lib/Elastica/Connection/Strategy/StrategyFactory.php @@ -12,7 +12,7 @@ class StrategyFactory { /** - * @param mixed|Closure|String|StrategyInterface $strategyName + * @param mixed|Closure|String|StrategyInterface $strategyName * @return \Elastica\Connection\Strategy\StrategyInterface * @throws \Elastica\Exception\InvalidException */ @@ -21,21 +21,21 @@ public static function create($strategyName) $strategy = null; if ($strategyName instanceof StrategyInterface) { $strategy = $strategyName; - } else if (CallbackStrategy::isValid($strategyName)) { + } elseif (CallbackStrategy::isValid($strategyName)) { $strategy = new CallbackStrategy($strategyName); - } else if (is_string($strategyName) && class_exists($strategyName)) { + } elseif (is_string($strategyName) && class_exists($strategyName)) { $strategy = new $strategyName(); - } else if (is_string($strategyName)) { + } elseif (is_string($strategyName)) { $pathToStrategy = '\\Elastica\\Connection\\Strategy\\'.$strategyName; if (class_exists($pathToStrategy)) { $strategy = new $pathToStrategy(); } } - + if (!$strategy instanceof StrategyInterface) { throw new InvalidException('Can\'t load strategy class'); } - + return $strategy; } } diff --git a/lib/Elastica/Connection/Strategy/StrategyInterface.php b/lib/Elastica/Connection/Strategy/StrategyInterface.php index 1ece1049ca..a0a73cd644 100644 --- a/lib/Elastica/Connection/Strategy/StrategyInterface.php +++ b/lib/Elastica/Connection/Strategy/StrategyInterface.php @@ -10,7 +10,7 @@ interface StrategyInterface { /** - * @param array|\Elastica\Connection[] $connections + * @param array|\Elastica\Connection[] $connections * @return \Elastica\Connection */ public function getConnection($connections); diff --git a/lib/Elastica/Document.php b/lib/Elastica/Document.php index 3f6b88dee6..b0d47269b8 100644 --- a/lib/Elastica/Document.php +++ b/lib/Elastica/Document.php @@ -40,10 +40,10 @@ class Document extends AbstractUpdateAction /** * Creates a new document * - * @param int|string $id OPTIONAL $id Id is create if empty - * @param array|string $data OPTIONAL Data array - * @param string $type OPTIONAL Type name - * @param string $index OPTIONAL Index name + * @param int|string $id OPTIONAL $id Id is create if empty + * @param array|string $data OPTIONAL Data array + * @param string $type OPTIONAL Type name + * @param string $index OPTIONAL Index name */ public function __construct($id = '', $data = array(), $type = '', $index = '') { @@ -54,7 +54,7 @@ public function __construct($id = '', $data = array(), $type = '', $index = '') } /** - * @param string $key + * @param string $key * @return mixed */ public function __get($key) @@ -64,7 +64,7 @@ public function __get($key) /** * @param string $key - * @param mixed $value + * @param mixed $value */ public function __set($key, $value) { @@ -72,7 +72,7 @@ public function __set($key, $value) } /** - * @param string $key + * @param string $key * @return bool */ public function __isset($key) @@ -89,7 +89,7 @@ public function __unset($key) } /** - * @param string $key + * @param string $key * @return mixed * @throws \Elastica\Exception\InvalidException */ @@ -98,12 +98,13 @@ public function get($key) if (!$this->has($key)) { throw new InvalidException("Field {$key} does not exist"); } + return $this->_data[$key]; } /** - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value * @throws \Elastica\Exception\InvalidException * @return \Elastica\Document */ @@ -118,7 +119,7 @@ public function set($key, $value) } /** - * @param string $key + * @param string $key * @return bool */ public function has($key) @@ -127,7 +128,7 @@ public function has($key) } /** - * @param string $key + * @param string $key * @throws \Elastica\Exception\InvalidException * @return \Elastica\Document */ @@ -145,8 +146,8 @@ public function remove($key) * Adds the given key/value pair to the document * * @deprecated - * @param string $key Document entry key - * @param mixed $value Document entry value + * @param string $key Document entry key + * @param mixed $value Document entry value * @return \Elastica\Document */ public function add($key, $value) @@ -165,9 +166,9 @@ public function add($key, $value) * This installs the tika file analysis plugin. More infos about supported formats * can be found here: {@link http://tika.apache.org/0.7/formats.html} * - * @param string $key Key to add the file to - * @param string $filepath Path to add the file - * @param string $mimeType OPTIONAL Header mime type + * @param string $key Key to add the file to + * @param string $filepath Path to add the file + * @param string $mimeType OPTIONAL Header mime type * @return \Elastica\Document */ public function addFile($key, $filepath, $mimeType = '') @@ -175,7 +176,7 @@ public function addFile($key, $filepath, $mimeType = '') $value = base64_encode(file_get_contents($filepath)); if (!empty($mimeType)) { - $value = array('_content_type' => $mimeType, '_name' => $filepath, 'content' => $value,); + $value = array('_content_type' => $mimeType, '_name' => $filepath, 'content' => $value); } $this->set($key, $value); @@ -186,8 +187,8 @@ public function addFile($key, $filepath, $mimeType = '') /** * Add file content * - * @param string $key Document key - * @param string $content Raw file content + * @param string $key Document key + * @param string $content Raw file content * @return \Elastica\Document */ public function addFileContent($key, $content) @@ -200,15 +201,15 @@ public function addFileContent($key, $content) * * Geohashes are not yet supported * - * @param string $key Field key - * @param float $latitude Latitude value - * @param float $longitude Longitude value + * @param string $key Field key + * @param float $latitude Latitude value + * @param float $longitude Longitude value * @link http://www.elasticsearch.org/guide/reference/mapping/geo-point-type.html * @return \Elastica\Document */ public function addGeoPoint($key, $latitude, $longitude) { - $value = array('lat' => $latitude, 'lon' => $longitude,); + $value = array('lat' => $latitude, 'lon' => $longitude); $this->set($key, $value); @@ -218,7 +219,7 @@ public function addGeoPoint($key, $latitude, $longitude) /** * Overwrites the current document data with the given data * - * @param array|string $data Data array + * @param array|string $data Data array * @return \Elastica\Document */ public function setData($data) @@ -239,13 +240,13 @@ public function getData() } /** - * @param \Elastica\Script $data + * @param \Elastica\Script $data * @throws NotImplementedException * @deprecated */ public function setScript($data) { - throw new NotImplementedException("setScript() is no longer available as of 0.90.2. See http://elastica.io/migration/0.90.2/upsert.html to migrate"); + throw new NotImplementedException("setScript() is no longer available as of 0.90.2. See http://elastica.io/migration/0.90.2/upsert.html to migrate"); } /** @@ -267,7 +268,7 @@ public function hasScript() } /** - * @param bool $value + * @param bool $value * @return \Elastica\Document */ public function setDocAsUpsert($value) @@ -286,7 +287,7 @@ public function getDocAsUpsert() } /** - * @param bool $autoPopulate + * @param bool $autoPopulate * @return $this */ public function setAutoPopulate($autoPopulate = true) @@ -317,7 +318,7 @@ public function toArray() } /** - * @param array|\Elastica\Document $data + * @param array|\Elastica\Document $data * @throws \Elastica\Exception\InvalidException * @return \Elastica\Document */ diff --git a/lib/Elastica/Exception/Bulk/Response/ActionException.php b/lib/Elastica/Exception/Bulk/Response/ActionException.php index 6500e040b3..c058042a16 100644 --- a/lib/Elastica/Exception/Bulk/Response/ActionException.php +++ b/lib/Elastica/Exception/Bulk/Response/ActionException.php @@ -40,7 +40,7 @@ public function getResponse() } /** - * @param \Elastica\Bulk\Response $response + * @param \Elastica\Bulk\Response $response * @return string */ public function getErrorMessage(Response $response) @@ -51,13 +51,13 @@ public function getErrorMessage(Response $response) $path = ''; if (isset($data['_index'])) { - $path.= '/' . $data['_index']; + $path .= '/'.$data['_index']; } if (isset($data['_type'])) { - $path.= '/' . $data['_type']; + $path .= '/'.$data['_type']; } if (isset($data['_id'])) { - $path.= '/' . $data['_id']; + $path .= '/'.$data['_id']; } $message = "$opType: $path caused $error"; diff --git a/lib/Elastica/Exception/Bulk/ResponseException.php b/lib/Elastica/Exception/Bulk/ResponseException.php index 9df1b3e8fa..02ed7ae346 100644 --- a/lib/Elastica/Exception/Bulk/ResponseException.php +++ b/lib/Elastica/Exception/Bulk/ResponseException.php @@ -35,8 +35,8 @@ public function __construct(ResponseSet $responseSet) { $this->_init($responseSet); - $message = 'Error in one or more bulk request actions:' . PHP_EOL . PHP_EOL; - $message.= $this->getActionExceptionsAsString(); + $message = 'Error in one or more bulk request actions:'.PHP_EOL.PHP_EOL; + $message .= $this->getActionExceptionsAsString(); parent::__construct($message); } @@ -96,8 +96,9 @@ public function getActionExceptionsAsString() { $message = ''; foreach ($this->getActionExceptions() as $actionException) { - $message.= $actionException->getMessage() . PHP_EOL; + $message .= $actionException->getMessage().PHP_EOL; } + return $message; } } diff --git a/lib/Elastica/Exception/Connection/GuzzleException.php b/lib/Elastica/Exception/Connection/GuzzleException.php index 645c0eff3e..b4298d38b9 100644 --- a/lib/Elastica/Exception/Connection/GuzzleException.php +++ b/lib/Elastica/Exception/Connection/GuzzleException.php @@ -22,8 +22,8 @@ class GuzzleException extends ConnectionException /** * @param \GuzzleHttp\Exception\TransferException $guzzleException - * @param \Elastica\Request $request - * @param \Elastica\Response $response + * @param \Elastica\Request $request + * @param \Elastica\Response $response */ public function __construct(TransferException $guzzleException, Request $request = null, Response $response = null) { @@ -33,7 +33,7 @@ public function __construct(TransferException $guzzleException, Request $request } /** - * @param \GuzzleHttp\Exception\TransferException $guzzleException + * @param \GuzzleHttp\Exception\TransferException $guzzleException * @return string */ public function getErrorMessage(TransferException $guzzleException) diff --git a/lib/Elastica/Exception/Connection/HttpException.php b/lib/Elastica/Exception/Connection/HttpException.php index 2a36fe48d6..88e8a13653 100644 --- a/lib/Elastica/Exception/Connection/HttpException.php +++ b/lib/Elastica/Exception/Connection/HttpException.php @@ -25,7 +25,7 @@ class HttpException extends ConnectionException /** * Construct Exception * - * @param string $error Error + * @param string $error Error * @param \Elastica\Request $request * @param \Elastica\Response $response */ @@ -69,7 +69,7 @@ public function getErrorMessage($error) $error = "Operation timed out"; break; default: - $error = "Unknown error:" . $error; + $error = "Unknown error:".$error; break; } diff --git a/lib/Elastica/Exception/Connection/ThriftException.php b/lib/Elastica/Exception/Connection/ThriftException.php index 0ca331c7f3..899fa8ffe9 100644 --- a/lib/Elastica/Exception/Connection/ThriftException.php +++ b/lib/Elastica/Exception/Connection/ThriftException.php @@ -23,8 +23,8 @@ class ThriftException extends ConnectionException /** * @param \Thrift\Exception\TException $thriftException - * @param \Elastica\Request $request - * @param \Elastica\Response $response + * @param \Elastica\Request $request + * @param \Elastica\Response $response */ public function __construct(TException $thriftException, Request $request = null, Response $response = null) { @@ -34,7 +34,7 @@ public function __construct(TException $thriftException, Request $request = null } /** - * @param \Thrift\Exception\TException $thriftException + * @param \Thrift\Exception\TException $thriftException * @return string */ public function getErrorMessage(TException $thriftException) diff --git a/lib/Elastica/Exception/ConnectionException.php b/lib/Elastica/Exception/ConnectionException.php index 35d6047288..f6c76eba27 100644 --- a/lib/Elastica/Exception/ConnectionException.php +++ b/lib/Elastica/Exception/ConnectionException.php @@ -31,7 +31,7 @@ class ConnectionException extends \RuntimeException implements ExceptionInterfac /** * Construct Exception * - * @param string $message Message + * @param string $message Message * @param \Elastica\Request $request * @param \Elastica\Response $response */ diff --git a/lib/Elastica/Exception/ElasticsearchException.php b/lib/Elastica/Exception/ElasticsearchException.php index 0f7509f91a..73d5465942 100644 --- a/lib/Elastica/Exception/ElasticsearchException.php +++ b/lib/Elastica/Exception/ElasticsearchException.php @@ -11,7 +11,6 @@ */ class ElasticsearchException extends \Exception { - const REMOTE_TRANSPORT_EXCEPTION = 'RemoteTransportException'; /** @@ -31,7 +30,7 @@ class ElasticsearchException extends \Exception /** * Constructs elasticsearch exception * - * @param int $code Error code + * @param int $code Error code * @param string $error Error message from elasticsearch */ public function __construct($code, $error) @@ -64,7 +63,7 @@ protected function _parseError($error) /** * Extract exception name from error response * - * @param string $error + * @param string $error * @return null|string */ protected function _extractException($error) @@ -72,7 +71,7 @@ protected function _extractException($error) if (preg_match('/^(\w+)\[.*\]/', $error, $matches)) { return $matches[1]; } else { - return null; + return; } } @@ -95,5 +94,4 @@ public function isRemoteTransportException() { return $this->_isRemote; } - } diff --git a/lib/Elastica/Exception/PartialShardFailureException.php b/lib/Elastica/Exception/PartialShardFailureException.php index f853bf96a6..4c6a772ee3 100644 --- a/lib/Elastica/Exception/PartialShardFailureException.php +++ b/lib/Elastica/Exception/PartialShardFailureException.php @@ -15,11 +15,10 @@ */ class PartialShardFailureException extends ResponseException { - /** * Construct Exception * - * @param \Elastica\Request $request + * @param \Elastica\Request $request * @param \Elastica\Response $response */ public function __construct(Request $request, Response $response) @@ -29,5 +28,4 @@ public function __construct(Request $request, Response $response) $shardsStatistics = $response->getShardsStatistics(); $this->message = JSON::stringify($shardsStatistics['failed']); } - } diff --git a/lib/Elastica/Exception/ResponseException.php b/lib/Elastica/Exception/ResponseException.php index 63244487e8..b5b80fded0 100644 --- a/lib/Elastica/Exception/ResponseException.php +++ b/lib/Elastica/Exception/ResponseException.php @@ -31,7 +31,7 @@ class ResponseException extends \RuntimeException implements ExceptionInterface /** * Construct Exception * - * @param \Elastica\Request $request + * @param \Elastica\Request $request * @param \Elastica\Response $response */ public function __construct(Request $request, Response $response) @@ -66,7 +66,8 @@ public function getResponse() * * @return ElasticsearchException */ - public function getElasticsearchException() { + public function getElasticsearchException() + { $response = $this->getResponse(); $transfer = $response->getTransferInfo(); $code = array_key_exists('http_code', $transfer) ? $transfer['http_code'] : 0; diff --git a/lib/Elastica/Facet/AbstractFacet.php b/lib/Elastica/Facet/AbstractFacet.php index 25cee8128a..7a0bc1f4ea 100644 --- a/lib/Elastica/Facet/AbstractFacet.php +++ b/lib/Elastica/Facet/AbstractFacet.php @@ -42,7 +42,7 @@ public function __construct($name) * Sets the name of the facet. It is automatically set by * the constructor. * - * @param string $name The name of the facet. + * @param string $name The name of the facet. * @throws \Elastica\Exception\InvalidException * @return \Elastica\Facet\AbstractFacet */ @@ -82,7 +82,7 @@ public function setFilter(AbstractFilter $filter) * current search query. When not set, it defaults to the * Elasticsearch default value. * - * @param bool $global Flag to either run the facet globally. + * @param bool $global Flag to either run the facet globally. * @return \Elastica\Facet\AbstractFacet */ public function setGlobal($global = true) @@ -93,7 +93,7 @@ public function setGlobal($global = true) /** * Sets the path to the nested document * - * @param string $nestedPath Nested path + * @param string $nestedPath Nested path * @return \Elastica\Facet\AbstractFacet */ public function setNested($nestedPath) @@ -104,7 +104,7 @@ public function setNested($nestedPath) /** * Sets the scope * - * @param string $scope Scope + * @param string $scope Scope * @return \Elastica\Facet\AbstractFacet */ public function setScope($scope) @@ -128,8 +128,8 @@ public function toArray() * Sets a param for the facet. Each facet implementation needs to take * care of handling their own params. * - * @param string $key The key of the param to set. - * @param mixed $value The value of the param. + * @param string $key The key of the param to set. + * @param mixed $value The value of the param. * @return \Elastica\Facet\AbstractFacet */ protected function _setFacetParam($key, $value) diff --git a/lib/Elastica/Facet/DateHistogram.php b/lib/Elastica/Facet/DateHistogram.php index 803f54a354..205277ef2d 100644 --- a/lib/Elastica/Facet/DateHistogram.php +++ b/lib/Elastica/Facet/DateHistogram.php @@ -16,7 +16,7 @@ class DateHistogram extends Histogram /** * Set the time_zone parameter * - * @param string $tzOffset + * @param string $tzOffset * @return \Elastica\Facet\DateHistogram */ public function setTimezone($tzOffset) diff --git a/lib/Elastica/Facet/GeoCluster.php b/lib/Elastica/Facet/GeoCluster.php index a6f5e9edcf..4dad35b0b1 100644 --- a/lib/Elastica/Facet/GeoCluster.php +++ b/lib/Elastica/Facet/GeoCluster.php @@ -10,32 +10,38 @@ * @author Konstantin Nikiforov * @link https://github.com/zenobase/geocluster-facet */ -class GeoCluster extends AbstractFacet { - +class GeoCluster extends AbstractFacet +{ /** - * @param string $fieldName + * @param string $fieldName * @return $this */ - public function setField($fieldName) { + public function setField($fieldName) + { $this->setParam('field', $fieldName); + return $this; } /** - * @param double $factor + * @param double $factor * @return $this */ - public function setFactor($factor){ + public function setFactor($factor) + { $this->setParam('factor', $factor); + return $this; } /** - * @param boolean $showIds + * @param boolean $showIds * @return $this */ - public function setShowIds($showIds) { + public function setShowIds($showIds) + { $this->setParam('showIds', $showIds); + return $this; } @@ -47,8 +53,10 @@ public function setShowIds($showIds) { * @throws \Elastica\Exception\InvalidException When the right fields haven't been set. * @return array */ - public function toArray(){ - $this->_setFacetParam ('geo_cluster', $this->_params); + public function toArray() + { + $this->_setFacetParam('geo_cluster', $this->_params); + return parent::toArray(); } } diff --git a/lib/Elastica/Facet/GeoDistance.php b/lib/Elastica/Facet/GeoDistance.php index 35537986ae..8ff523fed8 100644 --- a/lib/Elastica/Facet/GeoDistance.php +++ b/lib/Elastica/Facet/GeoDistance.php @@ -22,7 +22,7 @@ class GeoDistance extends AbstractFacet * array('from' => 150) * ) * - * @param array $ranges Numerical array with range definitions. + * @param array $ranges Numerical array with range definitions. * @return \Elastica\Facet\GeoDistance */ public function setRanges(array $ranges) @@ -33,9 +33,9 @@ public function setRanges(array $ranges) /** * Set the relative GeoPoint for the facet. * - * @param string $typeField index type and field e.g foo.bar - * @param float $latitude - * @param float $longitude + * @param string $typeField index type and field e.g foo.bar + * @param float $latitude + * @param float $longitude * @return \Elastica\Facet\GeoDistance */ public function setGeoPoint($typeField, $latitude, $longitude) @@ -59,7 +59,7 @@ public function toArray() /** * Set the geo_distance in the abstract as param. */ - $this->_setFacetParam ('geo_distance', $this->_params); + $this->_setFacetParam('geo_distance', $this->_params); return parent::toArray(); } diff --git a/lib/Elastica/Facet/Histogram.php b/lib/Elastica/Facet/Histogram.php index 68be6757eb..0cef46bae9 100644 --- a/lib/Elastica/Facet/Histogram.php +++ b/lib/Elastica/Facet/Histogram.php @@ -15,7 +15,7 @@ class Histogram extends AbstractFacet /** * Sets the field for histogram * - * @param string $field The name of the field for the histogram + * @param string $field The name of the field for the histogram * @return \Elastica\Facet\Histogram */ public function setField($field) @@ -26,7 +26,7 @@ public function setField($field) /** * Set the value for interval * - * @param string $interval + * @param string $interval * @return \Elastica\Facet\Histogram */ public function setInterval($interval) @@ -37,8 +37,8 @@ public function setInterval($interval) /** * Set the fields for key_field and value_field * - * @param string $keyField Key field - * @param string $valueField Value field + * @param string $keyField Key field + * @param string $valueField Value field * @return \Elastica\Facet\Histogram */ public function setKeyValueFields($keyField, $valueField) @@ -49,8 +49,8 @@ public function setKeyValueFields($keyField, $valueField) /** * Sets the key and value for this facet by script. * - * @param string $keyScript Script to check whether it falls into the range. - * @param string $valueScript Script to use for statistical calculations. + * @param string $keyScript Script to check whether it falls into the range. + * @param string $valueScript Script to use for statistical calculations. * @return \Elastica\Facet\Histogram */ public function setKeyValueScripts($keyScript, $valueScript) @@ -62,7 +62,7 @@ public function setKeyValueScripts($keyScript, $valueScript) /** * Set the "params" essential to the a script * - * @param array $params Associative array (key/value pair) + * @param array $params Associative array (key/value pair) * @return \Elastica\Facet\Histogram */ public function setScriptParams(array $params) diff --git a/lib/Elastica/Facet/Range.php b/lib/Elastica/Facet/Range.php index 194f611a36..9d887cc677 100644 --- a/lib/Elastica/Facet/Range.php +++ b/lib/Elastica/Facet/Range.php @@ -17,7 +17,7 @@ class Range extends AbstractFacet /** * Sets the field for the range. * - * @param string $field The name of the field for range. + * @param string $field The name of the field for range. * @return \Elastica\Facet\Range */ public function setField($field) @@ -28,8 +28,8 @@ public function setField($field) /** * Sets the fields by their separate key and value fields. * - * @param string $keyField The key_field param for the range. - * @param string $valueField The key_value param for the range. + * @param string $keyField The key_field param for the range. + * @param string $valueField The key_value param for the range. * @return \Elastica\Facet\Range */ public function setKeyValueFields($keyField, $valueField) @@ -61,7 +61,7 @@ public function setKeyValueScripts($keyScript, $valueScript) * array('from' => 150) * ) * - * @param array $ranges Numerical array with range definitions. + * @param array $ranges Numerical array with range definitions. * @return \Elastica\Facet\Range */ public function setRanges(array $ranges) @@ -72,8 +72,8 @@ public function setRanges(array $ranges) /** * Adds a range to the range facet. * - * @param mixed $from The from for the range. - * @param mixed $to The to for the range. + * @param mixed $from The from for the range. + * @param mixed $to The to for the range. * @return \Elastica\Facet\Range */ public function addRange($from = null, $to = null) diff --git a/lib/Elastica/Facet/Statistical.php b/lib/Elastica/Facet/Statistical.php index 71507b8f2f..c3cfa3fbec 100644 --- a/lib/Elastica/Facet/Statistical.php +++ b/lib/Elastica/Facet/Statistical.php @@ -15,7 +15,7 @@ class Statistical extends AbstractFacet /** * Sets the field for the statistical query. * - * @param string $field The field name for the statistical query. + * @param string $field The field name for the statistical query. * @return \Elastica\Facet\Statistical */ public function setField($field) @@ -26,7 +26,7 @@ public function setField($field) /** * Sets multiple fields for the statistical query. * - * @param array $fields Numerical array with the fields for the statistical query. + * @param array $fields Numerical array with the fields for the statistical query. * @return \Elastica\Facet\Statistical */ public function setFields(array $fields) @@ -37,7 +37,7 @@ public function setFields(array $fields) /** * Sets a script to calculate statistical information * - * @param string $script The script to do calculations on the statistical values + * @param string $script The script to do calculations on the statistical values * @return \Elastica\Facet\Statistical */ public function setScript($script) diff --git a/lib/Elastica/Facet/Terms.php b/lib/Elastica/Facet/Terms.php index c1dab80077..ee84ce716b 100644 --- a/lib/Elastica/Facet/Terms.php +++ b/lib/Elastica/Facet/Terms.php @@ -27,7 +27,7 @@ class Terms extends AbstractFacet /** * Sets the field for the terms. * - * @param string $field The field name for the terms. + * @param string $field The field name for the terms. * @return \Elastica\Facet\Terms */ public function setField($field) @@ -38,7 +38,7 @@ public function setField($field) /** * Sets the script for the term. * - * @param string $script The script for the term. + * @param string $script The script for the term. * @return \Elastica\Facet\Terms */ public function setScript($script) @@ -54,7 +54,7 @@ public function setScript($script) /** * Sets multiple fields for the terms. * - * @param array $fields Numerical array with the fields for the terms. + * @param array $fields Numerical array with the fields for the terms. * @return \Elastica\Facet\Terms */ public function setFields(array $fields) @@ -66,7 +66,7 @@ public function setFields(array $fields) * Sets the flag to return all available terms. When they * don't have a hit, they have a count of zero. * - * @param bool $allTerms Flag to fetch all terms. + * @param bool $allTerms Flag to fetch all terms. * @return \Elastica\Facet\Terms */ public function setAllTerms($allTerms) @@ -78,14 +78,14 @@ public function setAllTerms($allTerms) * Sets the ordering type for this facet. Elasticsearch * internal default is count. * - * @param string $type The order type to set use for sorting of the terms. + * @param string $type The order type to set use for sorting of the terms. * @throws \Elastica\Exception\InvalidException When an invalid order type was set. * @return \Elastica\Facet\Terms */ public function setOrder($type) { if (!in_array($type, $this->_orderTypes)) { - throw new InvalidException('Invalid order type: ' . $type); + throw new InvalidException('Invalid order type: '.$type); } return $this->setParam('order', $type); @@ -94,7 +94,7 @@ public function setOrder($type) /** * Set an array with terms which are omitted in the search. * - * @param array $exclude Numerical array which includes all terms which needs to be ignored. + * @param array $exclude Numerical array which includes all terms which needs to be ignored. * @return \Elastica\Facet\Terms */ public function setExclude(array $exclude) @@ -105,7 +105,7 @@ public function setExclude(array $exclude) /** * Sets the amount of terms to be returned. * - * @param int $size The amount of terms to be returned. + * @param int $size The amount of terms to be returned. * @return \Elastica\Facet\Terms */ public function setSize($size) diff --git a/lib/Elastica/Facet/TermsStats.php b/lib/Elastica/Facet/TermsStats.php index 61c6b39e1e..16df875d3a 100644 --- a/lib/Elastica/Facet/TermsStats.php +++ b/lib/Elastica/Facet/TermsStats.php @@ -14,7 +14,6 @@ */ class TermsStats extends AbstractFacet { - /** * Holds the types of ordering which are allowed * by Elasticsearch. @@ -23,42 +22,42 @@ class TermsStats extends AbstractFacet */ protected $_orderTypes = array('term', 'reverse_term', 'count', 'reverse_count', 'total', 'reverse_total', 'min', 'reverse_min', 'max', 'reverse_max', 'mean', - 'reverse_mean'); + 'reverse_mean', ); /** * Sets the key field for the query. * - * @param string $keyField The key field name for the query. + * @param string $keyField The key field name for the query. * @return \Elastica\Facet\TermsStats */ - public function setKeyField( $keyField ) + public function setKeyField($keyField) { - return $this->setParam( 'key_field', $keyField ); + return $this->setParam('key_field', $keyField); } /** * Sets a script to calculate statistical information on a per term basis * - * @param string $valueScript The script to do calculations on the statistical values + * @param string $valueScript The script to do calculations on the statistical values * @return \Elastica\Facet\TermsStats */ - public function setValueScript( $valueScript ) + public function setValueScript($valueScript) { - return $this->setParam( 'value_script', $valueScript ); + return $this->setParam('value_script', $valueScript); } /** * Sets the ordering type for this facet. Elasticsearch * internal default is count. * - * @param string $type The order type to set use for sorting of the terms. + * @param string $type The order type to set use for sorting of the terms. * @throws \Elastica\Exception\InvalidException When an invalid order type was set. * @return \Elastica\Facet\TermsStats */ public function setOrder($type) { if (!in_array($type, $this->_orderTypes)) { - throw new InvalidException('Invalid order type: ' . $type); + throw new InvalidException('Invalid order type: '.$type); } return $this->setParam('order', $type); @@ -67,18 +66,18 @@ public function setOrder($type) /** * Sets a field to compute basic statistical results on * - * @param string $valueField The field to compute statistical values for + * @param string $valueField The field to compute statistical values for * @return \Elastica\Facet\TermsStats */ - public function setValueField( $valueField ) + public function setValueField($valueField) { - return $this->setParam( 'value_field', $valueField ); + return $this->setParam('value_field', $valueField); } /** * Sets the amount of terms to be returned. * - * @param int $size The amount of terms to be returned. + * @param int $size The amount of terms to be returned. * @return \Elastica\Facet\Terms */ public function setSize($size) @@ -95,9 +94,8 @@ public function setSize($size) */ public function toArray() { - $this->_setFacetParam( 'terms_stats', $this->_params ); + $this->_setFacetParam('terms_stats', $this->_params); return parent::toArray(); } - } diff --git a/lib/Elastica/Filter/AbstractFilter.php b/lib/Elastica/Filter/AbstractFilter.php index 665f155f52..899e0ed500 100644 --- a/lib/Elastica/Filter/AbstractFilter.php +++ b/lib/Elastica/Filter/AbstractFilter.php @@ -18,7 +18,7 @@ abstract class AbstractFilter extends Param /** * Sets the filter cache * - * @param boolean $cached Cached + * @param boolean $cached Cached * @return \Elastica\Filter\AbstractFilter */ public function setCached($cached = true) @@ -29,7 +29,7 @@ public function setCached($cached = true) /** * Sets the filter cache key * - * @param string $cacheKey Cache key + * @param string $cacheKey Cache key * @throws \Elastica\Exception\InvalidException * @return \Elastica\Filter\AbstractFilter */ @@ -47,7 +47,7 @@ public function setCacheKey($cacheKey) /** * Sets the filter name * - * @param string $name Name + * @param string $name Name * @return \Elastica\Filter\AbstractFilter */ public function setName($name) diff --git a/lib/Elastica/Filter/AbstractGeoDistance.php b/lib/Elastica/Filter/AbstractGeoDistance.php index 997ceab77b..6cb833d5d5 100644 --- a/lib/Elastica/Filter/AbstractGeoDistance.php +++ b/lib/Elastica/Filter/AbstractGeoDistance.php @@ -14,7 +14,6 @@ */ abstract class AbstractGeoDistance extends AbstractFilter { - const LOCATION_TYPE_GEOHASH = 'geohash'; const LOCATION_TYPE_LATLON = 'latlon'; @@ -59,8 +58,8 @@ abstract class AbstractGeoDistance extends AbstractFilter /** * Create GeoDistance object * - * @param string $key Key - * @param array|string $location Location as array or geohash: array('lat' => 48.86, 'lon' => 2.35) OR 'drm3btev3e86' + * @param string $key Key + * @param array|string $location Location as array or geohash: array('lat' => 48.86, 'lon' => 2.35) OR 'drm3btev3e86' * @internal param string $distance Distance */ public function __construct($key, $location) @@ -71,7 +70,7 @@ public function __construct($key, $location) } /** - * @param string $key + * @param string $key * @return \Elastica\Filter\AbstractGeoDistance current filter */ public function setKey($key) @@ -82,7 +81,7 @@ public function setKey($key) } /** - * @param array|string $location + * @param array|string $location * @return \Elastica\Filter\AbstractGeoDistance * @throws \Elastica\Exception\InvalidException */ @@ -113,7 +112,7 @@ public function setLocation($location) } /** - * @param float $latitude + * @param float $latitude * @return \Elastica\Filter\AbstractGeoDistance current filter */ public function setLatitude($latitude) @@ -125,7 +124,7 @@ public function setLatitude($latitude) } /** - * @param float $longitude + * @param float $longitude * @return \Elastica\Filter\AbstractGeoDistance current filter */ public function setLongitude($longitude) @@ -137,7 +136,7 @@ public function setLongitude($longitude) } /** - * @param string $geohash + * @param string $geohash * @return \Elastica\Filter\AbstractGeoDistance current filter */ public function setGeohash($geohash) diff --git a/lib/Elastica/Filter/AbstractMulti.php b/lib/Elastica/Filter/AbstractMulti.php index 53ef74cf26..027054c28f 100644 --- a/lib/Elastica/Filter/AbstractMulti.php +++ b/lib/Elastica/Filter/AbstractMulti.php @@ -20,7 +20,7 @@ abstract class AbstractMulti extends AbstractFilter /** * Add filter * - * @param \Elastica\Filter\AbstractFilter $filter + * @param \Elastica\Filter\AbstractFilter $filter * @return \Elastica\Filter\AbstractMulti */ public function addFilter(AbstractFilter $filter) @@ -33,7 +33,7 @@ public function addFilter(AbstractFilter $filter) /** * Set filters * - * @param array $filters + * @param array $filters * @return \Elastica\Filter\AbstractMulti */ public function setFilters(array $filters) diff --git a/lib/Elastica/Filter/Bool.php b/lib/Elastica/Filter/Bool.php index 94b1b32551..018d8ea5a3 100644 --- a/lib/Elastica/Filter/Bool.php +++ b/lib/Elastica/Filter/Bool.php @@ -39,7 +39,7 @@ class Bool extends AbstractFilter * Adds should filter * * @param array|\Elastica\Filter\AbstractFilter $args Filter data - * @return \Elastica\Filter\Bool Current object + * @return \Elastica\Filter\Bool Current object */ public function addShould($args) { @@ -50,7 +50,7 @@ public function addShould($args) * Adds must filter * * @param array|\Elastica\Filter\AbstractFilter $args Filter data - * @return \Elastica\Filter\Bool Current object + * @return \Elastica\Filter\Bool Current object */ public function addMust($args) { @@ -61,7 +61,7 @@ public function addMust($args) * Adds mustNot filter * * @param array|\Elastica\Filter\AbstractFilter $args Filter data - * @return \Elastica\Filter\Bool Current object + * @return \Elastica\Filter\Bool Current object */ public function addMustNot($args) { @@ -71,10 +71,10 @@ public function addMustNot($args) /** * Adds general filter based on type * - * @param string $type Filter type + * @param string $type Filter type * @param array|\Elastica\Filter\AbstractFilter $args Filter data * @throws \Elastica\Exception\InvalidException - * @return \Elastica\Filter\Bool Current object + * @return \Elastica\Filter\Bool Current object */ protected function _addFilter($type, $args) { @@ -82,17 +82,17 @@ protected function _addFilter($type, $args) $args = $args->toArray(); } elseif (!is_array($args)) { throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Filter'); - } else{ + } else { $parsedArgs = array(); - foreach ($args as $filter){ - if ($filter instanceof AbstractFilter){ + foreach ($args as $filter) { + if ($filter instanceof AbstractFilter) { $parsedArgs[] = $filter->toArray(); } } $args = $parsedArgs; } - $varName = '_' . $type; + $varName = '_'.$type; $this->{$varName}[] = $args; return $this; diff --git a/lib/Elastica/Filter/Exists.php b/lib/Elastica/Filter/Exists.php index 6fe43e3d4d..b34dc87cc8 100644 --- a/lib/Elastica/Filter/Exists.php +++ b/lib/Elastica/Filter/Exists.php @@ -25,7 +25,7 @@ public function __construct($field) /** * Set field * - * @param string $field + * @param string $field * @return \Elastica\Filter\Exists */ public function setField($field) diff --git a/lib/Elastica/Filter/GeoBoundingBox.php b/lib/Elastica/Filter/GeoBoundingBox.php index 1462e9afae..3f4d94f6f6 100644 --- a/lib/Elastica/Filter/GeoBoundingBox.php +++ b/lib/Elastica/Filter/GeoBoundingBox.php @@ -30,8 +30,8 @@ public function __construct($key, array $coordinates) * * @param string $key Key * @param array $coordinates Array with top left coordinate as first and bottom right coordinate as second element - * @throws \Elastica\Exception\InvalidException If $coordinates doesn't have two elements - * @return \Elastica\Filter\GeoBoundingBox Current object + * @throws \Elastica\Exception\InvalidException If $coordinates doesn't have two elements + * @return \Elastica\Filter\GeoBoundingBox Current object */ public function addCoordinates($key, array $coordinates) { @@ -41,7 +41,7 @@ public function addCoordinates($key, array $coordinates) $this->setParam($key, array( 'top_left' => $coordinates[0], - 'bottom_right' => $coordinates[1] + 'bottom_right' => $coordinates[1], )); return $this; diff --git a/lib/Elastica/Filter/GeoDistance.php b/lib/Elastica/Filter/GeoDistance.php index af28fc8ca5..00112ddb09 100644 --- a/lib/Elastica/Filter/GeoDistance.php +++ b/lib/Elastica/Filter/GeoDistance.php @@ -23,9 +23,9 @@ class GeoDistance extends AbstractGeoDistance /** * Create GeoDistance object * - * @param string $key Key - * @param array|string $location Location as array or geohash: array('lat' => 48.86, 'lon' => 2.35) OR 'drm3btev3e86' - * @param string $distance Distance + * @param string $key Key + * @param array|string $location Location as array or geohash: array('lat' => 48.86, 'lon' => 2.35) OR 'drm3btev3e86' + * @param string $distance Distance * @throws \Elastica\Exception\InvalidException */ public function __construct($key, $location, $distance) @@ -36,7 +36,7 @@ public function __construct($key, $location, $distance) } /** - * @param string $distance + * @param string $distance * @return \Elastica\Filter\GeoDistance current filter */ public function setDistance($distance) @@ -49,7 +49,7 @@ public function setDistance($distance) /** * See DISTANCE_TYPE_* constants * - * @param string $distanceType + * @param string $distanceType * @return \Elastica\Filter\GeoDistance current filter */ public function setDistanceType($distanceType) @@ -62,7 +62,7 @@ public function setDistanceType($distanceType) /** * See OPTIMIZE_BBOX_* constants * - * @param string $optimizeBbox + * @param string $optimizeBbox * @return \Elastica\Filter\GeoDistance current filter */ public function setOptimizeBbox($optimizeBbox) diff --git a/lib/Elastica/Filter/GeoDistanceRange.php b/lib/Elastica/Filter/GeoDistanceRange.php index 230e5ebf44..90e1556359 100644 --- a/lib/Elastica/Filter/GeoDistanceRange.php +++ b/lib/Elastica/Filter/GeoDistanceRange.php @@ -45,7 +45,7 @@ public function __construct($key, $location, array $ranges = array()) } /** - * @param array $ranges + * @param array $ranges * @return \Elastica\Filter\GeoDistanceRange */ public function setRanges(array $ranges) @@ -60,8 +60,8 @@ public function setRanges(array $ranges) } /** - * @param string $key - * @param mixed $value + * @param string $key + * @param mixed $value * @return \Elastica\Filter\GeoDistanceRange * @throws \Elastica\Exception\InvalidException */ @@ -80,7 +80,7 @@ public function setRange($key, $value) $value = (boolean) $value; break; default: - throw new InvalidException('Invalid range parameter given: ' . $key); + throw new InvalidException('Invalid range parameter given: '.$key); } $this->_ranges[$key] = $value; diff --git a/lib/Elastica/Filter/GeoPolygon.php b/lib/Elastica/Filter/GeoPolygon.php index fa12c035f7..ef44d7b18b 100644 --- a/lib/Elastica/Filter/GeoPolygon.php +++ b/lib/Elastica/Filter/GeoPolygon.php @@ -2,7 +2,6 @@ namespace Elastica\Filter; -use Elastica\Filter\AbstractFilter; /** * Geo polygon filter @@ -51,9 +50,9 @@ public function toArray() return array( 'geo_polygon' => array( $this->_key => array( - 'points' => $this->_points + 'points' => $this->_points, ), - ) + ), ); } } diff --git a/lib/Elastica/Filter/GeoShapePreIndexed.php b/lib/Elastica/Filter/GeoShapePreIndexed.php index 7e89f8a8ef..7acae81f59 100644 --- a/lib/Elastica/Filter/GeoShapePreIndexed.php +++ b/lib/Elastica/Filter/GeoShapePreIndexed.php @@ -75,11 +75,11 @@ public function toArray() 'id' => $this->_indexedId, 'type' => $this->_indexedType, 'index' => $this->_indexedIndex, - 'path' => $this->_indexedPath + 'path' => $this->_indexedPath, ), - 'relation' => $this->_relation - ) - ) + 'relation' => $this->_relation, + ), + ), ); } } diff --git a/lib/Elastica/Filter/GeoShapeProvided.php b/lib/Elastica/Filter/GeoShapeProvided.php index 5a88c05faa..35c9b87e43 100644 --- a/lib/Elastica/Filter/GeoShapeProvided.php +++ b/lib/Elastica/Filter/GeoShapeProvided.php @@ -64,11 +64,11 @@ public function toArray() $this->_path => array( 'shape' => array( 'type' => $this->_shapeType, - 'coordinates' => $this->_coordinates + 'coordinates' => $this->_coordinates, ), - 'relation' => $this->_relation + 'relation' => $this->_relation, ), - ) + ), ); } } diff --git a/lib/Elastica/Filter/GeohashCell.php b/lib/Elastica/Filter/GeohashCell.php index d14b25fe25..1794a0e966 100644 --- a/lib/Elastica/Filter/GeohashCell.php +++ b/lib/Elastica/Filter/GeohashCell.php @@ -2,7 +2,6 @@ namespace Elastica\Filter; - /** * Class GeohashCell * @package Elastica @@ -11,10 +10,10 @@ class GeohashCell extends AbstractGeoDistance { /** - * @param string $key The field on which to filter - * @param array|string $location Location as coordinates array or geohash string ['lat' => 40.3, 'lon' => 45.2] + * @param string $key The field on which to filter + * @param array|string $location Location as coordinates array or geohash string ['lat' => 40.3, 'lon' => 45.2] * @param $precision Integer length of geohash prefix or distance (3, or "50m") - * @param bool $neighbors If true, filters cells next to the given cell. + * @param bool $neighbors If true, filters cells next to the given cell. */ public function __construct($key, $location, $precision = -1, $neighbors = false) { @@ -25,7 +24,7 @@ public function __construct($key, $location, $precision = -1, $neighbors = false /** * Set the precision for this filter - * @param string|int $precision Integer length of geohash prefix or distance (3, or "50m") + * @param string|int $precision Integer length of geohash prefix or distance (3, or "50m") * @return \Elastica\Filter\GeohashCell */ public function setPrecision($precision) @@ -35,11 +34,11 @@ public function setPrecision($precision) /** * Set the neighbors option for this filter - * @param bool $neighbors If true, filters cells next to the given cell. + * @param bool $neighbors If true, filters cells next to the given cell. * @return \Elastica\Filter\GeohashCell */ public function setNeighbors($neighbors) { - return $this->setParam('neighbors', (bool)$neighbors); + return $this->setParam('neighbors', (bool) $neighbors); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Filter/HasChild.php b/lib/Elastica/Filter/HasChild.php index 1a90c28065..d68d52f3f0 100644 --- a/lib/Elastica/Filter/HasChild.php +++ b/lib/Elastica/Filter/HasChild.php @@ -32,7 +32,7 @@ public function __construct($query, $type = null) * Sets query object * * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query - * @return \Elastica\Filter\HasChild Current object + * @return \Elastica\Filter\HasChild Current object */ public function setQuery($query) { @@ -45,8 +45,8 @@ public function setQuery($query) /** * Sets the filter object * - * @param \Elastica\Filter\AbstractFilter $filter - * @return \Elastica\Filter\HasChild Current object + * @param \Elastica\Filter\AbstractFilter $filter + * @return \Elastica\Filter\HasChild Current object */ public function setFilter($filter) { @@ -57,7 +57,7 @@ public function setFilter($filter) * Set type of the child document * * @param string|\Elastica\Type $type Child document type - * @return \Elastica\Filter\HasParent Current object + * @return \Elastica\Filter\HasParent Current object */ public function setType($type) { diff --git a/lib/Elastica/Filter/HasParent.php b/lib/Elastica/Filter/HasParent.php index 2b6534f7a9..360b6ed9c6 100644 --- a/lib/Elastica/Filter/HasParent.php +++ b/lib/Elastica/Filter/HasParent.php @@ -31,7 +31,7 @@ public function __construct($query, $type) * Sets query object * * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query - * @return \Elastica\Filter\HasParent Current object + * @return \Elastica\Filter\HasParent Current object */ public function setQuery($query) { @@ -45,7 +45,7 @@ public function setQuery($query) * Sets filter object * * @param \Elastica\Filter\AbstractFilter $filter - * @return \Elastica\Filter\HasParent Current object + * @return \Elastica\Filter\HasParent Current object */ public function setFilter($filter) { @@ -56,7 +56,7 @@ public function setFilter($filter) * Set type of the parent document * * @param string|\Elastica\Type $type Parent document type - * @return \Elastica\Filter\HasParent Current object + * @return \Elastica\Filter\HasParent Current object */ public function setType($type) { diff --git a/lib/Elastica/Filter/Ids.php b/lib/Elastica/Filter/Ids.php index fd1d9770d5..634ecb012e 100644 --- a/lib/Elastica/Filter/Ids.php +++ b/lib/Elastica/Filter/Ids.php @@ -18,7 +18,7 @@ class Ids extends AbstractFilter * Creates filter object * * @param string|\Elastica\Type $type Type to filter on - * @param array $ids List of ids + * @param array $ids List of ids */ public function __construct($type = null, array $ids = array()) { @@ -29,7 +29,7 @@ public function __construct($type = null, array $ids = array()) /** * Adds one more filter to the and filter * - * @param string $id Adds id to filter + * @param string $id Adds id to filter * @return \Elastica\Filter\Ids Current object */ public function addId($id) @@ -40,8 +40,8 @@ public function addId($id) /** * Adds one more type to query * - * @param string|\Elastica\Type $type Type name or object - * @return \Elastica\Filter\Ids Current object + * @param string|\Elastica\Type $type Type name or object + * @return \Elastica\Filter\Ids Current object */ public function addType($type) { @@ -59,8 +59,8 @@ public function addType($type) /** * Set type * - * @param string|\Elastica\Type $type Type name or object - * @return \Elastica\Filter\Ids Current object + * @param string|\Elastica\Type $type Type name or object + * @return \Elastica\Filter\Ids Current object */ public function setType($type) { @@ -78,7 +78,7 @@ public function setType($type) /** * Sets the ids to filter * - * @param array|string $ids List of ids + * @param array|string $ids List of ids * @return \Elastica\Filter\Ids Current object */ public function setIds($ids) diff --git a/lib/Elastica/Filter/Indices.php b/lib/Elastica/Filter/Indices.php index 68ecdd4ab1..769c7137ba 100644 --- a/lib/Elastica/Filter/Indices.php +++ b/lib/Elastica/Filter/Indices.php @@ -12,8 +12,8 @@ class Indices extends AbstractFilter { /** - * @param AbstractFilter $filter filter which will be applied to docs in the specified indices - * @param mixed[] $indices + * @param AbstractFilter $filter filter which will be applied to docs in the specified indices + * @param mixed[] $indices */ public function __construct(AbstractFilter $filter, array $indices) { @@ -22,7 +22,7 @@ public function __construct(AbstractFilter $filter, array $indices) /** * Set the indices on which this filter should be applied - * @param mixed[] $indices + * @param mixed[] $indices * @return Indices */ public function setIndices(array $indices) @@ -31,12 +31,13 @@ public function setIndices(array $indices) foreach ($indices as $index) { $this->addIndex($index); } + return $this; } /** * Adds one more index on which this filter should be applied - * @param string|\Elastica\Index $index + * @param string|\Elastica\Index $index * @return Indices */ public function addIndex($index) @@ -44,12 +45,13 @@ public function addIndex($index) if ($index instanceof ElasticaIndex) { $index = $index->getName(); } + return $this->addParam('indices', (string) $index); } /** * Set the filter to be applied to docs in the specified indices - * @param AbstractFilter $filter + * @param AbstractFilter $filter * @return Indices */ public function setFilter(AbstractFilter $filter) @@ -59,11 +61,11 @@ public function setFilter(AbstractFilter $filter) /** * Set the filter to be applied to docs in indices which do not match those specified in the "indices" parameter - * @param AbstractFilter $filter + * @param AbstractFilter $filter * @return Indices */ public function setNoMatchFilter(AbstractFilter $filter) { return $this->setParam('no_match_filter', $filter->toArray()); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Filter/Limit.php b/lib/Elastica/Filter/Limit.php index e02853ae4d..cf3182449d 100644 --- a/lib/Elastica/Filter/Limit.php +++ b/lib/Elastica/Filter/Limit.php @@ -15,7 +15,7 @@ class Limit extends AbstractFilter /** * Construct limit filter * - * @param int $limit Limit + * @param int $limit Limit * @return \Elastica\Filter\Limit */ public function __construct($limit) @@ -26,7 +26,7 @@ public function __construct($limit) /** * Set the limit * - * @param int $limit Limit + * @param int $limit Limit * @return \Elastica\Filter\Limit */ public function setLimit($limit) diff --git a/lib/Elastica/Filter/Nested.php b/lib/Elastica/Filter/Nested.php index ae70189c1d..ef78e52dc3 100644 --- a/lib/Elastica/Filter/Nested.php +++ b/lib/Elastica/Filter/Nested.php @@ -17,7 +17,7 @@ class Nested extends AbstractFilter /** * Adds field to mlt filter * - * @param string $path Nested object path + * @param string $path Nested object path * @return \Elastica\Filter\Nested */ public function setPath($path) diff --git a/lib/Elastica/Filter/Prefix.php b/lib/Elastica/Filter/Prefix.php index 2caf13cb81..b0efcd51be 100644 --- a/lib/Elastica/Filter/Prefix.php +++ b/lib/Elastica/Filter/Prefix.php @@ -41,7 +41,7 @@ public function __construct($field = '', $prefix = '') /** * Sets the name of the prefix field. * - * @param string $field Field name + * @param string $field Field name * @return \Elastica\Filter\Prefix */ public function setField($field) @@ -54,7 +54,7 @@ public function setField($field) /** * Sets the prefix string. * - * @param string $prefix Prefix string + * @param string $prefix Prefix string * @return \Elastica\Filter\Prefix */ public function setPrefix($prefix) diff --git a/lib/Elastica/Filter/Query.php b/lib/Elastica/Filter/Query.php index 3f1ba2d2cb..5abf0282e6 100644 --- a/lib/Elastica/Filter/Query.php +++ b/lib/Elastica/Filter/Query.php @@ -37,7 +37,7 @@ public function __construct($query = null) * Set query * * @param array|\Elastica\Query\AbstractQuery $query - * @return \Elastica\Filter\Query Query object + * @return \Elastica\Filter\Query Query object * @throws \Elastica\Exception\InvalidException Invalid param */ public function setQuery($query) diff --git a/lib/Elastica/Filter/Range.php b/lib/Elastica/Filter/Range.php index b48b0cae66..5c08fdd7fa 100644 --- a/lib/Elastica/Filter/Range.php +++ b/lib/Elastica/Filter/Range.php @@ -35,8 +35,8 @@ public function __construct($fieldName = '', array $args = array()) /** * Ads a field with arguments to the range query * - * @param string $fieldName Field name - * @param array $args Field arguments + * @param string $fieldName Field name + * @param array $args Field arguments * @return \Elastica\Filter\Range */ public function addField($fieldName, array $args) diff --git a/lib/Elastica/Filter/Regexp.php b/lib/Elastica/Filter/Regexp.php index 33c47cfda2..bd6cddab74 100644 --- a/lib/Elastica/Filter/Regexp.php +++ b/lib/Elastica/Filter/Regexp.php @@ -29,8 +29,8 @@ class Regexp extends AbstractFilter /** * Create Regexp object * - * @param string $field Field name - * @param string $regexp Regular expression + * @param string $field Field name + * @param string $regexp Regular expression * @throws \Elastica\Exception\InvalidException */ public function __construct($field = '', $regexp = '') @@ -42,7 +42,7 @@ public function __construct($field = '', $regexp = '') /** * Sets the name of the regexp field. * - * @param string $field Field name + * @param string $field Field name * @return \Elastica\Filter\Regexp */ public function setField($field) @@ -55,7 +55,7 @@ public function setField($field) /** * Sets the regular expression query string. * - * @param string $regexp Regular expression + * @param string $regexp Regular expression * @return \Elastica\Filter\Regexp */ public function setRegexp($regexp) diff --git a/lib/Elastica/Filter/Term.php b/lib/Elastica/Filter/Term.php index b4773030e5..bfc5d8148c 100644 --- a/lib/Elastica/Filter/Term.php +++ b/lib/Elastica/Filter/Term.php @@ -25,7 +25,7 @@ public function __construct(array $term = array()) /** * Sets/overwrites key and term directly * - * @param array $term Key value pair + * @param array $term Key value pair * @return \Elastica\Filter\Term Filter object */ public function setRawTerm(array $term) @@ -36,8 +36,8 @@ public function setRawTerm(array $term) /** * Adds a term to the term query * - * @param string $key Key to query - * @param string|array $value Values(s) for the query. Boost can be set with array + * @param string $key Key to query + * @param string|array $value Values(s) for the query. Boost can be set with array * @return \Elastica\Filter\Term Filter object */ public function setTerm($key, $value) diff --git a/lib/Elastica/Filter/Terms.php b/lib/Elastica/Filter/Terms.php index 9f1e686f35..036c417cf3 100644 --- a/lib/Elastica/Filter/Terms.php +++ b/lib/Elastica/Filter/Terms.php @@ -49,8 +49,8 @@ public function __construct($key = '', array $terms = array()) /** * Sets key and terms for the filter * - * @param string $key Terms key - * @param array $terms Terms for the query. + * @param string $key Terms key + * @param array $terms Terms for the query. * @return \Elastica\Filter\Terms */ public function setTerms($key, array $terms) @@ -63,12 +63,12 @@ public function setTerms($key, array $terms) /** * Set the lookup parameters for this filter - * @param string $key terms key - * @param string|\Elastica\Type $type document type from which to fetch the terms values - * @param string $id id of the document from which to fetch the terms values - * @param string $path the field from which to fetch the values for the filter - * @param string|array|\Elastica\Index $options An array of options or the index from which to fetch the terms values. Defaults to the current index. - * @return \Elastica\Filter\Terms Filter object + * @param string $key terms key + * @param string|\Elastica\Type $type document type from which to fetch the terms values + * @param string $id id of the document from which to fetch the terms values + * @param string $path the field from which to fetch the values for the filter + * @param string|array|\Elastica\Index $options An array of options or the index from which to fetch the terms values. Defaults to the current index. + * @return \Elastica\Filter\Terms Filter object */ public function setLookup($key, $type, $id, $path, $options = array()) { @@ -79,31 +79,32 @@ public function setLookup($key, $type, $id, $path, $options = array()) $this->_terms = array( 'type' => $type, 'id' => $id, - 'path' => $path + 'path' => $path, ); - + $index = $options; - if(is_array($options)) { - if(isset($options['index'])) { + if (is_array($options)) { + if (isset($options['index'])) { $index = $options['index']; unset($options['index']); } $this->_terms = array_merge($options, $this->_terms); } - + if (!is_null($index)) { if ($index instanceof \Elastica\Index) { $index = $index->getName(); } $this->_terms['index'] = $index; } + return $this; } /** * Adds an additional term to the query * - * @param string $term Filter term + * @param string $term Filter term * @return \Elastica\Filter\Terms Filter object */ public function addTerm($term) @@ -118,7 +119,7 @@ public function addTerm($term) * * @see \Elastica\Filter\AbstractFilter::toArray() * @throws \Elastica\Exception\InvalidException - * @return array data array + * @return array data array */ public function toArray() { @@ -133,7 +134,7 @@ public function toArray() /** * Set execution mode * - * @param string $execution Options: "bool", "and", "or", "plain" or "fielddata" + * @param string $execution Options: "bool", "and", "or", "plain" or "fielddata" * @return \Elastica\Filter\Terms */ public function setExecution($execution) diff --git a/lib/Elastica/Filter/Type.php b/lib/Elastica/Filter/Type.php index 8fb58c7d85..4595e46bb3 100644 --- a/lib/Elastica/Filter/Type.php +++ b/lib/Elastica/Filter/Type.php @@ -22,7 +22,7 @@ class Type extends AbstractFilter /** * Construct Type Filter * - * @param string $typeName Type name + * @param string $typeName Type name * @return \Elastica\Filter\Type */ public function __construct($typeName = null) @@ -35,7 +35,7 @@ public function __construct($typeName = null) /** * Ads a field with arguments to the range query * - * @param string $typeName Type name + * @param string $typeName Type name * @return \Elastica\Filter\Type current object */ public function setType($typeName) @@ -54,7 +54,7 @@ public function setType($typeName) public function toArray() { return array( - 'type' => array('value' => $this->_type) + 'type' => array('value' => $this->_type), ); } } diff --git a/lib/Elastica/Index.php b/lib/Elastica/Index.php index 08ba1790c8..e410f9c2aa 100644 --- a/lib/Elastica/Index.php +++ b/lib/Elastica/Index.php @@ -38,8 +38,8 @@ class Index implements SearchableInterface * * All the communication to and from an index goes of this object * - * @param \Elastica\Client $client Client object - * @param string $name Index name + * @param \Elastica\Client $client Client object + * @param string $name Index name * @throws \Elastica\Exception\InvalidException */ public function __construct(Client $client, $name) @@ -55,7 +55,7 @@ public function __construct(Client $client, $name) /** * Returns a type object for the current index with the given name * - * @param string $type Type name + * @param string $type Type name * @return \Elastica\Type Type object */ public function getType($type) @@ -94,10 +94,10 @@ public function getMapping() $response = $this->request($path, Request::GET); $data = $response->getData(); - + // Get first entry as if index is an Alias, the name of the mapping is the real name and not alias name $mapping = array_shift($data); - + if (isset($mapping['mappings'])) { return $mapping['mappings']; } @@ -203,13 +203,13 @@ public function refresh() /** * Creates a new index with the given arguments * - * @param array $args OPTIONAL Arguments to use - * @param bool|array $options OPTIONAL - * bool=> Deletes index first if already exists (default = false). - * array => Associative array of options (option=>value) + * @param array $args OPTIONAL Arguments to use + * @param bool|array $options OPTIONAL + * bool=> Deletes index first if already exists (default = false). + * array => Associative array of options (option=>value) * @throws \Elastica\Exception\InvalidException * @throws \Elastica\Exception\ResponseException - * @return array Server response + * @return array Server response * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html */ public function create(array $args = array(), $options = null) @@ -240,7 +240,7 @@ public function create(array $args = array(), $options = null) $query = array('routing' => $value); break; default: - throw new InvalidException('Invalid option ' . $key); + throw new InvalidException('Invalid option '.$key); break; } } @@ -260,12 +260,12 @@ public function exists() $response = $this->getClient()->request($this->getName(), Request::HEAD); $info = $response->getTransferInfo(); - return (bool)($info['http_code'] == 200); + return (bool) ($info['http_code'] == 200); } /** - * @param string $query - * @param int|array $options + * @param string $query + * @param int|array $options * @return \Elastica\Search */ public function createSearch($query = '', $options = null) @@ -280,8 +280,8 @@ public function createSearch($query = '', $options = null) /** * Searches in this index * - * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object - * @param int|array $options OPTIONAL Limit or associative array of options (option=>value) + * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object + * @param int|array $options OPTIONAL Limit or associative array of options (option=>value) * @return \Elastica\ResultSet ResultSet with all results inside * @see \Elastica\SearchableInterface::search */ @@ -296,7 +296,7 @@ public function search($query = '', $options = null) * Counts results of query * * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object - * @return int number of documents matching the query + * @return int number of documents matching the query * @see \Elastica\SearchableInterface::count */ public function count($query = '') @@ -351,8 +351,8 @@ public function getClient() /** * Adds an alias to the current index * - * @param string $name Alias name - * @param bool $replace OPTIONAL If set, an existing alias will be replaced + * @param string $name Alias name + * @param bool $replace OPTIONAL If set, an existing alias will be replaced * @return \Elastica\Response Response * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html */ @@ -377,7 +377,7 @@ public function addAlias($name, $replace = false) /** * Removes an alias pointing to the current index * - * @param string $name Alias name + * @param string $name Alias name * @return \Elastica\Response Response * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-aliases.html */ @@ -412,6 +412,7 @@ public function clearCache() public function flush($refresh = false) { $path = '_flush'; + return $this->request($path, Request::POST, array(), array('refresh' => $refresh)); } @@ -419,7 +420,7 @@ public function flush($refresh = false) * Can be used to change settings during runtime. One example is to use * if for bulk updating {@link http://www.elasticsearch.org/blog/2011/03/23/update-settings.html} * - * @param array $data Data array + * @param array $data Data array * @return \Elastica\Response Response object * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings.html */ @@ -431,15 +432,15 @@ public function setSettings(array $data) /** * Makes calls to the elasticsearch server based on this index * - * @param string $path Path to call - * @param string $method Rest method to use (GET, POST, DELETE, PUT) - * @param array $data OPTIONAL Arguments as array - * @param array $query OPTIONAL Query params + * @param string $path Path to call + * @param string $method Rest method to use (GET, POST, DELETE, PUT) + * @param array $data OPTIONAL Arguments as array + * @param array $query OPTIONAL Query params * @return \Elastica\Response Response object */ public function request($path, $method, $data = array(), array $query = array()) { - $path = $this->getName() . '/' . $path; + $path = $this->getName().'/'.$path; return $this->getClient()->request($path, $method, $data, $query); } @@ -450,13 +451,14 @@ public function request($path, $method, $data = array(), array $query = array()) * Detailed arguments can be found here in the link * * @param string $text String to be analyzed - * @param array $args OPTIONAL Additional arguments - * @return array Server response + * @param array $args OPTIONAL Additional arguments + * @return array Server response * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-analyze.html */ public function analyze($text, $args = array()) { $data = $this->request('_analyze', Request::POST, $text, $args)->getData(); + return $data['tokens']; } } diff --git a/lib/Elastica/Index/Settings.php b/lib/Elastica/Index/Settings.php index 985ba4de4e..3438bc4d7e 100644 --- a/lib/Elastica/Index/Settings.php +++ b/lib/Elastica/Index/Settings.php @@ -59,7 +59,7 @@ public function __construct(BaseIndex $index) * If param is set, only specified setting is return. * 'index.' is added in front of $setting. * - * @param string $setting OPTIONAL Setting name to return + * @param string $setting OPTIONAL Setting name to return * @return array|string|null Settings data * @link http://www.elasticsearch.org/guide/reference/api/admin-indices-update-settings.html */ @@ -81,12 +81,14 @@ public function get($setting = '') if (isset($settings[$key])) { $settings = $settings[$key]; } else { - return null; + return; } } + return $settings; } - return null; + + return; } } @@ -96,12 +98,12 @@ public function get($setting = '') /** * Sets the number of replicas * - * @param int $replicas Number of replicas + * @param int $replicas Number of replicas * @return \Elastica\Response Response object */ public function setNumberOfReplicas($replicas) { - $replicas = (int)$replicas; + $replicas = (int) $replicas; $data = array('number_of_replicas' => $replicas); @@ -111,7 +113,7 @@ public function setNumberOfReplicas($replicas) /** * Sets the index to read only * - * @param bool $readOnly (default = true) + * @param bool $readOnly (default = true) * @return \Elastica\Response */ public function setReadOnly($readOnly = true) @@ -124,11 +126,11 @@ public function setReadOnly($readOnly = true) */ public function getBlocksRead() { - return (bool)$this->get('blocks.read'); + return (bool) $this->get('blocks.read'); } /** - * @param bool $state OPTIONAL (default = true) + * @param bool $state OPTIONAL (default = true) * @return \Elastica\Response */ public function setBlocksRead($state = true) @@ -143,18 +145,18 @@ public function setBlocksRead($state = true) */ public function getBlocksWrite() { - return (bool)$this->get('blocks.write'); + return (bool) $this->get('blocks.write'); } /** - * @param bool $state OPTIONAL (default = true) + * @param bool $state OPTIONAL (default = true) * @return \Elastica\Response */ public function setBlocksWrite($state = true) { $state = $state ? 1 : 0; - return $this->set(array('blocks.write' => (int)$state)); + return $this->set(array('blocks.write' => (int) $state)); } /** @@ -162,18 +164,18 @@ public function setBlocksWrite($state = true) */ public function getBlocksMetadata() { - return (bool)$this->get('blocks.metadata'); + return (bool) $this->get('blocks.metadata'); } /** - * @param bool $state OPTIONAL (default = true) + * @param bool $state OPTIONAL (default = true) * @return \Elastica\Response */ public function setBlocksMetadata($state = true) { $state = $state ? 1 : 0; - return $this->set(array('blocks.metadata' => (int)$state)); + return $this->set(array('blocks.metadata' => (int) $state)); } /** @@ -182,7 +184,7 @@ public function setBlocksMetadata($state = true) * Value can be for example 3s for 3 seconds or * 5m for 5 minutes. -1 refreshing is disabled. * - * @param int $interval Number of milliseconds + * @param int $interval Number of milliseconds * @return \Elastica\Response Response object */ public function setRefreshInterval($interval) @@ -215,14 +217,13 @@ public function getRefreshInterval() */ public function getMergePolicyType() { - return $this->get('merge.policy.type'); } /** * Sets merge policy * - * @param string $type Merge policy type + * @param string $type Merge policy type * @return \Elastica\Response Response object * @link http://www.elasticsearch.org/guide/reference/index-modules/merge.html */ @@ -240,15 +241,15 @@ public function setMergePolicyType($type) * * To have this changes made the index has to be closed and reopened * - * @param string $key Merge policy key (for ex. expunge_deletes_allowed) - * @param string $value + * @param string $key Merge policy key (for ex. expunge_deletes_allowed) + * @param string $value * @return \Elastica\Response * @link http://www.elasticsearch.org/guide/reference/index-modules/merge.html */ public function setMergePolicy($key, $value) { $this->getIndex()->close(); - $response = $this->set(array('merge.policy.' . $key => $value)); + $response = $this->set(array('merge.policy.'.$key => $value)); $this->getIndex()->open(); return $response; @@ -267,13 +268,14 @@ public function getMergePolicy($key) if (isset($settings['merge']['policy'][$key])) { return $settings['merge']['policy'][$key]; } - return null; + + return; } /** * Can be used to set/update settings * - * @param array $data Arguments + * @param array $data Arguments * @return \Elastica\Response Response object */ public function set(array $data) @@ -304,8 +306,8 @@ public function getIndex() * - index.merge.policy * - index.auto_expand_replicas * - * @param array $data OPTIONAL Data array - * @param string $method OPTIONAL Transfer method (default = \Elastica\Request::GET) + * @param array $data OPTIONAL Data array + * @param string $method OPTIONAL Transfer method (default = \Elastica\Request::GET) * @return \Elastica\Response Response object */ public function request(array $data = array(), $method = Request::GET) diff --git a/lib/Elastica/Index/Stats.php b/lib/Elastica/Index/Stats.php index 9312e2730b..6195eee0c2 100644 --- a/lib/Elastica/Index/Stats.php +++ b/lib/Elastica/Index/Stats.php @@ -1,6 +1,7 @@ getIndex()->request('_aliases', \Elastica\Request::GET)->getData(); + return array_keys($responseData[$this->getIndex()->getName()]['aliases']); } @@ -98,6 +99,7 @@ public function getAliases() public function getSettings() { $responseData = $this->getIndex()->request('_settings', \Elastica\Request::GET)->getData(); + return $responseData[$this->getIndex()->getName()]['settings']; } diff --git a/lib/Elastica/JSON.php b/lib/Elastica/JSON.php index d430a7ad3b..2cce64a42b 100644 --- a/lib/Elastica/JSON.php +++ b/lib/Elastica/JSON.php @@ -15,7 +15,7 @@ class JSON * Parse JSON string to an array * * @param string $json JSON string to parse - * @return array PHP array representation of JSON string + * @return array PHP array representation of JSON string * @link http://php.net/manual/en/function.json-decode.php * @link http://www.php.net/manual/en/function.json-last-error.php */ diff --git a/lib/Elastica/Log.php b/lib/Elastica/Log.php index b246a7b167..e3d22be16c 100644 --- a/lib/Elastica/Log.php +++ b/lib/Elastica/Log.php @@ -2,7 +2,6 @@ namespace Elastica; -use Elastica\JSON; use Psr\Log\AbstractLogger; /** @@ -41,9 +40,9 @@ public function __construct($log = '') /** * Log a message * - * @param mixed $level - * @param string $message - * @param array $context + * @param mixed $level + * @param string $message + * @param array $context * @return null|void */ public function log($level, $message, array $context = array()) @@ -52,17 +51,16 @@ public function log($level, $message, array $context = array()) $this->_lastMessage = JSON::stringify($context); if (!empty($this->_log) && is_string($this->_log)) { - error_log($this->_lastMessage . PHP_EOL, 3, $this->_log); + error_log($this->_lastMessage.PHP_EOL, 3, $this->_log); } else { error_log($this->_lastMessage); } - } /** * Enable/disable log or set log path * - * @param bool|string $log Enables log or sets log path + * @param bool|string $log Enables log or sets log path * @return \Elastica\Log */ public function setLog($log) diff --git a/lib/Elastica/Multi/ResultSet.php b/lib/Elastica/Multi/ResultSet.php index a0df5785c6..d04e39d900 100644 --- a/lib/Elastica/Multi/ResultSet.php +++ b/lib/Elastica/Multi/ResultSet.php @@ -1,6 +1,7 @@ _searches[$key] = $search; + $this->_searches[$key] = $search; } else { - $this->_searches[] = $search; + $this->_searches[] = $search; } return $this; @@ -121,7 +121,7 @@ public function getSearches() } /** - * @param string $searchType + * @param string $searchType * @return \Elastica\Multi\Search */ public function setSearchType($searchType) @@ -155,7 +155,7 @@ protected function _getData() { $data = ''; foreach ($this->getSearches() as $search) { - $data.= $this->_getSearchData($search); + $data .= $this->_getSearchData($search); } return $data; @@ -168,11 +168,11 @@ protected function _getData() protected function _getSearchData(BaseSearch $search) { $header = $this->_getSearchDataHeader($search); - $header = (empty($header)) ? new \stdClass : $header; + $header = (empty($header)) ? new \stdClass() : $header; $query = $search->getQuery(); - $data = JSON::stringify($header) . "\n"; - $data.= JSON::stringify($query->toArray()) . "\n"; + $data = JSON::stringify($header)."\n"; + $data .= JSON::stringify($query->toArray())."\n"; return $data; } diff --git a/lib/Elastica/Node.php b/lib/Elastica/Node.php index a9684ca6a7..87ba837734 100644 --- a/lib/Elastica/Node.php +++ b/lib/Elastica/Node.php @@ -1,6 +1,7 @@ getName() . '/_shutdown?delay=' . $delay; + $path = '_cluster/nodes/'.$this->getName().'/_shutdown?delay='.$delay; return $this->_client->request($path, Request::POST); } diff --git a/lib/Elastica/Node/Info.php b/lib/Elastica/Node/Info.php index 1d04e53d69..43e13587ae 100644 --- a/lib/Elastica/Node/Info.php +++ b/lib/Elastica/Node/Info.php @@ -47,7 +47,7 @@ class Info * Create new info object for node * * @param \Elastica\Node $node Node object - * @param array $params List of params to return. Can be: settings, os, process, jvm, thread_pool, network, transport, http + * @param array $params List of params to return. Can be: settings, os, process, jvm, thread_pool, network, transport, http */ public function __construct(BaseNode $node, array $params = array()) { @@ -73,7 +73,7 @@ public function get() if (isset($data[$arg])) { $data = $data[$arg]; } else { - return null; + return; } } @@ -117,26 +117,28 @@ public function getIp() */ public function getPlugins() { - if(!in_array('plugins', $this->_params)) { + if (!in_array('plugins', $this->_params)) { //Plugin data was not retrieved when refresh() was called last. Get it now. $this->_params[] = 'plugins'; $this->refresh($this->_params); } + return $this->get('plugins'); } /** * Check if the given plugin is installed on this node - * @param string $name plugin name - * @return bool true if the plugin is installed, false otherwise + * @param string $name plugin name + * @return bool true if the plugin is installed, false otherwise */ public function hasPlugin($name) { - foreach($this->getPlugins() as $plugin) { - if($plugin['name'] == $name) { + foreach ($this->getPlugins() as $plugin) { + if ($plugin['name'] == $name) { return true; } } + return false; } @@ -173,19 +175,19 @@ public function getResponse() /** * Reloads all nodes information. Has to be called if informations changed * - * @param array $params Params to return (default none). Possible options: settings, os, process, jvm, thread_pool, network, transport, http, plugin + * @param array $params Params to return (default none). Possible options: settings, os, process, jvm, thread_pool, network, transport, http, plugin * @return \Elastica\Response Response object */ public function refresh(array $params = array()) { $this->_params = $params; - $path = '_nodes/' . $this->getNode()->getName(); + $path = '_nodes/'.$this->getNode()->getName(); if (!empty($params)) { $path .= '?'; foreach ($params as $param) { - $path .= $param . '=true&'; + $path .= $param.'=true&'; } } diff --git a/lib/Elastica/Node/Stats.php b/lib/Elastica/Node/Stats.php index d918e68630..2c3416beb6 100644 --- a/lib/Elastica/Node/Stats.php +++ b/lib/Elastica/Node/Stats.php @@ -63,7 +63,7 @@ public function get() if (isset($data[$arg])) { $data = $data[$arg]; } else { - return null; + return; } } @@ -107,7 +107,7 @@ public function getResponse() */ public function refresh() { - $path = '_nodes/' . $this->getNode()->getName() . '/stats'; + $path = '_nodes/'.$this->getNode()->getName().'/stats'; $this->_response = $this->getNode()->getClient()->request($path, Request::GET); $data = $this->getResponse()->getData(); $this->_data = reset($data['nodes']); diff --git a/lib/Elastica/Param.php b/lib/Elastica/Param.php index 38a45d1482..2c14fed0f3 100644 --- a/lib/Elastica/Param.php +++ b/lib/Elastica/Param.php @@ -1,6 +1,7 @@ _params[$key])) { $this->_params[$key] = array(); } $this->_params[$key][] = $value; } else { - $this->_params = $value; + $this->_params = $value; } return $this; @@ -126,14 +127,14 @@ public function addParam($key, $value) /** * Returns a specific param * - * @param string $key Key to return - * @return mixed Key value + * @param string $key Key to return + * @return mixed Key value * @throws \Elastica\Exception\InvalidException If requested key is not set */ public function getParam($key) { if (!$this->hasParam($key)) { - throw new InvalidException('Param ' . $key . ' does not exist'); + throw new InvalidException('Param '.$key.' does not exist'); } return $this->_params[$key]; diff --git a/lib/Elastica/Percolator.php b/lib/Elastica/Percolator.php index 2ec312b9ad..61d8d25565 100644 --- a/lib/Elastica/Percolator.php +++ b/lib/Elastica/Percolator.php @@ -32,15 +32,15 @@ public function __construct(Index $index) /** * Registers a percolator query, with optional extra fields to include in the registered query. * - * @param string $name Query name - * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to add - * @param array $fields Extra fields to include in the registered query + * @param string $name Query name + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to add + * @param array $fields Extra fields to include in the registered query * and can be used to filter executed queries. * @return \Elastica\Response */ public function registerQuery($name, $query, $fields = array()) { - $path = $this->_index->getName() . '/.percolator/' . $name; + $path = $this->_index->getName().'/.percolator/'.$name; $query = Query::create($query); $data = array_merge($query->toArray(), $fields); @@ -50,12 +50,12 @@ public function registerQuery($name, $query, $fields = array()) /** * Removes a percolator query - * @param string $name query name + * @param string $name query name * @return \Elastica\Response */ public function unregisterQuery($name) { - $path = $this->_index->getName() . '/.percolator/' . $name; + $path = $this->_index->getName().'/.percolator/'.$name; return $this->_index->getClient()->request($path, Request::DELETE); } @@ -63,16 +63,16 @@ public function unregisterQuery($name) /** * Match a document to percolator queries * - * @param \Elastica\Document $doc - * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the percolator queries which - * are executed. - * @param string $type - * @param array $params - * @return array With matching registered queries. + * @param \Elastica\Document $doc + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the percolator queries which + * are executed. + * @param string $type + * @param array $params + * @return array With matching registered queries. */ public function matchDoc(Document $doc, $query = null, $type = 'type', $params = array()) { - $path = $this->_index->getName() . '/' . $type . '/_percolate'; + $path = $this->_index->getName().'/'.$type.'/_percolate'; $data = array('doc' => $doc->getData()); return $this->_percolate($path, $query, $data, $params); @@ -81,26 +81,26 @@ public function matchDoc(Document $doc, $query = null, $type = 'type', $params = /** * Percolating an existing document * - * @param string $id - * @param string $type - * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the percolator queries which - * are executed. - * @param array $params - * @return array With matching registered queries. + * @param string $id + * @param string $type + * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query Query to filter the percolator queries which + * are executed. + * @param array $params + * @return array With matching registered queries. */ public function matchExistingDoc($id, $type, $query = null, $params = array()) { $id = urlencode($id); - $path = $this->_index->getName() . '/' . $type . '/'. $id . '/_percolate'; + $path = $this->_index->getName().'/'.$type.'/'.$id.'/_percolate'; return $this->_percolate($path, $query, array(), $params); } /** - * @param string $path + * @param string $path * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $query] $query [description] - * @param array $data - * @param array $params + * @param array $data + * @param array $params * @return array */ protected function _percolate($path, $query, $data = array(), $params = array()) @@ -117,6 +117,7 @@ protected function _percolate($path, $query, $data = array(), $params = array()) if (isset($data['matches'])) { return $data['matches']; } + return array(); } diff --git a/lib/Elastica/Query.php b/lib/Elastica/Query.php index 02c586bf9d..fdd680be39 100644 --- a/lib/Elastica/Query.php +++ b/lib/Elastica/Query.php @@ -1,6 +1,7 @@ setPostFilter($filter); } /** * Sets the start from which the search results should be returned * - * @param int $from + * @param int $from * @return \Elastica\Query Query object */ public function setFrom($from) @@ -157,7 +158,7 @@ public function setFrom($from) * Sets sort arguments for the query * Replaces existing values * - * @param array $sortArgs Sorting arguments + * @param array $sortArgs Sorting arguments * @return \Elastica\Query Query object * @link http://www.elasticsearch.org/guide/reference/api/search/sort.html */ @@ -169,7 +170,7 @@ public function setSort(array $sortArgs) /** * Adds a sort param to the query * - * @param mixed $sort Sort parameter + * @param mixed $sort Sort parameter * @return \Elastica\Query Query object * @link http://www.elasticsearch.org/guide/reference/api/search/sort.html */ @@ -181,7 +182,7 @@ public function addSort($sort) /** * Sets highlight arguments for the query * - * @param array $highlightArgs Set all highlight arguments + * @param array $highlightArgs Set all highlight arguments * @return \Elastica\Query Query object * @link http://www.elasticsearch.org/guide/reference/api/search/highlighting.html */ @@ -193,7 +194,7 @@ public function setHighlight(array $highlightArgs) /** * Adds a highlight argument * - * @param mixed $highlight Add highlight argument + * @param mixed $highlight Add highlight argument * @return \Elastica\Query Query object * @link http://www.elasticsearch.org/guide/reference/api/search/highlighting.html */ @@ -205,7 +206,7 @@ public function addHighlight($highlight) /** * Sets maximum number of results for this query * - * @param int $size OPTIONAL Maximal number of results for query (default = 10) + * @param int $size OPTIONAL Maximal number of results for query (default = 10) * @return \Elastica\Query Query object */ public function setSize($size = 10) @@ -217,7 +218,7 @@ public function setSize($size = 10) * Alias for setSize * * @deprecated Use the setSize() method, this method will be removed in future releases - * @param int $limit OPTIONAL Maximal number of results for query (default = 10) + * @param int $limit OPTIONAL Maximal number of results for query (default = 10) * @return \Elastica\Query Query object */ public function setLimit($limit = 10) @@ -228,7 +229,7 @@ public function setLimit($limit = 10) /** * Enables explain on the query * - * @param bool $explain OPTIONAL Enabled or disable explain (default = true) + * @param bool $explain OPTIONAL Enabled or disable explain (default = true) * @return \Elastica\Query Current object * @link http://www.elasticsearch.org/guide/reference/api/search/explain.html */ @@ -240,7 +241,7 @@ public function setExplain($explain = true) /** * Enables version on the query * - * @param bool $version OPTIONAL Enabled or disable version (default = true) + * @param bool $version OPTIONAL Enabled or disable version (default = true) * @return \Elastica\Query Current object * @link http://www.elasticsearch.org/guide/reference/api/search/version.html */ @@ -254,7 +255,7 @@ public function setVersion($version = true) * NOTICE php will encode modified(or named keys) array into object format in json format request * so the fields array must a sequence(list) type of array * - * @param array $fields Fields to be returned + * @param array $fields Fields to be returned * @return \Elastica\Query Current object * @link http://www.elasticsearch.org/guide/reference/api/search/fields.html */ @@ -282,7 +283,7 @@ public function setScriptFields($scriptFields) /** * Adds a Script to the query * - * @param string $name + * @param string $name * @param \Elastica\Script $script Script object * @return \Elastica\Query Query object */ @@ -296,7 +297,7 @@ public function addScriptField($name, Script $script) /** * Sets all facets for this query object. Replaces existing facets * - * @param array $facets List of facet objects + * @param array $facets List of facet objects * @return \Elastica\Query Query object * @link http://www.elasticsearch.org/guide/reference/api/search/facets/ */ @@ -326,8 +327,8 @@ public function addFacet(AbstractFacet $facet) /** * Adds an Aggregation to the query * - * @param AbstractAggregation $agg - * @return \Elastica\Query Query object + * @param AbstractAggregation $agg + * @return \Elastica\Query Query object */ public function addAggregation(AbstractAggregation $agg) { @@ -335,6 +336,7 @@ public function addAggregation(AbstractAggregation $agg) $this->_params['aggs'] = array(); } $this->_params['aggs'][$agg->getName()] = $agg->toArray(); + return $this; } @@ -363,7 +365,7 @@ public function toArray() /** * Allows filtering of documents based on a minimum score * - * @param int $minScore Minimum score to filter documents by + * @param int $minScore Minimum score to filter documents by * @throws \Elastica\Exception\InvalidException * @return \Elastica\Query Query object */ @@ -379,7 +381,7 @@ public function setMinScore($minScore) /** * Add a suggest term * - * @param \Elastica\Suggest $suggest suggestion object + * @param \Elastica\Suggest $suggest suggestion object */ public function setSuggest(Suggest $suggest) { @@ -394,7 +396,7 @@ public function setSuggest(Suggest $suggest) * Add a Rescore * * @param \Elastica\Rescore\AbstractRescore $rescore suggestion object - * @return \Elastica\Query Current object + * @return \Elastica\Query Current object */ public function setRescore($rescore) { @@ -404,7 +406,7 @@ public function setRescore($rescore) /** * Sets the _source field to be returned with every hit * - * @param array $fields Fields to be returned + * @param array $fields Fields to be returned * @return \Elastica\Query Current object * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/1.x/search-request-source-filtering.html */ @@ -416,14 +418,13 @@ public function setSource(array $fields) /** * Sets post_filter argument for the query. The filter is applied after the query has executed * - * @param array|\Elastica\Filter\AbstractFilter $filter - * @return \Elastica\Query Current object + * @param array|\Elastica\Filter\AbstractFilter $filter + * @return \Elastica\Query Current object * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-post-filter.html */ public function setPostFilter($filter) { - if($filter instanceof AbstractFilter) - { + if ($filter instanceof AbstractFilter) { $filter = $filter->toArray(); } else { trigger_error('Deprecated: Elastica\Query::setPostFilter() passing filter as array is deprecated. Pass instance of AbstractFilter instead.', E_USER_DEPRECATED); diff --git a/lib/Elastica/Query/AbstractQuery.php b/lib/Elastica/Query/AbstractQuery.php index 5b24ace4cd..0ecbf50398 100644 --- a/lib/Elastica/Query/AbstractQuery.php +++ b/lib/Elastica/Query/AbstractQuery.php @@ -1,6 +1,7 @@ setParam('negative_boost', (float)$negativeBoost); + return $this->setParam('negative_boost', (float) $negativeBoost); } } diff --git a/lib/Elastica/Query/Builder.php b/lib/Elastica/Query/Builder.php index 3bb44911b8..c12a534a03 100644 --- a/lib/Elastica/Query/Builder.php +++ b/lib/Elastica/Query/Builder.php @@ -322,7 +322,7 @@ public function facetsClose() public function field($name, $value) { if (is_bool($value)) { - $value = '"'. var_export($value, true) . '"'; + $value = '"'.var_export($value, true).'"'; } elseif (is_array($value)) { $value = '["'.implode('","', $value).'"]'; } else { @@ -554,7 +554,7 @@ public function matchAll($boost = null) { $this->fieldOpen('match_all'); - if ( ! $boost == null && is_numeric($boost)) { + if (! $boost == null && is_numeric($boost)) { $this->field('boost', (float) $boost); } @@ -849,7 +849,7 @@ public function sortFields(array $fields) $this->_string .= '{"'.$fieldName.'":"'.$order.'"},'; } - $this->_string = rtrim($this->_string, ',') . '],'; + $this->_string = rtrim($this->_string, ',').'],'; return $this; } diff --git a/lib/Elastica/Query/Common.php b/lib/Elastica/Query/Common.php index 6e11276966..25f8a542e1 100644 --- a/lib/Elastica/Query/Common.php +++ b/lib/Elastica/Query/Common.php @@ -2,7 +2,6 @@ namespace Elastica\Query; - /** * Class Common * @package Elastica @@ -24,9 +23,9 @@ class Common extends AbstractQuery protected $_queryParams = array(); /** - * @param string $field the field on which to query - * @param string $query the query string - * @param float $cutoffFrequency percentage in decimal form (.001 == 0.1%) + * @param string $field the field on which to query + * @param string $query the query string + * @param float $cutoffFrequency percentage in decimal form (.001 == 0.1%) */ public function __construct($field, $query, $cutoffFrequency) { @@ -37,18 +36,19 @@ public function __construct($field, $query, $cutoffFrequency) /** * Set the field on which to query - * @param string $field the field on which to query + * @param string $field the field on which to query * @return \Elastica\Query\Common */ public function setField($field) { $this->_field = $field; + return $this; } /** * Set the query string for this query - * @param string $query + * @param string $query * @return \Elastica\Query\Common */ public function setQuery($query) @@ -58,17 +58,17 @@ public function setQuery($query) /** * Set the frequency below which terms will be put in the low frequency group - * @param float $frequency percentage in decimal form (.001 == 0.1%) + * @param float $frequency percentage in decimal form (.001 == 0.1%) * @return \Elastica\Query\Common */ public function setCutoffFrequency($frequency) { - return $this->setQueryParam('cutoff_frequency', (float)$frequency); + return $this->setQueryParam('cutoff_frequency', (float) $frequency); } /** * Set the logic operator for low frequency terms - * @param string $operator see OPERATOR_* class constants for options + * @param string $operator see OPERATOR_* class constants for options * @return \Elastica\Query\Common */ public function setLowFrequencyOperator($operator) @@ -78,7 +78,7 @@ public function setLowFrequencyOperator($operator) /** * Set the logic operator for high frequency terms - * @param string $operator see OPERATOR_* class constants for options + * @param string $operator see OPERATOR_* class constants for options * @return \Elastica\Query\Common */ public function setHighFrequencyOperator($operator) @@ -88,7 +88,7 @@ public function setHighFrequencyOperator($operator) /** * Set the minimum_should_match parameter - * @param int|string $minimum minimum number of low frequency terms which must be present + * @param int|string $minimum minimum number of low frequency terms which must be present * @return \Elastica\Query\Common * @link Possible values for minimum_should_match http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html */ @@ -99,17 +99,17 @@ public function setMinimumShouldMatch($minimum) /** * Set the boost for this query - * @param float $boost + * @param float $boost * @return \Elastica\Query\Common */ public function setBoost($boost) { - return $this->setQueryParam('boost', (float)$boost); + return $this->setQueryParam('boost', (float) $boost); } /** * Set the analyzer for this query - * @param string $analyzer + * @param string $analyzer * @return \Elastica\Query\Common */ public function setAnalyzer($analyzer) @@ -119,23 +119,24 @@ public function setAnalyzer($analyzer) /** * Enable / disable computation of score factor based on the fraction of all query terms contained in the document - * @param bool $disable disable_coord is false by default + * @param bool $disable disable_coord is false by default * @return \Elastica\Query\Common */ public function setDisableCoord($disable = true) { - return $this->setQueryParam('disable_coord', (bool)$disable); + return $this->setQueryParam('disable_coord', (bool) $disable); } /** * Set a parameter in the body of this query - * @param string $key parameter key - * @param mixed $value parameter value + * @param string $key parameter key + * @param mixed $value parameter value * @return \Elastica\Query\Common */ public function setQueryParam($key, $value) { $this->_queryParams[$key] = $value; + return $this; } @@ -145,6 +146,7 @@ public function setQueryParam($key, $value) public function toArray() { $this->setParam($this->_field, $this->_queryParams); + return parent::toArray(); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Query/ConstantScore.php b/lib/Elastica/Query/ConstantScore.php index 16854600ee..66ec0ec974 100644 --- a/lib/Elastica/Query/ConstantScore.php +++ b/lib/Elastica/Query/ConstantScore.php @@ -1,6 +1,7 @@ setQuery($query); $this->setFilter($filter); } @@ -89,7 +90,7 @@ public function toArray() if (empty($filtered)) { throw new InvalidException('A query and/or filter is required'); } - + return array('filtered' => $filtered); } } diff --git a/lib/Elastica/Query/FunctionScore.php b/lib/Elastica/Query/FunctionScore.php index 8230c86edb..643f7f560a 100644 --- a/lib/Elastica/Query/FunctionScore.php +++ b/lib/Elastica/Query/FunctionScore.php @@ -1,6 +1,7 @@ $functionParams + $functionType => $functionParams, ); if (!is_null($filter)) { $function['filter'] = $filter->toArray(); } $this->_functions[] = $function; + return $this; } /** * Add a script_score function to the query - * @param Script $script a Script object - * @param AbstractFilter $filter an optional filter to apply to the function + * @param Script $script a Script object + * @param AbstractFilter $filter an optional filter to apply to the function * @return \Elastica\Query\FunctionScore */ - public function addScriptScoreFunction(Script $script, AbstractFilter $filter = NULL) + public function addScriptScoreFunction(Script $script, AbstractFilter $filter = null) { return $this->addFunction('script_score', $script->toArray(), $filter); } /** * Add a decay function to the query - * @param string $function see DECAY_* constants for valid options - * @param string $field the document field on which to perform the decay function - * @param string $origin the origin value for this decay function - * @param string $scale a scale to define the rate of decay for this function - * @param string $offset If defined, this function will only be computed for documents with a distance from the origin greater than this value - * @param float $decay optionally defines how documents are scored at the distance given by the $scale parameter - * @param float $scaleWeight optional factor by which to multiply the score at the value provided by the $scale parameter - * @param AbstractFilter $filter a filter associated with this function + * @param string $function see DECAY_* constants for valid options + * @param string $field the document field on which to perform the decay function + * @param string $origin the origin value for this decay function + * @param string $scale a scale to define the rate of decay for this function + * @param string $offset If defined, this function will only be computed for documents with a distance from the origin greater than this value + * @param float $decay optionally defines how documents are scored at the distance given by the $scale parameter + * @param float $scaleWeight optional factor by which to multiply the score at the value provided by the $scale parameter + * @param AbstractFilter $filter a filter associated with this function * @return \Elastica\Query\FunctionScore */ - public function addDecayFunction($function, $field, $origin, $scale, $offset = NULL, $decay = NULL, $scaleWeight = NULL, - AbstractFilter $filter = NULL) + public function addDecayFunction($function, $field, $origin, $scale, $offset = null, $decay = null, $scaleWeight = null, + AbstractFilter $filter = null) { $functionParams = array( $field => array( 'origin' => $origin, - 'scale' => $scale - ) + 'scale' => $scale, + ), ); if (!is_null($offset)) { $functionParams[$field]['offset'] = $offset; } if (!is_null($decay)) { - $functionParams[$field]['decay'] = (float)$decay; + $functionParams[$field]['decay'] = (float) $decay; } if (!is_null($scaleWeight)) { - $functionParams[$field]['scale_weight'] = (float)$scaleWeight; + $functionParams[$field]['scale_weight'] = (float) $scaleWeight; } + return $this->addFunction($function, $functionParams, $filter); } /** * Add a boost_factor function to the query - * @param float $boostFactor the boost factor value - * @param AbstractFilter $filter a filter associated with this function + * @param float $boostFactor the boost factor value + * @param AbstractFilter $filter a filter associated with this function */ - public function addBoostFactorFunction($boostFactor, AbstractFilter $filter = NULL) + public function addBoostFactorFunction($boostFactor, AbstractFilter $filter = null) { $this->addFunction('boost_factor', $boostFactor, $filter); } /** * Add a random_score function to the query - * @param number $seed the seed value + * @param number $seed the seed value * @param AbstractFilter $filter a filter associated with this function - * @param float $boost an optional boost value associated with this function + * @param float $boost an optional boost value associated with this function */ - public function addRandomScoreFunction($seed, AbstractFilter $filter = NULL, $boost = NULL) + public function addRandomScoreFunction($seed, AbstractFilter $filter = null, $boost = null) { $this->addFunction('random_score', array('seed' => $seed), $filter, $boost); } /** * Set an overall boost value for this query - * @param float $boost + * @param float $boost * @return \Elastica\Query\FunctionScore */ public function setBoost($boost) { - return $this->setParam('boost', (float)$boost); + return $this->setParam('boost', (float) $boost); } /** * Restrict the combined boost of the function_score query and its child query - * @param float $maxBoost + * @param float $maxBoost * @return \Elastica\Query\FunctionScore */ public function setMaxBoost($maxBoost) { - return $this->setParam('max_boost', (float)$maxBoost); + return $this->setParam('max_boost', (float) $maxBoost); } /** * The boost mode determines how the score of this query is combined with that of the child query - * @param string $mode see BOOST_MODE_* constants for valid options. Default is multiply. + * @param string $mode see BOOST_MODE_* constants for valid options. Default is multiply. * @return \Elastica\Query\FunctionScore */ public function setBoostMode($mode) @@ -166,21 +169,22 @@ public function setBoostMode($mode) /** * If set, this query will return results in random order. - * @param int $seed Set a seed value to return results in the same random order for consistent pagination. + * @param int $seed Set a seed value to return results in the same random order for consistent pagination. * @return \Elastica\Query\FunctionScore */ - public function setRandomScore($seed = NULL) + public function setRandomScore($seed = null) { $seedParam = new \stdClass(); if (!is_null($seed)) { $seedParam->seed = $seed; } + return $this->setParam('random_score', $seedParam); } /** * Set the score method - * @param string $mode see SCORE_MODE_* constants for valid options. Default is multiply. + * @param string $mode see SCORE_MODE_* constants for valid options. Default is multiply. * @return \Elastica\Query\FunctionScore */ public function setScoreMode($mode) @@ -196,6 +200,7 @@ public function toArray() if (sizeof($this->_functions)) { $this->setParam('functions', $this->_functions); } + return parent::toArray(); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Query/Fuzzy.php b/lib/Elastica/Query/Fuzzy.php index 73b0f1a1d7..1bc1c2e3e0 100644 --- a/lib/Elastica/Query/Fuzzy.php +++ b/lib/Elastica/Query/Fuzzy.php @@ -17,11 +17,11 @@ class Fuzzy extends AbstractQuery /** * Construct a fuzzy query * - * @param string $fieldName Field name - * @param string $value String to search for + * @param string $fieldName Field name + * @param string $value String to search for * @return \Elastica\Query\Fuzzy Current object */ - public function __construct ($fieldName = null, $value = null) + public function __construct($fieldName = null, $value = null) { if ($fieldName and $value) { $this->setField($fieldName, $value); @@ -31,11 +31,11 @@ public function __construct ($fieldName = null, $value = null) /** * Set field for fuzzy query * - * @param string $fieldName Field name - * @param string $value String to search for + * @param string $fieldName Field name + * @param string $value String to search for * @return \Elastica\Query\Fuzzy Current object */ - public function setField ($fieldName, $value) + public function setField($fieldName, $value) { if (!is_string($value) or !is_string($fieldName)) { throw new InvalidException('The field and value arguments must be of type string.'); @@ -43,21 +43,23 @@ public function setField ($fieldName, $value) if (count($this->getParams()) > 0 and array_shift(array_keys($this->getParams())) != $fieldName) { throw new InvalidException('Fuzzy query can only support a single field.'); } + return $this->setParam($fieldName, array('value' => $value)); } /** * Set optional parameters on the existing query * - * @param string $param option name - * @param mixed $value Value of the parameter + * @param string $param option name + * @param mixed $value Value of the parameter * @return \Elastica\Query\Fuzzy Current object */ - public function setFieldOption ($param, $value) { + public function setFieldOption($param, $value) + { //Retrieve the single existing field for alteration. $params = $this->getParams(); if (count($params) < 1) { - throw new InvalidException('No field has been set'); + throw new InvalidException('No field has been set'); } $keyArray = array_keys($params); $params[$keyArray[0]][$param] = $value; @@ -79,6 +81,7 @@ public function addField($fieldName, $args) foreach ($args as $param => $value) { $this->setFieldOption($param, $value); } + return $this; } } diff --git a/lib/Elastica/Query/FuzzyLikeThis.php b/lib/Elastica/Query/FuzzyLikeThis.php index 032acdb643..2df245e8d2 100644 --- a/lib/Elastica/Query/FuzzyLikeThis.php +++ b/lib/Elastica/Query/FuzzyLikeThis.php @@ -68,11 +68,10 @@ class FuzzyLikeThis extends AbstractQuery */ protected $_analyzer; - /** * Adds field to flt query * - * @param array $fields Field names + * @param array $fields Field names * @return \Elastica\Query\FuzzyLikeThis Current object */ public function addFields(array $fields) @@ -85,7 +84,7 @@ public function addFields(array $fields) /** * Set the "like_text" value * - * @param string $text + * @param string $text * @return \Elastica\Query\FuzzyLikeThis This current object */ public function setLikeText($text) @@ -99,7 +98,7 @@ public function setLikeText($text) /** * Set the "ignore_tf" value (ignore term frequency) * - * @param bool $ignoreTF + * @param bool $ignoreTF * @return \Elastica\Query\FuzzyLikeThis Current object */ public function setIgnoreTF($ignoreTF) @@ -112,7 +111,7 @@ public function setIgnoreTF($ignoreTF) /** * Set the minimum similarity * - * @param int $value + * @param int $value * @return \Elastica\Query\FuzzyLikeThis This current object */ public function setMinSimilarity($value) @@ -126,7 +125,7 @@ public function setMinSimilarity($value) /** * Set boost * - * @param float $value Boost value + * @param float $value Boost value * @return \Elastica\Query\FuzzyLikeThis Query object */ public function setBoost($value) @@ -139,7 +138,7 @@ public function setBoost($value) /** * Set Prefix Length * - * @param int $value Prefix length + * @param int $value Prefix length * @return \Elastica\Query\FuzzyLikeThis */ public function setPrefixLength($value) @@ -152,7 +151,7 @@ public function setPrefixLength($value) /** * Set max_query_terms * - * @param int $value Max query terms value + * @param int $value Max query terms value * @return \Elastica\Query\FuzzyLikeThis */ public function setMaxQueryTerms($value) @@ -165,7 +164,7 @@ public function setMaxQueryTerms($value) /** * Set analyzer * - * @param string $text Analyzer text + * @param string $text Analyzer text * @return \Elastica\Query\FuzzyLikeThis */ public function setAnalyzer($text) @@ -196,7 +195,6 @@ public function toArray() $args['analyzer'] = $this->_analyzer; } - $args['min_similarity'] = ($this->_minSimilarity > 0) ? $this->_minSimilarity : 0; $args['like_text'] = $this->_likeText; diff --git a/lib/Elastica/Query/HasChild.php b/lib/Elastica/Query/HasChild.php index e849a9bf05..ed5b26b9d7 100644 --- a/lib/Elastica/Query/HasChild.php +++ b/lib/Elastica/Query/HasChild.php @@ -1,6 +1,7 @@ array_merge(array('query' => $this->_queryString), $this->getParams()),); + return array('query_string' => array_merge(array('query' => $this->_queryString), $this->getParams())); } } diff --git a/lib/Elastica/Query/Range.php b/lib/Elastica/Query/Range.php index 54b79027a3..2bf59ea607 100644 --- a/lib/Elastica/Query/Range.php +++ b/lib/Elastica/Query/Range.php @@ -28,8 +28,8 @@ public function __construct($fieldName = null, array $args = array()) /** * Adds a range field to the query * - * @param string $fieldName Field name - * @param array $args Field arguments + * @param string $fieldName Field name + * @param array $args Field arguments * @return \Elastica\Query\Range Current object */ public function addField($fieldName, array $args) diff --git a/lib/Elastica/Query/Simple.php b/lib/Elastica/Query/Simple.php index 2448ca7973..75de2d2723 100644 --- a/lib/Elastica/Query/Simple.php +++ b/lib/Elastica/Query/Simple.php @@ -32,7 +32,7 @@ public function __construct(array $query) /** * Sets new query array * - * @param array $query Query array + * @param array $query Query array * @return \Elastica\Query\Simple Current object */ public function setQuery(array $query) diff --git a/lib/Elastica/Query/SimpleQueryString.php b/lib/Elastica/Query/SimpleQueryString.php index a6c4ba9d41..0a51f2205a 100644 --- a/lib/Elastica/Query/SimpleQueryString.php +++ b/lib/Elastica/Query/SimpleQueryString.php @@ -14,7 +14,7 @@ class SimpleQueryString extends AbstractQuery /** * @param string $query - * @param array $fields + * @param array $fields */ public function __construct($query, array $fields = array()) { @@ -26,7 +26,7 @@ public function __construct($query, array $fields = array()) /** * Set the querystring for this query - * @param string $query see ES documentation for querystring syntax + * @param string $query see ES documentation for querystring syntax * @return \Elastica\Query\SimpleQueryString */ public function setQuery($query) @@ -35,7 +35,7 @@ public function setQuery($query) } /** - * @param string[] $fields the fields on which to perform this query. Defaults to index.query.default_field. + * @param string[] $fields the fields on which to perform this query. Defaults to index.query.default_field. * @return \Elastica\Query\SimpleQueryString */ public function setFields(array $fields) @@ -45,7 +45,7 @@ public function setFields(array $fields) /** * Set the default operator to use if no explicit operator is defined in the query string - * @param string $operator see OPERATOR_* constants for options + * @param string $operator see OPERATOR_* constants for options * @return \Elastica\Query\SimpleQueryString */ public function setDefaultOperator($operator) @@ -55,11 +55,11 @@ public function setDefaultOperator($operator) /** * Set the analyzer used to analyze each term of the query - * @param string $analyzer + * @param string $analyzer * @return \Elastica\Query\SimpleQueryString */ public function setAnalyzer($analyzer) { return $this->setParam("analyzer", $analyzer); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Query/Term.php b/lib/Elastica/Query/Term.php index eb20eb86aa..12fc350d8c 100644 --- a/lib/Elastica/Query/Term.php +++ b/lib/Elastica/Query/Term.php @@ -26,7 +26,7 @@ public function __construct(array $term = array()) * Set term can be used instead of addTerm if some more special * values for a term have to be set. * - * @param array $term Term array + * @param array $term Term array * @return \Elastica\Query\Term Current object */ public function setRawTerm(array $term) @@ -37,9 +37,9 @@ public function setRawTerm(array $term) /** * Adds a term to the term query * - * @param string $key Key to query - * @param string|array $value Values(s) for the query. Boost can be set with array - * @param float $boost OPTIONAL Boost value (default = 1.0) + * @param string $key Key to query + * @param string|array $value Values(s) for the query. Boost can be set with array + * @param float $boost OPTIONAL Boost value (default = 1.0) * @return \Elastica\Query\Term Current object */ public function setTerm($key, $value, $boost = 1.0) diff --git a/lib/Elastica/Query/Terms.php b/lib/Elastica/Query/Terms.php index 41cc921666..96167e89ed 100644 --- a/lib/Elastica/Query/Terms.php +++ b/lib/Elastica/Query/Terms.php @@ -1,6 +1,7 @@ _facades[$dsl])) { - throw new QueryBuilderException('DSL "' . $dsl . '" not supported'); + throw new QueryBuilderException('DSL "'.$dsl.'" not supported'); } return $this->_facades[$dsl]; diff --git a/lib/Elastica/QueryBuilder/DSL/Aggregation.php b/lib/Elastica/QueryBuilder/DSL/Aggregation.php index a533c61c17..727d4aed6f 100644 --- a/lib/Elastica/QueryBuilder/DSL/Aggregation.php +++ b/lib/Elastica/QueryBuilder/DSL/Aggregation.php @@ -51,7 +51,7 @@ public function getType() * min aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html - * @param string $name + * @param string $name * @return Min */ public function min($name) @@ -63,7 +63,7 @@ public function min($name) * max aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html - * @param string $name + * @param string $name * @return Max */ public function max($name) @@ -75,7 +75,7 @@ public function max($name) * sum aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html - * @param string $name + * @param string $name * @return Sum */ public function sum($name) @@ -87,7 +87,7 @@ public function sum($name) * avg aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html - * @param string $name + * @param string $name * @return Avg */ public function avg($name) @@ -99,7 +99,7 @@ public function avg($name) * stats aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html - * @param string $name + * @param string $name * @return Stats */ public function stats($name) @@ -111,7 +111,7 @@ public function stats($name) * extended stats aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-extendedstats-aggregation.html - * @param string $name + * @param string $name * @return ExtendedStats */ public function extended_stats($name) @@ -123,8 +123,8 @@ public function extended_stats($name) * value count aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html - * @param string $name - * @param string $field + * @param string $name + * @param string $field * @return ValueCount */ public function value_count($name, $field) @@ -158,7 +158,7 @@ public function percentile_ranks($name) * cardinality aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html - * @param string $name + * @param string $name * @return Cardinality */ public function cardinality($name) @@ -203,7 +203,7 @@ public function scripted_metric($name) * global aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-global-aggregation.html - * @param string $name + * @param string $name * @return GlobalAggregation */ public function global_agg($name) @@ -215,8 +215,8 @@ public function global_agg($name) * filter aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html - * @param string $name - * @param AbstractFilter $filter + * @param string $name + * @param AbstractFilter $filter * @return FilterAggregation */ public function filter($name, AbstractFilter $filter) @@ -242,8 +242,8 @@ public function filters($name) * missing aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-missing-aggregation.html - * @param string $name - * @param string $field + * @param string $name + * @param string $field * @return Missing */ public function missing($name, $field) @@ -255,8 +255,8 @@ public function missing($name, $field) * nested aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html - * @param string $name - * @param string $path the nested path for this aggregation + * @param string $name + * @param string $path the nested path for this aggregation * @return Nested */ public function nested($name, $path) @@ -268,7 +268,7 @@ public function nested($name, $path) * reverse nested aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-reverse-nested-aggregation.html - * @param string $name + * @param string $name * @return ReverseNested */ public function reverse_nested($name) @@ -291,7 +291,7 @@ public function children($name) * terms aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html - * @param string $name + * @param string $name * @return Terms */ public function terms($name) @@ -314,7 +314,7 @@ public function significant_terms($name) * range aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-range-aggregation.html - * @param string $name + * @param string $name * @return Range */ public function range($name) @@ -326,7 +326,7 @@ public function range($name) * date range aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-daterange-aggregation.html - * @param string $name + * @param string $name * @return DateRange */ public function date_range($name) @@ -338,8 +338,8 @@ public function date_range($name) * ipv4 range aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-iprange-aggregation.html - * @param string $name - * @param string $field + * @param string $name + * @param string $field * @return IpRange */ public function ipv4_range($name, $field) @@ -351,9 +351,9 @@ public function ipv4_range($name, $field) * histogram aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-histogram-aggregation.html - * @param string $name the name of this aggregation - * @param string $field the name of the field on which to perform the aggregation - * @param int $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 $interval the interval by which documents will be bucketed * @return Histogram */ public function histogram($name, $field, $interval) @@ -365,9 +365,9 @@ public function histogram($name, $field, $interval) * date histogram aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html - * @param string $name the name of this aggregation - * @param string $field the name of the field on which to perform the aggregation - * @param int $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 $interval the interval by which documents will be bucketed * @return DateHistogram */ public function date_histogram($name, $field, $interval) @@ -379,9 +379,9 @@ public function date_histogram($name, $field, $interval) * geo distance aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geodistance-aggregation.html - * @param string $name the name if this aggregation - * @param string $field the field on which to perform this aggregation - * @param string|array $origin the point from which distances will be calculated + * @param string $name the name if this aggregation + * @param string $field the field on which to perform this aggregation + * @param string|array $origin the point from which distances will be calculated * @return GeoDistance */ public function geo_distance($name, $field, $origin) @@ -393,8 +393,8 @@ public function geo_distance($name, $field, $origin) * geohash grid aggregation * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-geohashgrid-aggregation.html - * @param string $name the name of this aggregation - * @param string $field the field on which to perform this aggregation + * @param string $name the name of this aggregation + * @param string $field the field on which to perform this aggregation * @return GeohashGrid */ public function geohash_grid($name, $field) diff --git a/lib/Elastica/QueryBuilder/DSL/Filter.php b/lib/Elastica/QueryBuilder/DSL/Filter.php index 20fcaca153..8667e54dee 100644 --- a/lib/Elastica/QueryBuilder/DSL/Filter.php +++ b/lib/Elastica/QueryBuilder/DSL/Filter.php @@ -58,7 +58,7 @@ public function getType() * and filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-and-filter.html - * @param AbstractFilter[] $filters + * @param AbstractFilter[] $filters * @return BoolAnd */ public function bool_and(array $filters) @@ -84,7 +84,7 @@ public function bool() * exists filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-exists-filter.html - * @param string $field + * @param string $field * @return Exists */ public function exists($field) @@ -96,8 +96,8 @@ public function exists($field) * geo bounding box filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-bounding-box-filter.html - * @param string $field - * @param array $coordinates + * @param string $field + * @param array $coordinates * @return GeoBoundingBox */ public function geo_bounding_box($field, array $coordinates) @@ -109,9 +109,9 @@ public function geo_bounding_box($field, array $coordinates) * geo distance filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-filter.htm - * @param string $key Key + * @param string $key Key * @param array|string $location Location as array or geohash: array('lat' => 48.86, 'lon' => 2.35) OR 'drm3btev3e86' - * @param string $distance Distance + * @param string $distance Distance * @return GeoDistance */ public function geo_distance($key, $location, $distance) @@ -123,9 +123,9 @@ public function geo_distance($key, $location, $distance) * geo distance rangefilter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-range-filter.html - * @param string $key - * @param array|string $location - * @param array $ranges + * @param string $key + * @param array|string $location + * @param array $ranges * @return GeoDistanceRange */ public function geo_distance_range($key, $location, array $ranges = array()) @@ -137,8 +137,8 @@ public function geo_distance_range($key, $location, array $ranges = array()) * geo polygon filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-filter.html - * @param string $key Key - * @param array $points Points making up polygon + * @param string $key Key + * @param array $points Points making up polygon * @return GeoPolygon */ public function geo_polygon($key, array $points) @@ -150,9 +150,9 @@ public function geo_polygon($key, array $points) * provided geo shape filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html - * @param string $path - * @param array $coordinates - * @param string $shapeType + * @param string $path + * @param array $coordinates + * @param string $shapeType * @return GeoShapeProvided */ public function geo_shape_provided($path, array $coordinates, $shapeType = GeoShapeProvided::TYPE_ENVELOPE) @@ -164,11 +164,11 @@ public function geo_shape_provided($path, array $coordinates, $shapeType = GeoSh * pre indexed geo shape filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html - * @param string $path The path/field of the shape searched - * @param string $indexedId Id of the pre-indexed shape - * @param string $indexedType Type of the pre-indexed shape - * @param string $indexedIndex Index of the pre-indexed shape - * @param string $indexedPath Path of the pre-indexed shape + * @param string $path The path/field of the shape searched + * @param string $indexedId Id of the pre-indexed shape + * @param string $indexedType Type of the pre-indexed shape + * @param string $indexedIndex Index of the pre-indexed shape + * @param string $indexedPath Path of the pre-indexed shape * @return GeoShapePreIndexed */ public function geo_shape_pre_indexed($path, $indexedId, $indexedType, $indexedIndex, $indexedPath) @@ -180,10 +180,10 @@ public function geo_shape_pre_indexed($path, $indexedId, $indexedType, $indexedI * geohash cell filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geohash-cell-filter.html - * @param string $field The field on which to filter - * @param array|string $location Location as coordinates array or geohash string ['lat' => 40.3, 'lon' => 45.2] - * @param int|string $precision length of geohash prefix or distance (3, or "50m") - * @param bool $neighbors If true, filters cells next to the given cell. + * @param string $field The field on which to filter + * @param array|string $location Location as coordinates array or geohash string ['lat' => 40.3, 'lon' => 45.2] + * @param int|string $precision length of geohash prefix or distance (3, or "50m") + * @param bool $neighbors If true, filters cells next to the given cell. * @return GeohashCell */ public function geohash_cell($field, $location, $precision = -1, $neighbors = false) @@ -195,8 +195,8 @@ public function geohash_cell($field, $location, $precision = -1, $neighbors = fa * has child filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-filter.html - * @param AbstractQuery|AbstractFilter $query - * @param string $type + * @param AbstractQuery|AbstractFilter $query + * @param string $type * @return HasChild */ public function has_child($query, $type) @@ -208,8 +208,8 @@ public function has_child($query, $type) * has parent filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-parent-filter.html - * @param AbstractQuery|AbstractFilter $query - * @param string $type + * @param AbstractQuery|AbstractFilter $query + * @param string $type * @return HasParent */ public function has_parent($query, $type) @@ -221,8 +221,8 @@ public function has_parent($query, $type) * ids filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-ids-filter.html - * @param string|\Elastica\Type $type - * @param array $ids + * @param string|\Elastica\Type $type + * @param array $ids * @return Ids */ public function ids($type, array $ids) @@ -234,8 +234,8 @@ public function ids($type, array $ids) * indices filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-indices-filter.html - * @param AbstractFilter $filter filter which will be applied to docs in the specified indices - * @param string[] $indices + * @param AbstractFilter $filter filter which will be applied to docs in the specified indices + * @param string[] $indices * @return Indices */ public function indices(AbstractFilter $filter, array $indices) @@ -247,7 +247,7 @@ public function indices(AbstractFilter $filter, array $indices) * limit filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-limit-filter.html - * @param int $limit Limit + * @param int $limit Limit * @return Limit */ public function limit($limit) @@ -270,7 +270,7 @@ public function match_all() * missing filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-missing-filter.html - * @param string $field + * @param string $field * @return Missing */ public function missing($field) @@ -293,7 +293,7 @@ public function nested() * not filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-not-filter.html - * @param AbstractFilter $filter + * @param AbstractFilter $filter * @return BoolNot */ public function bool_not(AbstractFilter $filter) @@ -316,7 +316,7 @@ public function numeric_range() * or filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-or-filter.html - * @param AbstractFilter[] $filters + * @param AbstractFilter[] $filters * @return BoolOr */ public function bool_or($filters) @@ -331,8 +331,8 @@ public function bool_or($filters) * prefix filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-prefix-filter.html - * @param string $field - * @param string $prefix + * @param string $field + * @param string $prefix * @return Prefix */ public function prefix($field, $prefix) @@ -344,7 +344,7 @@ public function prefix($field, $prefix) * query filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html - * @param AbstractQuery $query + * @param AbstractQuery $query * @return QueryFilter */ public function query(AbstractQuery $query) @@ -356,8 +356,8 @@ public function query(AbstractQuery $query) * range filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html - * @param string $fieldName - * @param array $args + * @param string $fieldName + * @param array $args * @return Range */ public function range($fieldName, array $args) @@ -369,8 +369,8 @@ public function range($fieldName, array $args) * regexp filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-regexp-filter.html - * @param string $field - * @param string $regexp + * @param string $field + * @param string $regexp * @return Regexp */ public function regexp($field, $regexp) @@ -382,7 +382,7 @@ public function regexp($field, $regexp) * script filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html - * @param array|string|\Elastica\Script $script + * @param array|string|\Elastica\Script $script * @return Script */ public function script($script) @@ -394,7 +394,7 @@ public function script($script) * term filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html - * @param array $term + * @param array $term * @return Term */ public function term(array $term = array()) @@ -406,8 +406,8 @@ public function term(array $term = array()) * terms filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-filter.html - * @param string $field - * @param array $terms + * @param string $field + * @param array $terms * @return Terms */ public function terms($field, array $terms) @@ -419,7 +419,7 @@ public function terms($field, array $terms) * type filter * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-type-filter.html - * @param string $type + * @param string $type * @return Type */ public function type($type) diff --git a/lib/Elastica/QueryBuilder/DSL/Query.php b/lib/Elastica/QueryBuilder/DSL/Query.php index b9525b3486..65ce56ad8f 100644 --- a/lib/Elastica/QueryBuilder/DSL/Query.php +++ b/lib/Elastica/QueryBuilder/DSL/Query.php @@ -55,8 +55,8 @@ public function getType() * match query * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html - * @param null|string $field - * @param null|string $value + * @param null|string $field + * @param null|string $value * @return Match */ public function match($field = null, $value = null) @@ -108,9 +108,9 @@ public function boosting() * common terms query * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html - * @param string $field - * @param string $query - * @param float $cutoffFrequency percentage in decimal form (.001 == 0.1%) + * @param string $field + * @param string $query + * @param float $cutoffFrequency percentage in decimal form (.001 == 0.1%) * @return Common */ public function common_terms($field, $query, $cutoffFrequency) @@ -183,8 +183,8 @@ public function field() /** * filtered query * - * @param AbstractFilter $filter - * @param AbstractQuery $query + * @param AbstractFilter $filter + * @param AbstractQuery $query * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-filtered-query.html * @return Filtered */ @@ -250,8 +250,8 @@ public function geo_shape() * has child query * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html - * @param AbstractQuery $query - * @param null|string $type + * @param AbstractQuery $query + * @param null|string $type * @return HasChild */ public function has_child(AbstractQuery $query, $type = null) @@ -263,8 +263,8 @@ public function has_child(AbstractQuery $query, $type = null) * has parent query * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html - * @param AbstractQuery $query - * @param string $type + * @param AbstractQuery $query + * @param string $type * @return HasParent */ public function has_parent(AbstractQuery $query, $type) @@ -276,8 +276,8 @@ public function has_parent(AbstractQuery $query, $type) * ids query * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html - * @param array|string|\Elastica\Type $type - * @param array $ids + * @param array|string|\Elastica\Type $type + * @param array $ids * @return Ids */ public function ids($type, array $ids) @@ -364,8 +364,8 @@ public function query_string() * simple_query_string query * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html - * @param string $query - * @param array $fields + * @param string $query + * @param array $fields * @return SimpleQueryString */ public function simple_query_string($query, array $fields = array()) @@ -377,8 +377,8 @@ public function simple_query_string($query, array $fields = array()) * range query * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-range-query.html - * @param string $fieldName - * @param array $args + * @param string $fieldName + * @param array $args * @return Range */ public function range($fieldName, array $args) @@ -471,8 +471,8 @@ public function term() * terms query * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html - * @param string $field - * @param array $terms + * @param string $field + * @param array $terms * @return Terms */ public function terms($field, array $terms) @@ -484,8 +484,8 @@ public function terms($field, array $terms) * top children query * * @link http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-top-children-query.html - * @param AbstractQuery $query - * @param string $type + * @param AbstractQuery $query + * @param string $type * @return TopChildren */ public function top_children(AbstractQuery $query, $type) diff --git a/lib/Elastica/QueryBuilder/Facade.php b/lib/Elastica/QueryBuilder/Facade.php index 42295b6101..4eeacaa6c3 100644 --- a/lib/Elastica/QueryBuilder/Facade.php +++ b/lib/Elastica/QueryBuilder/Facade.php @@ -3,8 +3,6 @@ namespace Elastica\QueryBuilder; use Elastica\Exception\QueryBuilderException; -use Elastica\QueryBuilder\DSL; -use Elastica\QueryBuilder\Version; /** * Facade for a specific DSL object @@ -27,7 +25,7 @@ class Facade /** * Constructor * - * @param DSL $dsl + * @param DSL $dsl * @param Version $version */ public function __construct(DSL $dsl, Version $version) @@ -40,7 +38,7 @@ public function __construct(DSL $dsl, Version $version) * Executes DSL methods * * @param $name - * @param array $arguments + * @param array $arguments * @return mixed * @throws QueryBuilderException */ @@ -49,7 +47,7 @@ public function __call($name, array $arguments) // defined check if (false === method_exists($this->_dsl, $name)) { throw new QueryBuilderException( - 'undefined ' . $this->_dsl->getType() . ' "' . $name . '"' + 'undefined '.$this->_dsl->getType().' "'.$name.'"' ); } @@ -57,7 +55,7 @@ public function __call($name, array $arguments) if (false === $this->_version->supports($name, $this->_dsl->getType())) { $reflection = new \ReflectionClass($this->_version); throw new QueryBuilderException( - $this->_dsl->getType() . ' "' . $name . '" in ' . $reflection->getShortName() . ' not supported' + $this->_dsl->getType().' "'.$name.'" in '.$reflection->getShortName().' not supported' ); } diff --git a/lib/Elastica/QueryBuilder/Version.php b/lib/Elastica/QueryBuilder/Version.php index a5798d4e73..e04a38fb74 100644 --- a/lib/Elastica/QueryBuilder/Version.php +++ b/lib/Elastica/QueryBuilder/Version.php @@ -2,7 +2,6 @@ namespace Elastica\QueryBuilder; -use Elastica\QueryBuilder\DSL; /** * Abstract Version class @@ -43,7 +42,7 @@ abstract class Version /** * returns true if $name is supported, false otherwise * - * @param string $name + * @param string $name * @param $type * @return bool */ diff --git a/lib/Elastica/QueryBuilder/Version/Version090.php b/lib/Elastica/QueryBuilder/Version/Version090.php index 8e444256eb..8dbb35bd7e 100644 --- a/lib/Elastica/QueryBuilder/Version/Version090.php +++ b/lib/Elastica/QueryBuilder/Version/Version090.php @@ -93,6 +93,6 @@ class Version090 extends Version protected $suggesters = array( 'term', 'phrase', - 'completion' + 'completion', ); } diff --git a/lib/Elastica/QueryBuilder/Version/Version100.php b/lib/Elastica/QueryBuilder/Version/Version100.php index d39e5ea8c9..a73fbdbea8 100644 --- a/lib/Elastica/QueryBuilder/Version/Version100.php +++ b/lib/Elastica/QueryBuilder/Version/Version100.php @@ -119,6 +119,6 @@ class Version100 extends Version protected $suggesters = array( 'term', 'phrase', - 'completion' + 'completion', ); } diff --git a/lib/Elastica/QueryBuilder/Version/Version110.php b/lib/Elastica/QueryBuilder/Version/Version110.php index c4f52d52c1..b284f1fed1 100644 --- a/lib/Elastica/QueryBuilder/Version/Version110.php +++ b/lib/Elastica/QueryBuilder/Version/Version110.php @@ -60,7 +60,7 @@ class Version110 extends Version // 'custom_boost_factor' // new in 1.1.0 - 'template' + 'template', ); protected $filters = array( @@ -121,12 +121,12 @@ class Version110 extends Version // new in 1.1.0 'percentiles', 'cardinality', - 'significant_terms' + 'significant_terms', ); protected $suggesters = array( 'term', 'phrase', - 'completion' + 'completion', ); } diff --git a/lib/Elastica/QueryBuilder/Version/Version120.php b/lib/Elastica/QueryBuilder/Version/Version120.php index df387f27ae..caf9f8da5b 100644 --- a/lib/Elastica/QueryBuilder/Version/Version120.php +++ b/lib/Elastica/QueryBuilder/Version/Version120.php @@ -60,7 +60,7 @@ class Version120 extends Version // 'custom_boost_factor' // new in 1.1.0 - 'template' + 'template', ); protected $filters = array( @@ -124,7 +124,7 @@ class Version120 extends Version 'significant_terms', // new in 1.2.0 - 'reverse_nested' + 'reverse_nested', ); protected $suggesters = array( @@ -133,6 +133,6 @@ class Version120 extends Version 'completion', // new in 1.2.0 - 'context' + 'context', ); } diff --git a/lib/Elastica/QueryBuilder/Version/Version130.php b/lib/Elastica/QueryBuilder/Version/Version130.php index 0dc452d9f1..f03f9a2e4e 100644 --- a/lib/Elastica/QueryBuilder/Version/Version130.php +++ b/lib/Elastica/QueryBuilder/Version/Version130.php @@ -60,7 +60,7 @@ class Version130 extends Version // 'custom_boost_factor' // new in 1.1.0 - 'template' + 'template', ); protected $filters = array( @@ -129,7 +129,7 @@ class Version130 extends Version // new in 1.3.0 'percentile_ranks', 'geo_bounds', - 'top_hits' + 'top_hits', ); protected $suggesters = array( @@ -138,6 +138,6 @@ class Version130 extends Version 'completion', // new in 1.2.0 - 'context' + 'context', ); } diff --git a/lib/Elastica/QueryBuilder/Version/Version140.php b/lib/Elastica/QueryBuilder/Version/Version140.php index e783631dca..7c03786005 100644 --- a/lib/Elastica/QueryBuilder/Version/Version140.php +++ b/lib/Elastica/QueryBuilder/Version/Version140.php @@ -2,7 +2,6 @@ namespace Elastica\QueryBuilder\Version; -use Elastica\QueryBuilder\Version; /** * elasticsearch 1.4 DSL @@ -60,7 +59,7 @@ class Version140 extends Version130 // 'custom_boost_factor' // new in 1.1.0 - 'template' + 'template', ); protected $filters = array( @@ -134,7 +133,7 @@ class Version140 extends Version130 // new in 1.4.0 'scripted_metric', 'filters', - 'children' + 'children', ); protected $suggesters = array( @@ -143,6 +142,6 @@ class Version140 extends Version130 'completion', // new in 1.2.0 - 'context' + 'context', ); } diff --git a/lib/Elastica/Request.php b/lib/Elastica/Request.php index 6c6298be56..c9f3e95867 100644 --- a/lib/Elastica/Request.php +++ b/lib/Elastica/Request.php @@ -3,7 +3,6 @@ namespace Elastica; use Elastica\Exception\InvalidException; -use Elastica\JSON; /** * Elastica Request object @@ -28,11 +27,11 @@ class Request extends Param /** * Construct * - * @param string $path Request path - * @param string $method OPTIONAL Request method (use const's) (default = self::GET) - * @param array $data OPTIONAL Data array - * @param array $query OPTIONAL Query params - * @param Connection $connection + * @param string $path Request path + * @param string $method OPTIONAL Request method (use const's) (default = self::GET) + * @param array $data OPTIONAL Data array + * @param array $query OPTIONAL Query params + * @param Connection $connection * @return \Elastica\Request OPTIONAL Connection object */ public function __construct($path, $method = self::GET, $data = array(), array $query = array(), Connection $connection = null) @@ -50,7 +49,7 @@ public function __construct($path, $method = self::GET, $data = array(), array $ /** * Sets the request method. Use one of the for consts * - * @param string $method Request method + * @param string $method Request method * @return \Elastica\Request Current object */ public function setMethod($method) @@ -71,7 +70,7 @@ public function getMethod() /** * Sets the request data * - * @param array $data Request data + * @param array $data Request data * @return \Elastica\Request */ public function setData($data) @@ -92,7 +91,7 @@ public function getData() /** * Sets the request path * - * @param string $path Request path + * @param string $path Request path * @return \Elastica\Request Current object */ public function setPath($path) @@ -121,7 +120,7 @@ public function getQuery() } /** - * @param array $query + * @param array $query * @return \Elastica\Request */ public function setQuery(array $query = array()) @@ -177,6 +176,7 @@ public function toArray() if ($this->_connection) { $data['connection'] = $this->_connection->getParams(); } + return $data; } diff --git a/lib/Elastica/Rescore/AbstractRescore.php b/lib/Elastica/Rescore/AbstractRescore.php index cb6c7ccec7..f402c23ddc 100644 --- a/lib/Elastica/Rescore/AbstractRescore.php +++ b/lib/Elastica/Rescore/AbstractRescore.php @@ -1,6 +1,7 @@ setParam('window_size', $size); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Rescore/Query.php b/lib/Elastica/Rescore/Query.php index 5041f3edba..8dff2f6901 100644 --- a/lib/Elastica/Rescore/Query.php +++ b/lib/Elastica/Rescore/Query.php @@ -63,7 +63,7 @@ public function setRescoreQuery($rescoreQuery) /** * Sets query_weight * - * @param float $weight + * @param float $weight * @return \Elastica\Query\Rescore */ public function setQueryWeight($weight) @@ -77,7 +77,7 @@ public function setQueryWeight($weight) /** * Sets rescore_query_weight * - * @param float $size + * @param float $size * @return \Elastica\Query\Rescore */ public function setRescoreQueryWeight($weight) @@ -87,4 +87,4 @@ public function setRescoreQueryWeight($weight) return $this->setParam('query', $query); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Response.php b/lib/Elastica/Response.php index cf5e6a1a29..4dc0f3ac79 100644 --- a/lib/Elastica/Response.php +++ b/lib/Elastica/Response.php @@ -4,7 +4,6 @@ use Elastica\Exception\JSONParseException; use Elastica\Exception\NotFoundException; -use Elastica\JSON; /** * Elastica Response object @@ -63,7 +62,7 @@ class Response * Construct * * @param string|array $responseString Response string (json) - * @param int $responseStatus http status code + * @param int $responseStatus http status code */ public function __construct($responseString, $responseStatus = null) { @@ -138,6 +137,7 @@ public function isOk() if ($data['status'] >= 200 && $data['status'] <= 300) { return true; } + return false; } @@ -149,7 +149,6 @@ public function isOk() foreach ($data['items'] as $item) { if (isset($item['index']['ok']) && false == $item['index']['ok']) { return false; - } elseif (isset($item['index']['status']) && ($item['index']['status'] < 200 || $item['index']['status'] >= 300)) { return false; } @@ -174,7 +173,6 @@ public function getStatus() return $this->_status; } - /** * Response data array * @@ -222,12 +220,13 @@ public function getTransferInfo() * Sets the transfer info of the curl request. This function is called * from the \Elastica\Client::_callService . * - * @param array $transferInfo The curl transfer information. + * @param array $transferInfo The curl transfer information. * @return \Elastica\Response Current object */ public function setTransferInfo(array $transferInfo) { $this->_transferInfo = $transferInfo; + return $this; } @@ -244,7 +243,7 @@ public function getQueryTime() /** * Sets the query time * - * @param float $queryTime Query time + * @param float $queryTime Query time * @return \Elastica\Response Current object */ public function setQueryTime($queryTime) @@ -258,7 +257,7 @@ public function setQueryTime($queryTime) * Time request took * * @throws \Elastica\Exception\NotFoundException - * @return int Time request took + * @return int Time request took */ public function getEngineTime() { diff --git a/lib/Elastica/Result.php b/lib/Elastica/Result.php index e8aa8e3d1e..791e1ac46e 100644 --- a/lib/Elastica/Result.php +++ b/lib/Elastica/Result.php @@ -58,8 +58,8 @@ public function getParam($name) public function hasParam($name) { return isset($this->_hit[$name]); - } - + } + /** * Returns the hit id * @@ -92,14 +92,14 @@ public function getFields() /** * Returns whether result has fields - * + * * @return bool */ public function hasFields() { return $this->hasParam('fields'); - } - + } + /** * Returns the index name of the result * @@ -200,11 +200,11 @@ public function __get($key) return array_key_exists($key, $source) ? $source[$key] : null; } - + /** * Magic function to support isset() calls * - * @param string $key Key name + * @param string $key Key name * @return bool */ public function __isset($key) diff --git a/lib/Elastica/ResultSet.php b/lib/Elastica/ResultSet.php index 55c739e25d..e2d7d65100 100644 --- a/lib/Elastica/ResultSet.php +++ b/lib/Elastica/ResultSet.php @@ -1,6 +1,7 @@ _response->getData(); + return isset($data['suggest']); } /** - * Return all suggests - * - * @return array suggest results - */ - public function getSuggests() + * Return all suggests + * + * @return array suggest results + */ + public function getSuggests() { $data = $this->_response->getData(); + return isset($data['suggest']) ? $data['suggest'] : array(); } @@ -196,7 +200,7 @@ public function getAggregations() /** * Retrieve a specific aggregation from this result set - * @param string $name the name of the desired aggregation + * @param string $name the name of the desired aggregation * @return array * @throws Exception\InvalidException if an aggregation by the given name cannot be found */ @@ -243,20 +247,20 @@ public function getMaxScore() } /** - * Returns the total number of ms for this search to complete - * - * @return int Total time - */ + * Returns the total number of ms for this search to complete + * + * @return int Total time + */ public function getTotalTime() { return (int) $this->_took; } /** - * Returns true iff the query has timed out - * - * @return bool Timed out - */ + * Returns true iff the query has timed out + * + * @return bool Timed out + */ public function hasTimedOut() { return (bool) $this->_timedOut; @@ -356,8 +360,8 @@ public function rewind() * Whether a offset exists * @link http://php.net/manual/en/arrayaccess.offsetexists.php * - * @param integer $offset - * @return boolean true on success or false on failure. + * @param integer $offset + * @return boolean true on success or false on failure. */ public function offsetExists($offset) { @@ -368,9 +372,9 @@ public function offsetExists($offset) * Offset to retrieve * @link http://php.net/manual/en/arrayaccess.offsetget.php * - * @param integer $offset - * @throws Exception\InvalidException - * @return Result|null + * @param integer $offset + * @throws Exception\InvalidException + * @return Result|null */ public function offsetGet($offset) { @@ -385,9 +389,9 @@ public function offsetGet($offset) * Offset to set * @link http://php.net/manual/en/arrayaccess.offsetset.php * - * @param integer $offset - * @param Result $value - * @throws Exception\InvalidException + * @param integer $offset + * @param Result $value + * @throws Exception\InvalidException */ public function offsetSet($offset, $value) { diff --git a/lib/Elastica/ScanAndScroll.php b/lib/Elastica/ScanAndScroll.php index c83054e885..65dd7b5085 100644 --- a/lib/Elastica/ScanAndScroll.php +++ b/lib/Elastica/ScanAndScroll.php @@ -10,8 +10,8 @@ * @author Manuel Andreo Garcia * @link http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/scan-scroll.html */ -class ScanAndScroll implements \Iterator { - +class ScanAndScroll implements \Iterator +{ /** * time value parameter * @@ -50,9 +50,10 @@ class ScanAndScroll implements \Iterator { * * @param Search $search * @param string $expiryTime - * @param int $sizePerShard + * @param int $sizePerShard */ - public function __construct(Search $search, $expiryTime = '1m', $sizePerShard = 1000) { + public function __construct(Search $search, $expiryTime = '1m', $sizePerShard = 1000) + { $this->_search = $search; $this->expiryTime = $expiryTime; $this->sizePerShard = $sizePerShard; @@ -64,7 +65,8 @@ public function __construct(Search $search, $expiryTime = '1m', $sizePerShard = * @link http://php.net/manual/en/iterator.current.php * @return ResultSet */ - public function current() { + public function current() + { return $this->_currentResultSet; } @@ -74,7 +76,8 @@ public function current() { * @link http://php.net/manual/en/iterator.next.php * @return void */ - public function next() { + public function next() + { $this->_scroll(); } @@ -84,7 +87,8 @@ public function next() { * @link http://php.net/manual/en/iterator.key.php * @return string */ - public function key() { + public function key() + { return $this->_lastScrollId; } @@ -94,7 +98,8 @@ public function key() { * @link http://php.net/manual/en/iterator.valid.php * @return boolean */ - public function valid() { + public function valid() + { return $this->_nextScrollId !== null && $this->_currentResultSet !== null @@ -107,7 +112,8 @@ public function valid() { * @throws \Elastica\Exception\InvalidException * @return void */ - public function rewind() { + public function rewind() + { $this->_search->getQuery()->setSize($this->sizePerShard); $this->_search->setOption(Search::OPTION_SEARCH_TYPE, Search::OPTION_SEARCH_TYPE_SCAN); @@ -125,7 +131,8 @@ public function rewind() { * @throws \Elastica\Exception\InvalidException * @return void */ - protected function _scroll() { + protected function _scroll() + { $this->_search->setOption(Search::OPTION_SEARCH_TYPE, Search::OPTION_SEARCH_TYPE_SCROLL); $this->_search->setOption(Search::OPTION_SCROLL_ID, $this->_nextScrollId); @@ -138,13 +145,13 @@ protected function _scroll() { * Save last scroll id and extract the new one if possible * @param ResultSet $resultSet */ - protected function _setScrollId(ResultSet $resultSet) { + protected function _setScrollId(ResultSet $resultSet) + { $this->_lastScrollId = $this->_nextScrollId; $this->_nextScrollId = null; - if($resultSet->getResponse()->isOk()) { + if ($resultSet->getResponse()->isOk()) { $this->_nextScrollId = $resultSet->getResponse()->getScrollId(); } } - -} \ No newline at end of file +} diff --git a/lib/Elastica/Script.php b/lib/Elastica/Script.php index 99d9a6aa88..a20de57008 100644 --- a/lib/Elastica/Script.php +++ b/lib/Elastica/Script.php @@ -103,7 +103,7 @@ public static function create($data) } /** - * @param array $data + * @param array $data * @throws \Elastica\Exception\InvalidException * @return \Elastica\Script */ diff --git a/lib/Elastica/ScriptFields.php b/lib/Elastica/ScriptFields.php index 0a8b48711a..3e01638d03 100644 --- a/lib/Elastica/ScriptFields.php +++ b/lib/Elastica/ScriptFields.php @@ -1,6 +1,7 @@ hasOption($key)) { - throw new InvalidException('Option ' . $key . ' does not exist'); + throw new InvalidException('Option '.$key.' does not exist'); } return $this->_options[$key]; @@ -255,7 +254,7 @@ public function getOptions() } /** - * @param string $key + * @param string $key * @return bool * @throws \Elastica\Exception\InvalidException */ @@ -276,7 +275,7 @@ protected function _validateOption($key) return true; } - throw new InvalidException('Invalid option ' . $key); + throw new InvalidException('Invalid option '.$key); } /** @@ -308,7 +307,7 @@ public function hasIndices() } /** - * @param Index|string $index + * @param Index|string $index * @return bool */ public function hasIndex($index) @@ -339,7 +338,7 @@ public function hasTypes() } /** - * @param \Elastica\Type|string $type + * @param \Elastica\Type|string $type * @return bool */ public function hasType($type) @@ -399,18 +398,18 @@ public function getPath() } if (!empty($types)) { - $path .= '/' . implode(',', $types); + $path .= '/'.implode(',', $types); } // Add full path based on indices and types -> could be all - return $path . '/_search'; + return $path.'/_search'; } /** * Search in the set indices, types * - * @param mixed $query - * @param int|array $options OPTIONAL Limit or associative array of options (option=>value) + * @param mixed $query + * @param int|array $options OPTIONAL Limit or associative array of options (option=>value) * @throws \Elastica\Exception\InvalidException * @return \Elastica\ResultSet */ @@ -443,7 +442,7 @@ public function search($query = '', $options = null) /** * - * @param mixed $query + * @param mixed $query * @param $fullResult (default = false) By default only the total hit count is returned. If set to true, the full ResultSet including facets is returned. * @return int|ResultSet */ @@ -466,7 +465,7 @@ public function count($query = '', $fullResult = false) } /** - * @param array|int $options + * @param array|int $options * @param string|array|\Elastica\Query $query * @return \Elastica\Search */ @@ -494,7 +493,7 @@ public function setOptionsAndQuery($options = null, $query = '') } /** - * @param Suggest $suggest + * @param Suggest $suggest * @return Search */ public function setSuggest(Suggest $suggest) @@ -506,11 +505,12 @@ public function setSuggest(Suggest $suggest) * Returns the ScanAndScroll Iterator * * @see Elastica\ScanAndScroll - * @param string $expiryTime - * @param int $sizePerShard + * @param string $expiryTime + * @param int $sizePerShard * @return ScanAndScroll */ - public function scanAndScroll($expiryTime = '1m', $sizePerShard = 1000) { + public function scanAndScroll($expiryTime = '1m', $sizePerShard = 1000) + { return new ScanAndScroll($this, $expiryTime, $sizePerShard); } } diff --git a/lib/Elastica/SearchableInterface.php b/lib/Elastica/SearchableInterface.php index 372bcb1132..6adb0ee8ed 100644 --- a/lib/Elastica/SearchableInterface.php +++ b/lib/Elastica/SearchableInterface.php @@ -39,13 +39,13 @@ public function search($query = '', $options = null); * If no query is set, matchall query is created * * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object - * @return int number of documents matching the query + * @return int number of documents matching the query */ public function count($query = ''); /** - * @param \Elastica\Query $query - * @param array $options + * @param \Elastica\Query $query + * @param array $options * @return \Elastica\Search */ public function createSearch($query = '', $options = null); diff --git a/lib/Elastica/Snapshot.php b/lib/Elastica/Snapshot.php index 4b32172cef..10da5b459d 100644 --- a/lib/Elastica/Snapshot.php +++ b/lib/Elastica/Snapshot.php @@ -27,23 +27,24 @@ public function __construct(Client $client) /** * Register a snapshot repository - * @param string $name the name of the repository - * @param string $type the repository type ("fs" for file system) - * @param array $settings Additional repository settings. If type "fs" is used, the "location" setting must be provided. + * @param string $name the name of the repository + * @param string $type the repository type ("fs" for file system) + * @param array $settings Additional repository settings. If type "fs" is used, the "location" setting must be provided. * @return Response */ public function registerRepository($name, $type, $settings = array()) { $data = array( 'type' => $type, - 'settings' => $settings + 'settings' => $settings, ); + return $this->request($name, Request::PUT, $data); } /** * Retrieve a repository record by name - * @param string $name the name of the desired repository + * @param string $name the name of the desired repository * @throws Exception\ResponseException * @throws Exception\NotFoundException * @return array @@ -54,11 +55,12 @@ public function getRepository($name) $response = $this->request($name); } catch (ResponseException $e) { if ($e->getResponse()->getStatus() == 404) { - throw new NotFoundException("Repository '" . $name . "' does not exist."); + throw new NotFoundException("Repository '".$name."' does not exist."); } throw $e; } $data = $response->getData(); + return $data[$name]; } @@ -73,21 +75,21 @@ public function getAllRepositories() /** * Create a new snapshot - * @param string $repository the name of the repository in which this snapshot should be stored - * @param string $name the name of this snapshot - * @param array $options optional settings for this snapshot - * @param bool $waitForCompletion if true, the request will not return until the snapshot operation is complete + * @param string $repository the name of the repository in which this snapshot should be stored + * @param string $name the name of this snapshot + * @param array $options optional settings for this snapshot + * @param bool $waitForCompletion if true, the request will not return until the snapshot operation is complete * @return Response */ public function createSnapshot($repository, $name, $options = array(), $waitForCompletion = false) { - return $this->request($repository . '/' . $name, Request::PUT, $options, array('wait_for_completion' => $waitForCompletion)); + return $this->request($repository.'/'.$name, Request::PUT, $options, array('wait_for_completion' => $waitForCompletion)); } /** * Retrieve data regarding a specific snapshot - * @param string $repository the name of the repository from which to retrieve the snapshot - * @param string $name the name of the desired snapshot + * @param string $repository the name of the repository from which to retrieve the snapshot + * @param string $name the name of the desired snapshot * @throws Exception\ResponseException * @throws Exception\NotFoundException * @return array @@ -95,61 +97,62 @@ public function createSnapshot($repository, $name, $options = array(), $waitForC public function getSnapshot($repository, $name) { try { - $response = $this->request($repository . "/" . $name); + $response = $this->request($repository."/".$name); } catch (ResponseException $e) { if ($e->getResponse()->getStatus() == 404) { - throw new NotFoundException("Snapshot '" . $name . "' does not exist in repository '" . $repository . "'."); + throw new NotFoundException("Snapshot '".$name."' does not exist in repository '".$repository."'."); } throw $e; } $data = $response->getData(); + return $data['snapshots'][0]; } /** * Retrieve data regarding all snapshots in the given repository - * @param string $repository the repository name + * @param string $repository the repository name * @return array */ public function getAllSnapshots($repository) { - return $this->request($repository . "/_all")->getData(); + return $this->request($repository."/_all")->getData(); } /** * Delete a snapshot - * @param string $repository the repository in which the snapshot resides - * @param string $name the name of the snapshot to be deleted + * @param string $repository the repository in which the snapshot resides + * @param string $name the name of the snapshot to be deleted * @return Response */ public function deleteSnapshot($repository, $name) { - return $this->request($repository . "/" . $name, Request::DELETE); + return $this->request($repository."/".$name, Request::DELETE); } /** * Restore a snapshot - * @param string $repository the name of the repository - * @param string $name the name of the snapshot - * @param array $options options for the restore operation - * @param bool $waitForCompletion if true, the request will not return until the restore operation is complete + * @param string $repository the name of the repository + * @param string $name the name of the snapshot + * @param array $options options for the restore operation + * @param bool $waitForCompletion if true, the request will not return until the restore operation is complete * @return Response */ public function restoreSnapshot($repository, $name, $options = array(), $waitForCompletion = false) { - return $this->request($repository . "/" . $name . "/_restore", Request::POST, $options, array("wait_for_completion" => $waitForCompletion)); + return $this->request($repository."/".$name."/_restore", Request::POST, $options, array("wait_for_completion" => $waitForCompletion)); } /** * Perform a snapshot request - * @param string $path the URL - * @param string $method the HTTP method - * @param array $data request body data - * @param array $query query string parameters + * @param string $path the URL + * @param string $method the HTTP method + * @param array $data request body data + * @param array $query query string parameters * @return Response */ public function request($path, $method = Request::GET, $data = array(), array $query = array()) { - return $this->_client->request("/_snapshot/" . $path, $method, $data, $query); + return $this->_client->request("/_snapshot/".$path, $method, $data, $query); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Status.php b/lib/Elastica/Status.php index a747b9a5e5..3ff3ae4afc 100644 --- a/lib/Elastica/Status.php +++ b/lib/Elastica/Status.php @@ -1,6 +1,7 @@ _client->request('/_alias/' . $alias); + $response = $this->_client->request('/_alias/'.$alias); } catch (ResponseException $e) { $transferInfo = $e->getResponse()->getTransferInfo(); // 404 means the index alias doesn't exist which means no indexes have it. @@ -133,6 +134,7 @@ public function getIndicesWithAlias($alias) foreach ($response->getData() as $name => $unused) { $indices[] = new Index($this->_client, $name); } + return $indices; } diff --git a/lib/Elastica/Suggest.php b/lib/Elastica/Suggest.php index dd5dbbcc68..2fa55da895 100644 --- a/lib/Elastica/Suggest.php +++ b/lib/Elastica/Suggest.php @@ -2,7 +2,6 @@ namespace Elastica; - use Elastica\Exception\NotImplementedException; use Elastica\Suggest\AbstractSuggest; @@ -16,17 +15,16 @@ class Suggest extends Param /** * @param AbstractSuggest $suggestion */ - function __construct(AbstractSuggest $suggestion = NULL) + public function __construct(AbstractSuggest $suggestion = null) { if (!is_null($suggestion)) { $this->addSuggestion($suggestion); } } - /** * Set the global text for this suggester - * @param string $text + * @param string $text * @return \Elastica\Suggest */ public function setGlobalText($text) @@ -36,7 +34,7 @@ public function setGlobalText($text) /** * Add a suggestion to this suggest clause - * @param AbstractSuggest $suggestion + * @param AbstractSuggest $suggestion * @return \Elastica\Suggest */ public function addSuggestion(AbstractSuggest $suggestion) @@ -45,13 +43,13 @@ public function addSuggestion(AbstractSuggest $suggestion) } /** - * @param Suggest|AbstractSuggest $suggestion + * @param Suggest|AbstractSuggest $suggestion * @return \Elastica\Suggest * @throws Exception\NotImplementedException */ public static function create($suggestion) { - switch(true){ + switch (true) { case $suggestion instanceof Suggest: return $suggestion; case $suggestion instanceof AbstractSuggest: @@ -59,4 +57,4 @@ public static function create($suggestion) } throw new NotImplementedException(); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Suggest/AbstractSuggest.php b/lib/Elastica/Suggest/AbstractSuggest.php index e5f5e01c49..c636ae75f4 100644 --- a/lib/Elastica/Suggest/AbstractSuggest.php +++ b/lib/Elastica/Suggest/AbstractSuggest.php @@ -2,7 +2,6 @@ namespace Elastica\Suggest; - use Elastica\Param; /** @@ -33,17 +32,18 @@ public function __construct($name, $field) /** * Suggest text must be set either globally or per suggestion - * @param string $text + * @param string $text * @return \Elastica\Suggest\AbstractSuggest */ public function setText($text) { $this->_text = $text; + return $this; } /** - * @param string $field + * @param string $field * @return \Elastica\Suggest\AbstractSuggest */ public function setField($field) @@ -52,7 +52,7 @@ public function setField($field) } /** - * @param int $size + * @param int $size * @return \Elastica\Suggest\AbstractSuggest */ public function setSize($size) @@ -61,7 +61,7 @@ public function setSize($size) } /** - * @param int $size maximum number of suggestions to be retrieved from each shard + * @param int $size maximum number of suggestions to be retrieved from each shard * @return \Elastica\Suggest\AbstractSuggest */ public function setShardSize($size) @@ -87,6 +87,7 @@ public function toArray() if (isset($this->_text)) { $array['text'] = $this->_text; } + return $array; } -} \ No newline at end of file +} diff --git a/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php b/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php index d9e6ac7c1b..eb0eeed6c9 100644 --- a/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php +++ b/lib/Elastica/Suggest/CandidateGenerator/AbstractCandidateGenerator.php @@ -2,10 +2,8 @@ namespace Elastica\Suggest\CandidateGenerator; - use Elastica\Param; class AbstractCandidateGenerator extends Param { - -} \ No newline at end of file +} diff --git a/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php b/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php index 0277a5ac50..ccb85b2db2 100644 --- a/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php +++ b/lib/Elastica/Suggest/CandidateGenerator/DirectGenerator.php @@ -2,7 +2,6 @@ namespace Elastica\Suggest\CandidateGenerator; - /** * Class DirectGenerator * @package Elastica\Suggest\Phrase @@ -24,7 +23,7 @@ public function __construct($field) /** * Set the field name from which to fetch candidate suggestions - * @param string $field + * @param string $field * @return DirectGenerator */ public function setField($field) @@ -34,7 +33,7 @@ public function setField($field) /** * Set the maximum corrections to be returned per suggest text token - * @param int $size + * @param int $size * @return DirectGenerator */ public function setSize($size) @@ -43,7 +42,7 @@ public function setSize($size) } /** - * @param string $mode see SUGGEST_MODE_* constants for options + * @param string $mode see SUGGEST_MODE_* constants for options * @return DirectGenerator */ public function setSuggestMode($mode) @@ -52,7 +51,7 @@ public function setSuggestMode($mode) } /** - * @param int $max can only be a value between 1 and 2. Defaults to 2. + * @param int $max can only be a value between 1 and 2. Defaults to 2. * @return DirectGenerator */ public function setMaxEdits($max) @@ -61,7 +60,7 @@ public function setMaxEdits($max) } /** - * @param int $length defaults to 1 + * @param int $length defaults to 1 * @return DirectGenerator */ public function setPrefixLength($length) @@ -70,7 +69,7 @@ public function setPrefixLength($length) } /** - * @param int $min defaults to 4 + * @param int $min defaults to 4 * @return DirectGenerator */ public function setMinWordLength($min) @@ -79,7 +78,7 @@ public function setMinWordLength($min) } /** - * @param int $max + * @param int $max * @return DirectGenerator */ public function setMaxInspections($max) @@ -88,7 +87,7 @@ public function setMaxInspections($max) } /** - * @param float $min + * @param float $min * @return DirectGenerator */ public function setMinDocFrequency($min) @@ -97,7 +96,7 @@ public function setMinDocFrequency($min) } /** - * @param float $max + * @param float $max * @return DirectGenerator */ public function setMaxTermFrequency($max) @@ -107,7 +106,7 @@ public function setMaxTermFrequency($max) /** * Set an analyzer to be applied to the original token prior to candidate generation - * @param string $pre an analyzer + * @param string $pre an analyzer * @return DirectGenerator */ public function setPreFilter($pre) @@ -117,11 +116,11 @@ public function setPreFilter($pre) /** * Set an analyzer to be applied to generated tokens before they are passed to the phrase scorer - * @param string $post + * @param string $post * @return DirectGenerator */ public function setPostFilter($post) { return $this->setParam("post_filter", $post); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Suggest/Phrase.php b/lib/Elastica/Suggest/Phrase.php index 5c4adcd006..f5ed0dd8d2 100644 --- a/lib/Elastica/Suggest/Phrase.php +++ b/lib/Elastica/Suggest/Phrase.php @@ -4,7 +4,6 @@ use Elastica\Suggest\CandidateGenerator\AbstractCandidateGenerator; - /** * Class Phrase * @package Elastica\Suggest @@ -13,7 +12,7 @@ class Phrase extends AbstractSuggest { /** - * @param string $analyzer + * @param string $analyzer * @return \Elastica\Suggest\Phrase */ public function setAnalyzer($analyzer) @@ -23,7 +22,7 @@ public function setAnalyzer($analyzer) /** * Set the max size of the n-grams (shingles) in the field - * @param int $size + * @param int $size * @return \Elastica\Suggest\Phrase */ public function setGramSize($size) @@ -33,7 +32,7 @@ public function setGramSize($size) /** * Set the likelihood of a term being misspelled even if the term exists in the dictionary - * @param float $likelihood Defaults to 0.95, meaning 5% of the words are misspelled. + * @param float $likelihood Defaults to 0.95, meaning 5% of the words are misspelled. * @return \Elastica\Suggest\Phrase */ public function setRealWordErrorLikelihood($likelihood) @@ -44,7 +43,7 @@ public function setRealWordErrorLikelihood($likelihood) /** * Set the factor applied to the input phrases score to be used as a threshold for other suggestion candidates. * Only candidates which score higher than this threshold will be included in the result. - * @param float $confidence Defaults to 1.0. + * @param float $confidence Defaults to 1.0. * @return \Elastica\Suggest\Phrase */ public function setConfidence($confidence) @@ -54,7 +53,7 @@ public function setConfidence($confidence) /** * Set the maximum percentage of the terms considered to be misspellings in order to form a correction - * @param float $max + * @param float $max * @return \Elastica\Suggest\Phrase */ public function setMaxErrors($max) @@ -63,7 +62,7 @@ public function setMaxErrors($max) } /** - * @param string $separator + * @param string $separator * @return \Elastica\Param */ public function setSeparator($separator) @@ -73,44 +72,44 @@ public function setSeparator($separator) /** * Set suggestion highlighting - * @param string $preTag - * @param string $postTag + * @param string $preTag + * @param string $postTag * @return \Elastica\Suggest\Phrase */ public function setHighlight($preTag, $postTag) { return $this->setParam("highlight", array( 'pre_tag' => $preTag, - 'post_tag' => $postTag + 'post_tag' => $postTag, )); } /** - * @param float $discount + * @param float $discount * @return \Elastica\Suggest\Phrase */ public function setStupidBackoffSmoothing($discount = 0.4) { return $this->setSmoothingModel("stupid_backoff", array( - "discount" => $discount + "discount" => $discount, )); } /** - * @param float $alpha + * @param float $alpha * @return \Elastica\Suggest\Phrase */ public function setLaplaceSmoothing($alpha = 0.5) { return $this->setSmoothingModel("laplace", array( - "alpha" => $alpha + "alpha" => $alpha, )); } /** - * @param float $trigramLambda - * @param float $bigramLambda - * @param float $unigramLambda + * @param float $trigramLambda + * @param float $bigramLambda + * @param float $unigramLambda * @return \Elastica\Suggest\Phrase */ public function setLinearInterpolationSmoothing($trigramLambda, $bigramLambda, $unigramLambda) @@ -118,24 +117,24 @@ public function setLinearInterpolationSmoothing($trigramLambda, $bigramLambda, $ return $this->setSmoothingModel("linear_interpolation", array( "trigram_lambda" => $trigramLambda, "bigram_lambda" => $bigramLambda, - "unigram_lambda" => $unigramLambda + "unigram_lambda" => $unigramLambda, )); } /** - * @param string $model the name of the smoothing model - * @param array $params + * @param string $model the name of the smoothing model + * @param array $params * @return \Elastica\Suggest\Phrase */ public function setSmoothingModel($model, array $params) { return $this->setParam("smoothing", array( - $model => $params + $model => $params, )); } /** - * @param AbstractCandidateGenerator $generator + * @param AbstractCandidateGenerator $generator * @return \Elastica\Suggest\Phrase */ public function addCandidateGenerator(AbstractCandidateGenerator $generator) @@ -143,6 +142,7 @@ public function addCandidateGenerator(AbstractCandidateGenerator $generator) $generator = $generator->toArray(); $keys = array_keys($generator); $values = array_values($generator); + return $this->addParam($keys[0], $values[0]); } } diff --git a/lib/Elastica/Suggest/Term.php b/lib/Elastica/Suggest/Term.php index 3fca1731c0..dd27126b50 100644 --- a/lib/Elastica/Suggest/Term.php +++ b/lib/Elastica/Suggest/Term.php @@ -2,7 +2,6 @@ namespace Elastica\Suggest; - /** * Class Term * @package Elastica\Suggest @@ -18,7 +17,7 @@ class Term extends AbstractSuggest const SUGGEST_MODE_ALWAYS = 'always'; /** - * @param string $analyzer + * @param string $analyzer * @return \Elastica\Suggest\Term */ public function setAnalyzer($analyzer) @@ -27,7 +26,7 @@ public function setAnalyzer($analyzer) } /** - * @param string $sort see SORT_* constants for options + * @param string $sort see SORT_* constants for options * @return \Elastica\Suggest\Term */ public function setSort($sort) @@ -36,7 +35,7 @@ public function setSort($sort) } /** - * @param string $mode see SUGGEST_MODE_* constants for options + * @param string $mode see SUGGEST_MODE_* constants for options * @return \Elastica\Suggest\Term */ public function setSuggestMode($mode) @@ -46,46 +45,46 @@ public function setSuggestMode($mode) /** * If true, suggest terms will be lower cased after text analysis - * @param bool $lowercase + * @param bool $lowercase * @return \Elastica\Suggest\Term */ public function setLowercaseTerms($lowercase = true) { - return $this->setParam("lowercase_terms", (bool)$lowercase); + return $this->setParam("lowercase_terms", (bool) $lowercase); } /** * Set the maximum edit distance candidate suggestions can have in order to be considered as a suggestion - * @param int $max Either 1 or 2. Any other value will result in an error. + * @param int $max Either 1 or 2. Any other value will result in an error. * @return \Elastica\Suggest\Term */ public function setMaxEdits($max) { - return $this->setParam("max_edits", (int)$max); + return $this->setParam("max_edits", (int) $max); } /** * The number of minimum prefix characters that must match in order to be a suggestion candidate - * @param int $length Defaults to 1. + * @param int $length Defaults to 1. * @return \Elastica\Suggest\Term */ public function setPrefixLength($length) { - return $this->setParam("prefix_len", (int)$length); + return $this->setParam("prefix_len", (int) $length); } /** * The minimum length a suggest text term must have in order to be included. - * @param int $length Defaults to 4. + * @param int $length Defaults to 4. * @return \Elastica\Suggest\Term */ public function setMinWordLength($length) { - return $this->setParam("min_word_len", (int)$length); + return $this->setParam("min_word_len", (int) $length); } /** - * @param int $max Defaults to 5. + * @param int $max Defaults to 5. * @return \Elastica\Suggest\Term */ public function setMaxInspections($max) @@ -95,7 +94,7 @@ public function setMaxInspections($max) /** * Set the minimum number of documents in which a suggestion should appear - * @param int|float $min Defaults to 0. If the value is greater than 1, it must be a whole number. + * @param int|float $min Defaults to 0. If the value is greater than 1, it must be a whole number. * @return \Elastica\Suggest\Term */ public function setMinDocFrequency($min) @@ -105,11 +104,11 @@ public function setMinDocFrequency($min) /** * Set the maximum number of documents in which a suggest text token can exist in order to be included - * @param float $max + * @param float $max * @return \Elastica\Suggest\Term */ public function setMaxTermFrequency($max) { return $this->setParam("max_term_freq", $max); } -} \ No newline at end of file +} diff --git a/lib/Elastica/Transport/AbstractTransport.php b/lib/Elastica/Transport/AbstractTransport.php index d2ce0fb20f..9c389a0691 100644 --- a/lib/Elastica/Transport/AbstractTransport.php +++ b/lib/Elastica/Transport/AbstractTransport.php @@ -53,7 +53,7 @@ public function setConnection(Connection $connection) * Executes the transport request * * @param \Elastica\Request $request Request object - * @param array $params Hostname, port, path, ... + * @param array $params Hostname, port, path, ... * @return \Elastica\Response Response object */ abstract public function exec(Request $request, array $params); @@ -68,9 +68,9 @@ abstract public function exec(Request $request, array $params); * * array: An array with a "type" key which must be set to one of the two options. All other * keys in the array will be set as parameters in the transport instance * - * @param mixed $transport A transport definition - * @param \Elastica\Connection $connection A connection instance - * @param array $params Parameters for the transport class + * @param mixed $transport A transport definition + * @param \Elastica\Connection $connection A connection instance + * @param array $params Parameters for the transport class * @throws \Elastica\Exception\InvalidException * @return AbstractTransport */ @@ -85,13 +85,13 @@ public static function create($transport, Connection $connection, array $params } if (is_string($transport)) { - $className = 'Elastica\\Transport\\' . $transport; + $className = 'Elastica\\Transport\\'.$transport; if (!class_exists($className)) { throw new InvalidException('Invalid transport'); } - $transport = new $className; + $transport = new $className(); } if ($transport instanceof AbstractTransport) { diff --git a/lib/Elastica/Transport/Guzzle.php b/lib/Elastica/Transport/Guzzle.php index 96ad897140..554384c25a 100644 --- a/lib/Elastica/Transport/Guzzle.php +++ b/lib/Elastica/Transport/Guzzle.php @@ -6,7 +6,6 @@ use Elastica\Exception\Connection\GuzzleException; use Elastica\Exception\PartialShardFailureException; use Elastica\Exception\ResponseException; -use Elastica\Exception\InvalidException; use Elastica\Connection; use Elastica\Request; use Elastica\Response; @@ -43,12 +42,12 @@ class Guzzle extends AbstractTransport * * All calls that are made to the server are done through this function * - * @param \Elastica\Request $request - * @param array $params Host, Port, ... + * @param \Elastica\Request $request + * @param array $params Host, Port, ... * @throws \Elastica\Exception\ConnectionException * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\Connection\HttpException - * @return \Elastica\Response Response object + * @return \Elastica\Response Response object */ public function exec(Request $request, array $params) { @@ -71,7 +70,6 @@ public function exec(Request $request, array $params) $data = $request->getData(); if (!empty($data) || '0' === $data) { - if ($req->getMethod() == Request::GET) { $req->setMethod(Request::POST); } @@ -93,7 +91,7 @@ public function exec(Request $request, array $params) $res = $client->send($req); $end = microtime(true); - $response = new Response((string)$res->getBody(), $res->getStatusCode()); + $response = new Response((string) $res->getBody(), $res->getStatusCode()); if (defined('DEBUG') && DEBUG) { $response->setQueryTime($end - $start); @@ -102,7 +100,7 @@ public function exec(Request $request, array $params) $response->setTransferInfo( array( 'request_header' => $request->getMethod(), - 'http_code' => $res->getStatusCode() + 'http_code' => $res->getStatusCode(), ) ); @@ -115,19 +113,17 @@ public function exec(Request $request, array $params) } return $response; - } catch (ClientException $e) { // ignore 4xx errors } catch (TransferException $e) { throw new GuzzleException($e, $request, new Response($e->getMessage())); } - } /** * Return Guzzle resource * - * @param bool $persistent False if not persistent connection + * @param bool $persistent False if not persistent connection * @return resource Connection resource */ protected function _getGuzzleClient($baseUrl, $persistent = true) @@ -142,7 +138,7 @@ protected function _getGuzzleClient($baseUrl, $persistent = true) /** * Builds the base url for the guzzle connection * - * @param \Elastica\Connection $connection + * @param \Elastica\Connection $connection */ protected function _getBaseUrl(Connection $connection) { @@ -152,26 +148,27 @@ protected function _getBaseUrl(Connection $connection) if (!empty($url)) { $baseUri = $url; } else { - $baseUri = $this->_scheme . '://' . $connection->getHost() . ':' . $connection->getPort() . '/' . $connection->getPath(); + $baseUri = $this->_scheme.'://'.$connection->getHost().':'.$connection->getPort().'/'.$connection->getPath(); } + return rtrim($baseUri, '/'); } /** * Builds the action path url for each request * - * @param \Elastica\Request $request + * @param \Elastica\Request $request */ protected function _getActionPath(Request $request) { $action = $request->getPath(); if ($action) { - $action = '/'. ltrim($action, '/'); + $action = '/'.ltrim($action, '/'); } $query = $request->getQuery(); if (!empty($query)) { - $action .= '?' . http_build_query($query); + $action .= '?'.http_build_query($query); } return $action; diff --git a/lib/Elastica/Transport/Http.php b/lib/Elastica/Transport/Http.php index 5606dbbc70..4a86d9b3c1 100644 --- a/lib/Elastica/Transport/Http.php +++ b/lib/Elastica/Transport/Http.php @@ -37,12 +37,12 @@ class Http extends AbstractTransport * * All calls that are made to the server are done through this function * - * @param \Elastica\Request $request - * @param array $params Host, Port, ... + * @param \Elastica\Request $request + * @param array $params Host, Port, ... * @throws \Elastica\Exception\ConnectionException * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\Connection\HttpException - * @return \Elastica\Response Response object + * @return \Elastica\Response Response object */ public function exec(Request $request, array $params) { @@ -56,7 +56,7 @@ public function exec(Request $request, array $params) if (!empty($url)) { $baseUri = $url; } else { - $baseUri = $this->_scheme . '://' . $connection->getHost() . ':' . $connection->getPort() . '/' . $connection->getPath(); + $baseUri = $this->_scheme.'://'.$connection->getHost().':'.$connection->getPort().'/'.$connection->getPath(); } $baseUri .= $request->getPath(); @@ -64,7 +64,7 @@ public function exec(Request $request, array $params) $query = $request->getQuery(); if (!empty($query)) { - $baseUri .= '?' . http_build_query($query); + $baseUri .= '?'.http_build_query($query); } curl_setopt($conn, CURLOPT_URL, $baseUri); @@ -83,7 +83,7 @@ public function exec(Request $request, array $params) if (!empty($headersConfig)) { $headers = array(); while (list($header, $headerValue) = each($headersConfig)) { - array_push($headers, $header . ': ' . $headerValue); + array_push($headers, $header.': '.$headerValue); } curl_setopt($conn, CURLOPT_HTTPHEADER, $headers); @@ -141,7 +141,6 @@ public function exec(Request $request, array $params) $response->setTransferInfo(curl_getinfo($conn)); - if ($response->hasError()) { throw new ResponseException($request, $response); } @@ -174,7 +173,7 @@ protected function _setupCurl($curlConnection) /** * Return Curl resource * - * @param bool $persistent False if not persistent connection + * @param bool $persistent False if not persistent connection * @return resource Connection resource */ protected function _getConnection($persistent = true) diff --git a/lib/Elastica/Transport/HttpAdapter.php b/lib/Elastica/Transport/HttpAdapter.php index 17e137507f..add3596912 100644 --- a/lib/Elastica/Transport/HttpAdapter.php +++ b/lib/Elastica/Transport/HttpAdapter.php @@ -8,7 +8,6 @@ use Elastica\JSON; use Elastica\Request as ElasticaRequest; use Elastica\Response as ElasticaResponse; -use Elastica\Transport\AbstractTransport; use Ivory\HttpAdapter\HttpAdapterInterface; use Ivory\HttpAdapter\Message\Stream\StringStream; use Ivory\HttpAdapter\Message\Request as HttpAdapterRequest; @@ -41,12 +40,12 @@ public function __construct(Connection $connection = null, HttpAdapterInterface * * All calls that are made to the server are done through this function * - * @param \Elastica\Request $elasticaRequest - * @param array $params Host, Port, ... + * @param \Elastica\Request $elasticaRequest + * @param array $params Host, Port, ... * @throws \Elastica\Exception\ConnectionException * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\Connection\HttpException - * @return \Elastica\Response Response object + * @return \Elastica\Response Response object */ public function exec(ElasticaRequest $elasticaRequest, array $params) { @@ -93,12 +92,12 @@ public function exec(ElasticaRequest $elasticaRequest, array $params) */ protected function _createElasticaResponse(HttpAdapterResponse $httpAdapterResponse) { - return new ElasticaResponse((string)$httpAdapterResponse->getBody(), $httpAdapterResponse->getStatusCode()); + return new ElasticaResponse((string) $httpAdapterResponse->getBody(), $httpAdapterResponse->getStatusCode()); } /** * @param ElasticaRequest $elasticaRequest - * @param Connection $connection + * @param Connection $connection * * @return HttpAdapterRequest */ @@ -109,7 +108,6 @@ protected function _createHttpAdapterRequest(ElasticaRequest $elasticaRequest, C $method = $elasticaRequest->getMethod(); $headers = $connection->hasConfig('headers') ?: array(); if (!empty($data) || '0' === $data) { - if ($method == ElasticaRequest::GET) { $method = ElasticaRequest::POST; } @@ -133,7 +131,7 @@ protected function _createHttpAdapterRequest(ElasticaRequest $elasticaRequest, C } /** - * @param ElasticaRequest $request + * @param ElasticaRequest $request * @param \Elastica\Connection $connection * * @return string @@ -145,7 +143,7 @@ protected function _getUri(ElasticaRequest $request, Connection $connection) if (!empty($url)) { $baseUri = $url; } else { - $baseUri = $this->_scheme . '://' . $connection->getHost() . ':' . $connection->getPort() . '/' . $connection->getPath(); + $baseUri = $this->_scheme.'://'.$connection->getHost().':'.$connection->getPort().'/'.$connection->getPath(); } $baseUri .= $request->getPath(); @@ -153,7 +151,7 @@ protected function _getUri(ElasticaRequest $request, Connection $connection) $query = $request->getQuery(); if (!empty($query)) { - $baseUri .= '?' . http_build_query($query); + $baseUri .= '?'.http_build_query($query); } return $baseUri; diff --git a/lib/Elastica/Transport/Memcache.php b/lib/Elastica/Transport/Memcache.php index cf047b583d..044b2e7492 100644 --- a/lib/Elastica/Transport/Memcache.php +++ b/lib/Elastica/Transport/Memcache.php @@ -21,11 +21,11 @@ class Memcache extends AbstractTransport /** * Makes calls to the elasticsearch server * - * @param \Elastica\Request $request - * @param array $params Host, Port, ... + * @param \Elastica\Request $request + * @param array $params Host, Port, ... * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\InvalidException - * @return \Elastica\Response Response object + * @return \Elastica\Response Response object */ public function exec(Request $request, array $params) { @@ -58,12 +58,12 @@ public function exec(Request $request, array $params) $memcache->set($request->getPath(), $content); break; case 'get': - $responseString = $memcache->get($request->getPath() . '?source=' . $content); + $responseString = $memcache->get($request->getPath().'?source='.$content); break; case 'delete': break; default: - throw new InvalidException('Method ' . $function . ' is not supported in memcache transport'); + throw new InvalidException('Method '.$function.' is not supported in memcache transport'); } diff --git a/lib/Elastica/Transport/Null.php b/lib/Elastica/Transport/Null.php index 704e0e12b4..6dfe1885db 100644 --- a/lib/Elastica/Transport/Null.php +++ b/lib/Elastica/Transport/Null.php @@ -17,28 +17,28 @@ class Null extends AbstractTransport /** * Null transport. * - * @param \Elastica\Request $request - * @param array $params Hostname, port, path, ... + * @param \Elastica\Request $request + * @param array $params Hostname, port, path, ... * @return \Elastica\Response Response empty object */ public function exec(Request $request, array $params) { $response = array( "took" => 0, - "timed_out" => FALSE, + "timed_out" => false, "_shards" => array( "total" => 0, "successful" => 0, - "failed" => 0 + "failed" => 0, ), "hits" => array( "total" => 0, - "max_score" => NULL, - "hits" => array() + "max_score" => null, + "hits" => array(), ), - "params" => $params + "params" => $params, ); - return new Response(JSON::stringify($response)); + return new Response(JSON::stringify($response)); } } diff --git a/lib/Elastica/Transport/Thrift.php b/lib/Elastica/Transport/Thrift.php index f58c51a22f..61f4ec5917 100644 --- a/lib/Elastica/Transport/Thrift.php +++ b/lib/Elastica/Transport/Thrift.php @@ -37,7 +37,7 @@ class Thrift extends AbstractTransport /** * Construct transport * - * @param \Elastica\Connection $connection Connection object + * @param \Elastica\Connection $connection Connection object * @throws \Elastica\Exception\RuntimeException */ public function __construct(Connection $connection = null) @@ -49,11 +49,11 @@ public function __construct(Connection $connection = null) } /** - * @param string $host - * @param int $port - * @param int $sendTimeout msec - * @param int $recvTimeout msec - * @param bool $framedTransport + * @param string $host + * @param int $port + * @param int $sendTimeout msec + * @param int $recvTimeout msec + * @param bool $framedTransport * @return \Elasticsearch\RestClient */ protected function _createClient($host, $port, $sendTimeout = null, $recvTimeout = null, $framedTransport = false) @@ -83,30 +83,31 @@ protected function _createClient($host, $port, $sendTimeout = null, $recvTimeout } /** - * @param string $host - * @param int $port - * @param int $sendTimeout - * @param int $recvTimeout - * @param bool $framedTransport + * @param string $host + * @param int $port + * @param int $sendTimeout + * @param int $recvTimeout + * @param bool $framedTransport * @return \Elasticsearch\RestClient */ protected function _getClient($host, $port, $sendTimeout = null, $recvTimeout = null, $framedTransport = false) { - $key = $host . ':' . $port; + $key = $host.':'.$port; if (!isset($this->_clients[$key])) { $this->_clients[$key] = $this->_createClient($host, $port, $sendTimeout, $recvTimeout, $framedTransport); } + return $this->_clients[$key]; } /** * Makes calls to the elasticsearch server * - * @param \Elastica\Request $request - * @param array $params Host, Port, ... + * @param \Elastica\Request $request + * @param array $params Host, Port, ... * @throws \Elastica\Exception\Connection\ThriftException * @throws \Elastica\Exception\ResponseException - * @return \Elastica\Response Response object + * @return \Elastica\Response Response object */ public function exec(Request $request, array $params) { diff --git a/lib/Elastica/Type.php b/lib/Elastica/Type.php index 8e5825db1d..599c85b0e7 100644 --- a/lib/Elastica/Type.php +++ b/lib/Elastica/Type.php @@ -2,7 +2,6 @@ namespace Elastica; -use Elastica\Document; use Elastica\Exception\RuntimeException; use Elastica\Exception\InvalidException; use Elastica\Exception\NotFoundException; @@ -45,7 +44,7 @@ class Type implements SearchableInterface * Creates a new type object inside the given index * * @param \Elastica\Index $index Index Object - * @param string $name Type name + * @param string $name Type name */ public function __construct(Index $index, $name) { @@ -110,7 +109,7 @@ public function addDocument(Document $doc) /** * @param $object - * @param Document $doc + * @param Document $doc * @return Response * @throws Exception\RuntimeException */ @@ -132,8 +131,8 @@ public function addObject($object, Document $doc = null) /** * Update document, using update script. Requires elasticsearch >= 0.19.0 * - * @param \Elastica\Document|\Elastica\Script $data Document with update data - * @param array $options array of query params to use for query. For possible options check es api + * @param \Elastica\Document|\Elastica\Script $data Document with update data + * @param array $options array of query params to use for query. For possible options check es api * @throws \Elastica\Exception\InvalidException * @return \Elastica\Response * @link http://www.elasticsearch.org/guide/reference/api/update.html @@ -194,7 +193,7 @@ public function addDocuments(array $docs) /** * Uses _bulk to send documents to the server * - * @param objects[] $objects + * @param objects[] $objects * @return \Elastica\Bulk\ResponseSet * @link http://www.elasticsearch.org/guide/reference/api/bulk.html */ @@ -219,8 +218,8 @@ public function addObjects(array $objects) /** * Get the document from search index * - * @param string $id Document id - * @param array $options Options for the get request. + * @param string $id Document id + * @param array $options Options for the get request. * @throws \Elastica\Exception\NotFoundException * @throws \Elastica\Exception\ResponseException * @return \Elastica\Document @@ -233,7 +232,7 @@ public function getDocument($id, $options = array()) $result = $response->getData(); if (!isset($result['found']) || $result['found'] === false) { - throw new NotFoundException('doc id ' . $id . ' not found'); + throw new NotFoundException('doc id '.$id.' not found'); } if (isset($result['fields'])) { @@ -251,8 +250,8 @@ public function getDocument($id, $options = array()) } /** - * @param string $id - * @param array|string $data + * @param string $id + * @param array|string $data * @return Document */ public function createDocument($id = '', $data = array()) @@ -310,8 +309,8 @@ public function getMapping() /** * Create search object * - * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object - * @param int|array $options OPTIONAL Limit or associative array of options (option=>value) + * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object + * @param int|array $options OPTIONAL Limit or associative array of options (option=>value) * @return \Elastica\Search */ public function createSearch($query = '', $options = null) @@ -327,8 +326,8 @@ public function createSearch($query = '', $options = null) /** * Do a search on this type * - * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object - * @param int|array $options OPTIONAL Limit or associative array of options (option=>value) + * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object + * @param int|array $options OPTIONAL Limit or associative array of options (option=>value) * @return \Elastica\ResultSet ResultSet with all results inside * @see \Elastica\SearchableInterface::search */ @@ -343,7 +342,7 @@ public function search($query = '', $options = null) * Count docs by query * * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object - * @return int number of documents matching the query + * @return int number of documents matching the query * @see \Elastica\SearchableInterface::count */ public function count($query = '') @@ -364,7 +363,7 @@ public function getIndex() } /** - * @param \Elastica\Document $document + * @param \Elastica\Document $document * @return \Elastica\Response */ public function deleteDocument(Document $document) @@ -378,9 +377,10 @@ public function deleteDocument(Document $document) 'replication', 'consistency', 'refresh', - 'timeout' + 'timeout', ) ); + return $this->deleteById($document->getId(), $options); } @@ -403,11 +403,11 @@ public function deleteDocuments(array $docs) /** * Deletes an entry by its unique identifier * - * @param int|string $id Document id - * @param array $options + * @param int|string $id Document id + * @param array $options * @throws \InvalidArgumentException * @throws \Elastica\Exception\NotFoundException - * @return \Elastica\Response Response object + * @return \Elastica\Response Response object * @link http://www.elasticsearch.org/guide/reference/api/delete.html */ public function deleteById($id, array $options = array()) @@ -423,7 +423,7 @@ public function deleteById($id, array $options = array()) $responseData = $response->getData(); if (isset($responseData['found']) && false == $responseData['found']) { - throw new NotFoundException('Doc id ' . $id . ' not found and can not be deleted'); + throw new NotFoundException('Doc id '.$id.' not found and can not be deleted'); } return $response; @@ -433,7 +433,7 @@ public function deleteById($id, array $options = array()) * Deletes the given list of ids from this type * * @param array $ids - * @param string|false $routing Optional routing key for all ids + * @param string|false $routing Optional routing key for all ids * @return \Elastica\Response Response object */ public function deleteIds(array $ids, $routing = false) @@ -454,6 +454,7 @@ public function deleteByQuery($query, array $options = array()) if (is_string($query)) { // query_string queries are not supported for delete by query operations $options['q'] = $query; + return $this->request('_query', Request::DELETE, array(), $options); } $query = Query::create($query); @@ -478,15 +479,15 @@ public function delete() * * The id in the given object has to be set * - * @param \Elastica\Document $doc Document to query for similar objects - * @param array $params OPTIONAL Additional arguments for the query - * @param string|array|\Elastica\Query $query OPTIONAL Query to filter the moreLikeThis results + * @param \Elastica\Document $doc Document to query for similar objects + * @param array $params OPTIONAL Additional arguments for the query + * @param string|array|\Elastica\Query $query OPTIONAL Query to filter the moreLikeThis results * @return \Elastica\ResultSet ResultSet with all results inside * @link http://www.elasticsearch.org/guide/reference/api/more-like-this.html */ public function moreLikeThis(Document $doc, $params = array(), $query = array()) { - $path = $doc->getId() . '/_mlt'; + $path = $doc->getId().'/_mlt'; $query = Query::create($query); @@ -498,15 +499,15 @@ public function moreLikeThis(Document $doc, $params = array(), $query = array()) /** * Makes calls to the elasticsearch server based on this type * - * @param string $path Path to call - * @param string $method Rest method to use (GET, POST, DELETE, PUT) - * @param array $data OPTIONAL Arguments as array - * @param array $query OPTIONAL Query params + * @param string $path Path to call + * @param string $method Rest method to use (GET, POST, DELETE, PUT) + * @param array $data OPTIONAL Arguments as array + * @param array $query OPTIONAL Query params * @return \Elastica\Response Response object */ public function request($path, $method, $data = array(), array $query = array()) { - $path = $this->getName() . '/' . $path; + $path = $this->getName().'/'.$path; return $this->getIndex()->request($path, $method, $data, $query); } @@ -532,6 +533,6 @@ public function exists() $response = $this->getIndex()->request($this->getName(), Request::HEAD); $info = $response->getTransferInfo(); - return (bool)($info['http_code'] == 200); + return (bool) ($info['http_code'] == 200); } } diff --git a/lib/Elastica/Type/AbstractType.php b/lib/Elastica/Type/AbstractType.php index ba2e0430d2..241207f597 100644 --- a/lib/Elastica/Type/AbstractType.php +++ b/lib/Elastica/Type/AbstractType.php @@ -132,8 +132,8 @@ public function create($recreate = false) } /** - * @param \Elastica\Query $query - * @param array|int $options + * @param \Elastica\Query $query + * @param array|int $options * @return \Elastica\Search */ public function createSearch($query = '', $options = null) @@ -157,7 +157,7 @@ public function search($query = '', $options = null) * Count docs in the type based on query * * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object - * @return int number of documents matching the query + * @return int number of documents matching the query * @see \Elastica\SearchableInterface::count */ public function count($query = '') diff --git a/lib/Elastica/Type/Mapping.php b/lib/Elastica/Type/Mapping.php index 920093fb69..b8079ace4c 100644 --- a/lib/Elastica/Type/Mapping.php +++ b/lib/Elastica/Type/Mapping.php @@ -34,7 +34,7 @@ class Mapping * Construct Mapping * * @param \Elastica\Type $type OPTIONAL Type object - * @param array $properties OPTIONAL Properties + * @param array $properties OPTIONAL Properties */ public function __construct(Type $type = null, array $properties = array()) { @@ -50,7 +50,7 @@ public function __construct(Type $type = null, array $properties = array()) /** * Sets the mapping type * Enter description here ... - * @param \Elastica\Type $type Type object + * @param \Elastica\Type $type Type object * @return \Elastica\Type\Mapping Current object */ public function setType(Type $type) @@ -63,7 +63,7 @@ public function setType(Type $type) /** * Sets the mapping properties * - * @param array $properties Properties + * @param array $properties Properties * @return \Elastica\Type\Mapping Mapping object */ public function setProperties(array $properties) @@ -74,7 +74,7 @@ public function setProperties(array $properties) /** * Gets the mapping properties * - * @return array $properties Properties + * @return array $properties Properties */ public function getProperties() { @@ -83,7 +83,7 @@ public function getProperties() /** * Sets the mapping _meta - * @param array $meta metadata + * @param array $meta metadata * @return \Elastica\Type\Mapping Mapping object * @link http://www.elasticsearch.org/guide/reference/mapping/meta.html */ @@ -108,7 +108,7 @@ public function getType() * To disable source, argument is * array('enabled' => false) * - * @param array $source Source array + * @param array $source Source array * @return \Elastica\Type\Mapping Current object * @link http://www.elasticsearch.org/guide/reference/mapping/source-field.html */ @@ -122,7 +122,7 @@ public function setSource(array $source) * * Param can be set to true to enable again * - * @param bool $enabled OPTIONAL (default = false) + * @param bool $enabled OPTIONAL (default = false) * @return \Elastica\Type\Mapping Current object */ public function disableSource($enabled = false) @@ -147,8 +147,8 @@ public function disableSource($enabled = false) * _size * properties * - * @param string $key Key name - * @param mixed $value Key value + * @param string $key Key name + * @param mixed $value Key value * @return \Elastica\Type\Mapping Current object */ public function setParam($key, $value) @@ -162,18 +162,18 @@ public function setParam($key, $value) * Get raw parameters * * @see setParam - * @param string $key Key name - * @return mixed $value Key value + * @param string $key Key name + * @return mixed $value Key value */ public function getParam($key) { - return isset($this->_mapping[$key])?$this->_mapping[$key]:null; + return isset($this->_mapping[$key]) ? $this->_mapping[$key] : null; } /** * Sets params for the "_all" field * - * @param array $params _all Params (enabled, store, term_vector, analyzer) + * @param array $params _all Params (enabled, store, term_vector, analyzer) * @return \Elastica\Type\Mapping */ public function setAllField(array $params) @@ -184,7 +184,7 @@ public function setAllField(array $params) /** * Enables the "_all" field * - * @param bool $enabled OPTIONAL (default = true) + * @param bool $enabled OPTIONAL (default = true) * @return \Elastica\Type\Mapping */ public function enableAllField($enabled = true) @@ -195,19 +195,18 @@ public function enableAllField($enabled = true) /** * Set TTL * - * @param array $params TTL Params (enabled, default, ...) + * @param array $params TTL Params (enabled, default, ...) * @return \Elastica\Type\Mapping */ public function setTtl(array $params) { return $this->setParam('_ttl', $params); - } /** * Enables TTL for all documents in this type * - * @param bool $enabled OPTIONAL (default = true) + * @param bool $enabled OPTIONAL (default = true) * @return \Elastica\Type\Mapping */ public function enableTtl($enabled = true) @@ -218,7 +217,7 @@ public function enableTtl($enabled = true) /** * Set parent type * - * @param string $type Parent type + * @param string $type Parent type * @return \Elastica\Type\Mapping */ public function setParent($type) @@ -230,7 +229,7 @@ public function setParent($type) * Converts the mapping to an array * * @throws \Elastica\Exception\InvalidException - * @return array Mapping as array + * @return array Mapping as array */ public function toArray() { @@ -258,8 +257,8 @@ public function send() /** * Creates a mapping object * - * @param array|\Elastica\Type\Mapping $mapping Mapping object or properties array - * @return \Elastica\Type\Mapping Mapping object + * @param array|\Elastica\Type\Mapping $mapping Mapping object or properties array + * @return \Elastica\Type\Mapping Mapping object * @throws \Elastica\Exception\InvalidException If invalid type */ public static function create($mapping) diff --git a/lib/Elastica/Util.php b/lib/Elastica/Util.php index 4b3cee0da0..75c11fc264 100644 --- a/lib/Elastica/Util.php +++ b/lib/Elastica/Util.php @@ -2,7 +2,6 @@ namespace Elastica; -use Elastica\JSON; /** * Elastica tools @@ -49,7 +48,7 @@ public static function escapeTerm($term) $chars = array('\\', '+', '-', '&&', '||', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~', '*', '?', ':', '/'); foreach ($chars as $char) { - $result = str_replace($char, '\\' . $char, $result); + $result = str_replace($char, '\\'.$char, $result); } return $result; @@ -65,7 +64,7 @@ public static function escapeTerm($term) */ public static function replaceBooleanWords($term) { - $replacementMap = array(' AND '=>' && ', ' OR '=>' || ', ' NOT '=>' !'); + $replacementMap = array(' AND ' => ' && ', ' OR ' => ' || ', ' NOT ' => ' !'); $result = strtr($term, $replacementMap); return $result; @@ -96,7 +95,7 @@ public static function toSnakeCase($string) { $string = preg_replace('/([A-Z])/', '_$1', $string); - return strtolower(substr($string,1)); + return strtolower(substr($string, 1)); } /** @@ -124,13 +123,13 @@ public static function convertDate($date) * * Converts it to the lucene format, including the appropriate TimeZone * - * @param \DateTime $dateTime - * @param boolean $includeTimezone + * @param \DateTime $dateTime + * @param boolean $includeTimezone * @return string */ public static function convertDateTimeObject(\DateTime $dateTime, $includeTimezone = true) { - $formatString = 'Y-m-d\TH:i:s' . ($includeTimezone === true ? 'P' : '\Z'); + $formatString = 'Y-m-d\TH:i:s'.($includeTimezone === true ? 'P' : '\Z'); $string = $dateTime->format($formatString); return $string; @@ -160,26 +159,27 @@ public static function getParamName($class) /** * Converts Request to Curl console command * - * @param Request $request + * @param Request $request * @return string */ public static function convertRequestToCurlCommand(Request $request) { - $message = 'curl -X' . strtoupper($request->getMethod()) . ' '; - $message .= '\'http://' . $request->getConnection()->getHost() . ':' . $request->getConnection()->getPort() . '/'; + $message = 'curl -X'.strtoupper($request->getMethod()).' '; + $message .= '\'http://'.$request->getConnection()->getHost().':'.$request->getConnection()->getPort().'/'; $message .= $request->getPath(); $query = $request->getQuery(); if (!empty($query)) { - $message .= '?' . http_build_query($query); + $message .= '?'.http_build_query($query); } $message .= '\''; $data = $request->getData(); if (!empty($data)) { - $message .= ' -d \'' . JSON::stringify($data) . '\''; + $message .= ' -d \''.JSON::stringify($data).'\''; } + return $message; } }