From 0d32a397887badcd8340eb5711dd1046e3e0d40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20de=20Guillebon?= Date: Tue, 19 Nov 2019 14:54:05 +0100 Subject: [PATCH] Fix CS bis (#1706) --- .php_cs.dist | 2 + CHANGELOG.md | 1 + lib/Elastica/AbstractUpdateAction.php | 2 +- .../Aggregation/AbstractAggregation.php | 2 +- .../Aggregation/AbstractTermsAggregation.php | 4 +- lib/Elastica/Aggregation/AvgBucket.php | 4 +- lib/Elastica/Aggregation/BucketScript.php | 4 +- lib/Elastica/Aggregation/BucketSelector.php | 8 +-- lib/Elastica/Aggregation/Derivative.php | 8 +-- lib/Elastica/Aggregation/Filter.php | 7 +- lib/Elastica/Aggregation/Filters.php | 4 +- lib/Elastica/Aggregation/GeoDistance.php | 2 +- lib/Elastica/Aggregation/IpRange.php | 2 +- lib/Elastica/Aggregation/Percentiles.php | 2 +- lib/Elastica/Aggregation/Range.php | 4 +- lib/Elastica/Aggregation/ReverseNested.php | 4 +- lib/Elastica/Aggregation/ScriptedMetric.php | 8 +-- lib/Elastica/Aggregation/SerialDiff.php | 6 +- lib/Elastica/Aggregation/StatsBucket.php | 2 +- lib/Elastica/Aggregation/SumBucket.php | 2 +- lib/Elastica/Bulk.php | 15 ++-- lib/Elastica/Bulk/Action.php | 2 +- lib/Elastica/Bulk/Action/AbstractDocument.php | 2 +- lib/Elastica/Client.php | 70 +++++-------------- lib/Elastica/Connection/ConnectionPool.php | 9 +-- lib/Elastica/Document.php | 2 +- .../Exception/Connection/GuzzleException.php | 5 +- .../Exception/Connection/HttpException.php | 2 +- .../Exception/ConnectionException.php | 2 +- lib/Elastica/Index.php | 2 +- lib/Elastica/Multi/Search.php | 8 +-- lib/Elastica/Query/AbstractGeoDistance.php | 1 - lib/Elastica/Query/BoolQuery.php | 2 - lib/Elastica/Query/ConstantScore.php | 2 +- lib/Elastica/Query/FunctionScore.php | 36 +++++----- lib/Elastica/Query/Fuzzy.php | 11 ++- lib/Elastica/Query/GeoBoundingBox.php | 6 +- lib/Elastica/Query/HasChild.php | 4 +- lib/Elastica/Query/Match.php | 2 +- lib/Elastica/Query/MatchPhrase.php | 2 +- lib/Elastica/Query/Range.php | 2 +- lib/Elastica/Query/Regexp.php | 4 +- lib/Elastica/Query/SpanContaining.php | 2 +- lib/Elastica/Query/SpanFirst.php | 2 +- lib/Elastica/Query/SpanNot.php | 2 +- lib/Elastica/Query/SpanWithin.php | 2 +- lib/Elastica/Query/Wildcard.php | 2 +- lib/Elastica/QueryBuilder.php | 2 +- lib/Elastica/QueryBuilder/DSL/Aggregation.php | 22 +++--- lib/Elastica/QueryBuilder/DSL/Query.php | 45 +++++------- lib/Elastica/Request.php | 53 +++++--------- lib/Elastica/ResultSet.php | 2 +- lib/Elastica/Script/AbstractScript.php | 2 +- lib/Elastica/Script/Script.php | 7 +- lib/Elastica/Script/ScriptId.php | 3 +- lib/Elastica/Scroll.php | 18 ++--- lib/Elastica/Search.php | 11 +-- lib/Elastica/Suggest.php | 2 +- lib/Elastica/Suggest/AbstractSuggest.php | 16 ++--- lib/Elastica/Transport/AbstractTransport.php | 11 +-- lib/Elastica/Transport/HttpAdapter.php | 6 +- lib/Elastica/Util.php | 4 +- test/Elastica/Base.php | 20 ++---- test/Elastica/BasePipeline.php | 6 +- test/Elastica/ErrorsCollector.php | 2 +- test/Elastica/Multi/SearchTest.php | 2 +- 66 files changed, 186 insertions(+), 327 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index 08eb2b6ee4..e813e0306f 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -19,6 +19,8 @@ $config = PhpCsFixer\Config::create() '@PHPUnit60Migration:risky' => true, 'php_unit_dedicate_assert' => ['target' => 'newest'], 'native_function_invocation' => true, + 'no_alias_functions' => true, + 'nullable_type_declaration_for_default_null_value' => true, ]) ; diff --git a/CHANGELOG.md b/CHANGELOG.md index ab509c3093..c55a52ef81 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file based on the ### Improvements * Launch tests with PHP 7.4 +* Added `nullable_type_declaration_for_default_null_value`, `no_alias_functions` CS rules [#1706](https://github.com/ruflin/Elastica/pull/1706) ### Deprecated diff --git a/lib/Elastica/AbstractUpdateAction.php b/lib/Elastica/AbstractUpdateAction.php index c87a77a9a4..0b3f83d217 100644 --- a/lib/Elastica/AbstractUpdateAction.php +++ b/lib/Elastica/AbstractUpdateAction.php @@ -18,7 +18,7 @@ class AbstractUpdateAction extends Param /** * Sets the id of the document. */ - public function setId(string $id = null): self + public function setId(?string $id = null): self { return $this->setParam('_id', $id); } diff --git a/lib/Elastica/Aggregation/AbstractAggregation.php b/lib/Elastica/Aggregation/AbstractAggregation.php index 5d9c43a467..c80fc589ad 100644 --- a/lib/Elastica/Aggregation/AbstractAggregation.php +++ b/lib/Elastica/Aggregation/AbstractAggregation.php @@ -132,7 +132,7 @@ public function toArray(): array // compensate for class name GlobalAggregation $array = ['global' => new \stdClass()]; } - if (\sizeof($this->_aggs)) { + if (\count($this->_aggs)) { $array['aggs'] = $this->_convertArrayable($this->_aggs); } diff --git a/lib/Elastica/Aggregation/AbstractTermsAggregation.php b/lib/Elastica/Aggregation/AbstractTermsAggregation.php index e4f9739145..16761f8bef 100644 --- a/lib/Elastica/Aggregation/AbstractTermsAggregation.php +++ b/lib/Elastica/Aggregation/AbstractTermsAggregation.php @@ -25,7 +25,7 @@ public function setMinimumDocumentCount(int $count): self * * @return $this */ - public function setInclude(string $pattern, string $flags = null): self + public function setInclude(string $pattern, ?string $flags = null): self { if (null === $flags) { return $this->setParam('include', $pattern); @@ -45,7 +45,7 @@ public function setInclude(string $pattern, string $flags = null): self * * @return $this */ - public function setExclude(string $pattern, string $flags = null): self + public function setExclude(string $pattern, ?string $flags = null): self { if (null === $flags) { return $this->setParam('exclude', $pattern); diff --git a/lib/Elastica/Aggregation/AvgBucket.php b/lib/Elastica/Aggregation/AvgBucket.php index 7f1a447751..3f8b25df4a 100644 --- a/lib/Elastica/Aggregation/AvgBucket.php +++ b/lib/Elastica/Aggregation/AvgBucket.php @@ -14,7 +14,7 @@ class AvgBucket extends AbstractAggregation const DEFAULT_GAP_POLICY_VALUE = 'skip'; const DEFAULT_FORMAT_VALUE = null; - public function __construct(string $name, string $bucketsPath = null) + public function __construct(string $name, ?string $bucketsPath = null) { parent::__construct($name); @@ -48,7 +48,7 @@ public function setGapPolicy(string $gapPolicy): self * * @return $this */ - public function setFormat(string $format = null): self + public function setFormat(?string $format = null): self { return $this->setParam('format', $format); } diff --git a/lib/Elastica/Aggregation/BucketScript.php b/lib/Elastica/Aggregation/BucketScript.php index 0a65303e7d..568809d0c4 100644 --- a/lib/Elastica/Aggregation/BucketScript.php +++ b/lib/Elastica/Aggregation/BucketScript.php @@ -11,7 +11,7 @@ */ class BucketScript extends AbstractAggregation { - public function __construct(string $name, array $bucketsPath = null, string $script = null) + public function __construct(string $name, ?array $bucketsPath = null, ?string $script = null) { parent::__construct($name); @@ -59,7 +59,7 @@ public function setGapPolicy(string $gapPolicy = 'skip'): self * * @return $this */ - public function setFormat(string $format = null): self + public function setFormat(?string $format = null): self { return $this->setParam('format', $format); } diff --git a/lib/Elastica/Aggregation/BucketSelector.php b/lib/Elastica/Aggregation/BucketSelector.php index 8a730bc189..5c93739c93 100644 --- a/lib/Elastica/Aggregation/BucketSelector.php +++ b/lib/Elastica/Aggregation/BucketSelector.php @@ -9,7 +9,7 @@ */ class BucketSelector extends AbstractSimpleAggregation { - public function __construct(string $name, array $bucketsPath = null, string $script = null) + public function __construct(string $name, ?array $bucketsPath = null, ?string $script = null) { parent::__construct($name); @@ -25,11 +25,9 @@ public function __construct(string $name, array $bucketsPath = null, string $scr /** * Set the buckets_path for this aggregation. * - * @param array $bucketsPath - * * @return $this */ - public function setBucketsPath($bucketsPath) + public function setBucketsPath(array $bucketsPath): self { return $this->setParam('buckets_path', $bucketsPath); } @@ -39,7 +37,7 @@ public function setBucketsPath($bucketsPath) * * @return $this */ - public function setGapPolicy(string $gapPolicy = 'skip') + public function setGapPolicy(string $gapPolicy = 'skip'): self { return $this->setParam('gap_policy', $gapPolicy); } diff --git a/lib/Elastica/Aggregation/Derivative.php b/lib/Elastica/Aggregation/Derivative.php index 6eab88a382..4d9983e5ca 100644 --- a/lib/Elastica/Aggregation/Derivative.php +++ b/lib/Elastica/Aggregation/Derivative.php @@ -11,7 +11,7 @@ */ class Derivative extends AbstractAggregation { - public function __construct(string $name, string $bucketsPath = null) + public function __construct(string $name, ?string $bucketsPath = null) { parent::__construct($name); @@ -25,7 +25,7 @@ public function __construct(string $name, string $bucketsPath = null) * * @return $this */ - public function setBucketsPath(string $bucketsPath) + public function setBucketsPath(string $bucketsPath): self { return $this->setParam('buckets_path', $bucketsPath); } @@ -35,7 +35,7 @@ public function setBucketsPath(string $bucketsPath) * * @return $this */ - public function setGapPolicy(string $gapPolicy = 'skip') + public function setGapPolicy(string $gapPolicy = 'skip'): self { return $this->setParam('gap_policy', $gapPolicy); } @@ -45,7 +45,7 @@ public function setGapPolicy(string $gapPolicy = 'skip') * * @return $this */ - public function setFormat(string $format) + public function setFormat(string $format): self { return $this->setParam('format', $format); } diff --git a/lib/Elastica/Aggregation/Filter.php b/lib/Elastica/Aggregation/Filter.php index cbbfadf325..b4767f3e2a 100644 --- a/lib/Elastica/Aggregation/Filter.php +++ b/lib/Elastica/Aggregation/Filter.php @@ -12,10 +12,7 @@ */ class Filter extends AbstractAggregation { - /** - * @param AbstractQuery $filter - */ - public function __construct(string $name, AbstractQuery $filter = null) + public function __construct(string $name, ?AbstractQuery $filter = null) { parent::__construct($name); @@ -29,7 +26,7 @@ public function __construct(string $name, AbstractQuery $filter = null) * * @return $this */ - public function setFilter(AbstractQuery $filter) + public function setFilter(AbstractQuery $filter): self { return $this->setParam('filter', $filter); } diff --git a/lib/Elastica/Aggregation/Filters.php b/lib/Elastica/Aggregation/Filters.php index 683e4c9d3d..4d285e22bf 100644 --- a/lib/Elastica/Aggregation/Filters.php +++ b/lib/Elastica/Aggregation/Filters.php @@ -25,11 +25,9 @@ class Filters extends AbstractAggregation * * If a name is given, it will be added as a key, otherwise considered as an anonymous filter * - * @param string $name - * * @return $this */ - public function addFilter(AbstractQuery $filter, string $name = null): self + public function addFilter(AbstractQuery $filter, ?string $name = null): self { $filterArray = []; diff --git a/lib/Elastica/Aggregation/GeoDistance.php b/lib/Elastica/Aggregation/GeoDistance.php index 4067e3b57a..d019c5fa1d 100644 --- a/lib/Elastica/Aggregation/GeoDistance.php +++ b/lib/Elastica/Aggregation/GeoDistance.php @@ -62,7 +62,7 @@ public function setOrigin($origin): self * * @return $this */ - public function addRange(int $fromValue = null, int $toValue = null): self + public function addRange(?int $fromValue = null, ?int $toValue = null): self { if (null === $fromValue && null === $toValue) { throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.'); diff --git a/lib/Elastica/Aggregation/IpRange.php b/lib/Elastica/Aggregation/IpRange.php index 6d1dbf7906..b686f1d6e3 100644 --- a/lib/Elastica/Aggregation/IpRange.php +++ b/lib/Elastica/Aggregation/IpRange.php @@ -43,7 +43,7 @@ public function setField(string $field): self * * @return $this */ - public function addRange(string $fromValue = null, string $toValue = null): self + public function addRange(?string $fromValue = null, ?string $toValue = null): self { if (null === $fromValue && null === $toValue) { throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.'); diff --git a/lib/Elastica/Aggregation/Percentiles.php b/lib/Elastica/Aggregation/Percentiles.php index b0edbec3ef..ec6275eef6 100644 --- a/lib/Elastica/Aggregation/Percentiles.php +++ b/lib/Elastica/Aggregation/Percentiles.php @@ -13,7 +13,7 @@ class Percentiles extends AbstractSimpleAggregation * @param string $name the name of this aggregation * @param string $field the field on which to perform this aggregation */ - public function __construct(string $name, string $field = null) + public function __construct(string $name, ?string $field = null) { parent::__construct($name); diff --git a/lib/Elastica/Aggregation/Range.php b/lib/Elastica/Aggregation/Range.php index c8cc2364c9..d66551e5b2 100644 --- a/lib/Elastica/Aggregation/Range.php +++ b/lib/Elastica/Aggregation/Range.php @@ -22,7 +22,7 @@ class Range extends AbstractSimpleAggregation * * @return $this */ - public function addRange($fromValue = null, $toValue = null, string $key = null) + public function addRange($fromValue = null, $toValue = null, ?string $key = null): self { if (null === $fromValue && null === $toValue) { throw new InvalidException('Either fromValue or toValue must be set. Both cannot be null.'); @@ -50,7 +50,7 @@ public function addRange($fromValue = null, $toValue = null, string $key = null) * * @return $this */ - public function setKeyedResponse(bool $keyed = true) + public function setKeyedResponse(bool $keyed = true): self { return $this->setParam('keyed', $keyed); } diff --git a/lib/Elastica/Aggregation/ReverseNested.php b/lib/Elastica/Aggregation/ReverseNested.php index 611a0d3764..a7b261b4af 100644 --- a/lib/Elastica/Aggregation/ReverseNested.php +++ b/lib/Elastica/Aggregation/ReverseNested.php @@ -13,7 +13,7 @@ class ReverseNested extends AbstractAggregation * @param string $name The name of this aggregation * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document. */ - public function __construct(string $name, string $path = null) + public function __construct(string $name, ?string $path = null) { parent::__construct($name); @@ -27,7 +27,7 @@ public function __construct(string $name, string $path = null) * * @return $this */ - public function setPath(string $path) + public function setPath(string $path): self { return $this->setParam('path', $path); } diff --git a/lib/Elastica/Aggregation/ScriptedMetric.php b/lib/Elastica/Aggregation/ScriptedMetric.php index e43b401372..dbae414940 100644 --- a/lib/Elastica/Aggregation/ScriptedMetric.php +++ b/lib/Elastica/Aggregation/ScriptedMetric.php @@ -18,10 +18,10 @@ class ScriptedMetric extends AbstractAggregation */ public function __construct( string $name, - string $initScript = null, - string $mapScript = null, - string $combineScript = null, - string $reduceScript = null + ?string $initScript = null, + ?string $mapScript = null, + ?string $combineScript = null, + ?string $reduceScript = null ) { parent::__construct($name); if ($initScript) { diff --git a/lib/Elastica/Aggregation/SerialDiff.php b/lib/Elastica/Aggregation/SerialDiff.php index f0020a6e62..aaaf680f33 100644 --- a/lib/Elastica/Aggregation/SerialDiff.php +++ b/lib/Elastica/Aggregation/SerialDiff.php @@ -13,7 +13,7 @@ class SerialDiff extends AbstractAggregation { const DEFAULT_GAP_POLICY_VALUE = 'insert_zero'; - public function __construct(string $name, string $bucketsPath = null) + public function __construct(string $name, ?string $bucketsPath = null) { parent::__construct($name); @@ -55,11 +55,9 @@ public function setGapPolicy(string $gapPolicy): self /** * Set the format for this aggregation. * - * @param string $format - * * @return $this */ - public function setFormat(string $format = null): self + public function setFormat(?string $format = null): self { return $this->setParam('format', $format); } diff --git a/lib/Elastica/Aggregation/StatsBucket.php b/lib/Elastica/Aggregation/StatsBucket.php index 67478bd135..187441c155 100644 --- a/lib/Elastica/Aggregation/StatsBucket.php +++ b/lib/Elastica/Aggregation/StatsBucket.php @@ -11,7 +11,7 @@ */ class StatsBucket extends AbstractAggregation { - public function __construct(string $name, string $bucketsPath = null) + public function __construct(string $name, ?string $bucketsPath = null) { parent::__construct($name); diff --git a/lib/Elastica/Aggregation/SumBucket.php b/lib/Elastica/Aggregation/SumBucket.php index 4fa7ecdf68..28c378263f 100644 --- a/lib/Elastica/Aggregation/SumBucket.php +++ b/lib/Elastica/Aggregation/SumBucket.php @@ -11,7 +11,7 @@ */ class SumBucket extends AbstractAggregation { - public function __construct(string $name, string $bucketsPath = null) + public function __construct(string $name, ?string $bucketsPath = null) { parent::__construct($name); diff --git a/lib/Elastica/Bulk.php b/lib/Elastica/Bulk.php index bf2f91fdb0..90289459d2 100644 --- a/lib/Elastica/Bulk.php +++ b/lib/Elastica/Bulk.php @@ -118,11 +118,9 @@ public function getActions(): array } /** - * @param string $opType - * * @return $this */ - public function addDocument(Document $document, string $opType = null): self + public function addDocument(Document $document, ?string $opType = null): self { $action = AbstractDocumentAction::create($document, $opType); @@ -131,11 +129,10 @@ public function addDocument(Document $document, string $opType = null): self /** * @param Document[] $documents - * @param string $opType * * @return $this */ - public function addDocuments(array $documents, string $opType = null): self + public function addDocuments(array $documents, ?string $opType = null): self { foreach ($documents as $document) { $this->addDocument($document, $opType); @@ -145,11 +142,9 @@ public function addDocuments(array $documents, string $opType = null): self } /** - * @param string $opType - * * @return $this */ - public function addScript(AbstractScript $script, string $opType = null): self + public function addScript(AbstractScript $script, ?string $opType = null): self { $action = AbstractDocumentAction::create($script, $opType); @@ -158,7 +153,6 @@ public function addScript(AbstractScript $script, string $opType = null): self /** * @param Document[] $scripts - * @param string $opType * * @return $this */ @@ -173,11 +167,10 @@ public function addScripts(array $scripts, $opType = null): self /** * @param \Elastica\Script\AbstractScript|\Elastica\Document|array $data - * @param string $opType * * @return $this */ - public function addData($data, string $opType = null) + public function addData($data, ?string $opType = null) { if (!\is_array($data)) { $data = [$data]; diff --git a/lib/Elastica/Bulk/Action.php b/lib/Elastica/Bulk/Action.php index cb9fa3c668..4fc5712679 100644 --- a/lib/Elastica/Bulk/Action.php +++ b/lib/Elastica/Bulk/Action.php @@ -175,7 +175,7 @@ public function toString(): string return $string; } - public static function isValidOpType(string $opType = null): bool + public static function isValidOpType(?string $opType = null): bool { return \in_array($opType, self::$opTypes, true); } diff --git a/lib/Elastica/Bulk/Action/AbstractDocument.php b/lib/Elastica/Bulk/Action/AbstractDocument.php index 06000fc6e0..4ae9cca76c 100644 --- a/lib/Elastica/Bulk/Action/AbstractDocument.php +++ b/lib/Elastica/Bulk/Action/AbstractDocument.php @@ -121,7 +121,7 @@ abstract protected function _getMetadata(AbstractUpdateAction $source): array; * * @return static */ - public static function create($data, string $opType = null): self + public static function create($data, ?string $opType = null): self { //Check type if (!$data instanceof Document && !$data instanceof AbstractScript) { diff --git a/lib/Elastica/Client.php b/lib/Elastica/Client.php index 57411279a3..9ea65bf6a0 100644 --- a/lib/Elastica/Client.php +++ b/lib/Elastica/Client.php @@ -3,6 +3,7 @@ namespace Elastica; use Elastica\Bulk\Action; +use Elastica\Bulk\ResponseSet; use Elastica\Exception\ConnectionException; use Elastica\Exception\InvalidException; use Elastica\Script\AbstractScript; @@ -58,13 +59,12 @@ class Client /** * Creates a new Elastica client. * - * @param array|string $config OPTIONAL Additional config or DSN of options - * @param callback|null $callback OPTIONAL Callback function which can be used to be notified about errors (for example connection down) - * @param LoggerInterface $logger + * @param array|string $config OPTIONAL Additional config or DSN of options + * @param callback|null $callback OPTIONAL Callback function which can be used to be notified about errors (for example connection down) * * @throws \Elastica\Exception\InvalidException */ - public function __construct($config = [], callable $callback = null, LoggerInterface $logger = null) + public function __construct($config = [], ?callable $callback = null, ?LoggerInterface $logger = null) { if (\is_string($config)) { $configuration = ClientConfiguration::fromDsn($config); @@ -76,17 +76,15 @@ public function __construct($config = [], callable $callback = null, LoggerInter $this->_config = $configuration; $this->_callback = $callback; - $this->_logger = $logger ?: new NullLogger(); + $this->_logger = $logger ?? new NullLogger(); $this->_initConnections(); } /** * Get current version. - * - * @return string */ - public function getVersion() + public function getVersion(): string { if ($this->_version) { return $this->_version; @@ -221,10 +219,8 @@ public function getConfigValue($keys, $default = null) * Returns the index for the given connection. * * @param string $name Index name to create connection to - * - * @return \Elastica\Index Index for the given name */ - public function getIndex(string $name) + public function getIndex(string $name): Index { return new Index($this, $name); } @@ -292,10 +288,8 @@ public function removeHeader($header) * @param array|\Elastica\Document[] $docs Array of Elastica\Document * * @throws \Elastica\Exception\InvalidException If docs is empty - * - * @return \Elastica\Bulk\ResponseSet Response object */ - public function updateDocuments(array $docs, array $requestParams = []) + public function updateDocuments(array $docs, array $requestParams = []): ResponseSet { if (empty($docs)) { throw new InvalidException('Array has to consist of at least one element'); @@ -323,10 +317,8 @@ public function updateDocuments(array $docs, array $requestParams = []) * @param array|\Elastica\Document[] $docs Array of Elastica\Document * * @throws \Elastica\Exception\InvalidException If docs is empty - * - * @return \Elastica\Bulk\ResponseSet Response object */ - public function addDocuments(array $docs, array $requestParams = []) + public function addDocuments(array $docs, array $requestParams = []): ResponseSet { if (empty($docs)) { throw new InvalidException('Array has to consist of at least one element'); @@ -351,11 +343,9 @@ public function addDocuments(array $docs, array $requestParams = []) * @param string $index index to update * @param array $options array of query params to use for query. For possible options check es api * - * @return \Elastica\Response - * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html */ - public function updateDocument($id, $data, $index, array $options = []) + public function updateDocument($id, $data, $index, array $options = []): Response { $endpoint = new Update(); $endpoint->setID($id); @@ -420,10 +410,8 @@ public function updateDocument($id, $data, $index, array $options = []) * @param array|\Elastica\Document[] $docs * * @throws \Elastica\Exception\InvalidException - * - * @return \Elastica\Bulk\ResponseSet */ - public function deleteDocuments(array $docs, array $requestParams = []) + public function deleteDocuments(array $docs, array $requestParams = []): ResponseSet { if (empty($docs)) { throw new InvalidException('Array has to consist of at least one element'); @@ -537,10 +525,8 @@ public function setConnections(array $connections) * @param string|bool $routing Optional routing key for all ids * * @throws \Elastica\Exception\InvalidException - * - * @return \Elastica\Bulk\ResponseSet Response object */ - public function deleteIds(array $ids, $index, $routing = false) + public function deleteIds(array $ids, $index, $routing = false): ResponseSet { if (empty($ids)) { throw new InvalidException('Array has to consist of at least one id'); @@ -581,14 +567,10 @@ public function deleteIds(array $ids, $index, $routing = false) * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html * - * @param array $params Parameter array - * * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\InvalidException - * - * @return \Elastica\Bulk\ResponseSet Response object */ - public function bulk(array $params) + public function bulk(array $params): ResponseSet { if (empty($params)) { throw new InvalidException('Array has to consist of at least one param'); @@ -613,10 +595,8 @@ public function bulk(array $params) * @param string $contentType Content-Type sent with this request * * @throws Exception\ConnectionException|Exception\ClientException - * - * @return Response Response object */ - public function request($path, $method = Request::GET, $data = [], array $query = [], $contentType = Request::DEFAULT_CONTENT_TYPE) + public function request(string $path, string $method = Request::GET, $data = [], array $query = [], string $contentType = Request::DEFAULT_CONTENT_TYPE): Response { $connection = $this->getConnection(); $request = $this->_lastRequest = new Request($path, $method, $data, $query, $connection, $contentType); @@ -651,10 +631,8 @@ public function request($path, $method = Request::GET, $data = [], array $query /** * Makes calls to the elasticsearch server with usage official client Endpoint. - * - * @return Response */ - public function requestEndpoint(AbstractEndpoint $endpoint) + public function requestEndpoint(AbstractEndpoint $endpoint): Response { return $this->request( \ltrim($endpoint->getURI(), '/'), @@ -669,11 +647,9 @@ public function requestEndpoint(AbstractEndpoint $endpoint) * * @param array $args OPTIONAL Optional arguments * - * @return \Elastica\Response Response object - * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html */ - public function forcemergeAll($args = []) + public function forcemergeAll($args = []): Response { $endpoint = new ForceMerge(); $endpoint->setParams($args); @@ -684,27 +660,19 @@ public function forcemergeAll($args = []) /** * Refreshes all search indices. * - * @return \Elastica\Response Response object - * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html */ - public function refreshAll() + public function refreshAll(): Response { return $this->requestEndpoint(new Refresh()); } - /** - * @return Request|null - */ - public function getLastRequest() + public function getLastRequest(): ?Request { return $this->_lastRequest; } - /** - * @return Response|null - */ - public function getLastResponse() + public function getLastResponse(): ?Response { return $this->_lastResponse; } diff --git a/lib/Elastica/Connection/ConnectionPool.php b/lib/Elastica/Connection/ConnectionPool.php index 135cf38926..5023385bf5 100644 --- a/lib/Elastica/Connection/ConnectionPool.php +++ b/lib/Elastica/Connection/ConnectionPool.php @@ -26,19 +26,14 @@ class ConnectionPool protected $_strategy; /** - * @var callable Function called on connection fail + * @var callable|null Function called on connection fail */ protected $_callback; - /** - * @param callback|null $callback - */ - public function __construct(array $connections, StrategyInterface $strategy, callable $callback = null) + public function __construct(array $connections, StrategyInterface $strategy, ?callable $callback = null) { $this->_connections = $connections; - $this->_strategy = $strategy; - $this->_callback = $callback; } diff --git a/lib/Elastica/Document.php b/lib/Elastica/Document.php index 0d28038cb4..c615c65532 100644 --- a/lib/Elastica/Document.php +++ b/lib/Elastica/Document.php @@ -40,7 +40,7 @@ class Document extends AbstractUpdateAction * @param array|string $data Data array * @param Index|string $index Index name */ - public function __construct(string $id = null, $data = [], $index = '') + public function __construct(?string $id = null, $data = [], $index = '') { $this->setId($id); $this->setData($data); diff --git a/lib/Elastica/Exception/Connection/GuzzleException.php b/lib/Elastica/Exception/Connection/GuzzleException.php index 013875b345..da3fb6a3c6 100644 --- a/lib/Elastica/Exception/Connection/GuzzleException.php +++ b/lib/Elastica/Exception/Connection/GuzzleException.php @@ -20,10 +20,7 @@ class GuzzleException extends ConnectionException */ protected $_guzzleException; - /** - * @param Request $request - */ - public function __construct(TransferException $guzzleException, Request $request = null, Response $response = null) + public function __construct(TransferException $guzzleException, ?Request $request = null, ?Response $response = null) { $this->_guzzleException = $guzzleException; $message = $this->getErrorMessage($this->getGuzzleException()); diff --git a/lib/Elastica/Exception/Connection/HttpException.php b/lib/Elastica/Exception/Connection/HttpException.php index 7c88195545..98eac8dd3b 100644 --- a/lib/Elastica/Exception/Connection/HttpException.php +++ b/lib/Elastica/Exception/Connection/HttpException.php @@ -27,7 +27,7 @@ class HttpException extends ConnectionException * @param Request $request * @param Response $response */ - public function __construct($error, Request $request = null, Response $response = null) + public function __construct($error, ?Request $request = null, ?Response $response = null) { $this->_error = $error; diff --git a/lib/Elastica/Exception/ConnectionException.php b/lib/Elastica/Exception/ConnectionException.php index 5a9c5e2b96..99f1680cd3 100644 --- a/lib/Elastica/Exception/ConnectionException.php +++ b/lib/Elastica/Exception/ConnectionException.php @@ -25,7 +25,7 @@ class ConnectionException extends \RuntimeException implements ExceptionInterfac /** * Construct Exception. */ - public function __construct(string $message, Request $request = null, Response $response = null) + public function __construct(string $message, ?Request $request = null, ?Response $response = null) { $this->_request = $request; $this->_response = $response; diff --git a/lib/Elastica/Index.php b/lib/Elastica/Index.php index 0be3256ac9..4d617ae093 100644 --- a/lib/Elastica/Index.php +++ b/lib/Elastica/Index.php @@ -462,7 +462,7 @@ public function exists(): bool * * @return Search */ - public function createSearch($query = '', $options = null, BuilderInterface $builder = null) + public function createSearch($query = '', $options = null, ?BuilderInterface $builder = null) { $search = new Search($this->getClient(), $builder); $search->addIndex($this); diff --git a/lib/Elastica/Multi/Search.php b/lib/Elastica/Multi/Search.php index 4b048c64eb..8a4b444776 100644 --- a/lib/Elastica/Multi/Search.php +++ b/lib/Elastica/Multi/Search.php @@ -49,10 +49,8 @@ class Search /** * Constructs search object. - * - * @param MultiBuilderInterface $builder */ - public function __construct(Client $client, MultiBuilderInterface $builder = null) + public function __construct(Client $client, ?MultiBuilderInterface $builder = null) { $this->_builder = $builder ?? new MultiBuilder(); $this->_client = $client; @@ -74,11 +72,9 @@ public function clearSearches(): self } /** - * @param string $key - * * @return $this */ - public function addSearch(BaseSearch $search, string $key = null): self + public function addSearch(BaseSearch $search, ?string $key = null): self { if ($key) { $this->_searches[$key] = $search; diff --git a/lib/Elastica/Query/AbstractGeoDistance.php b/lib/Elastica/Query/AbstractGeoDistance.php index f11de3193e..4803bbb681 100644 --- a/lib/Elastica/Query/AbstractGeoDistance.php +++ b/lib/Elastica/Query/AbstractGeoDistance.php @@ -57,7 +57,6 @@ abstract class AbstractGeoDistance extends AbstractQuery /** * 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' * * @internal param string $distance Distance diff --git a/lib/Elastica/Query/BoolQuery.php b/lib/Elastica/Query/BoolQuery.php index 9c8df96c63..49223c9242 100644 --- a/lib/Elastica/Query/BoolQuery.php +++ b/lib/Elastica/Query/BoolQuery.php @@ -52,8 +52,6 @@ public function addMustNot($args): self /** * Sets the filter. * - * @param AbstractQuery $filter Filter object - * * @return $this */ public function addFilter(AbstractQuery $filter): self diff --git a/lib/Elastica/Query/ConstantScore.php b/lib/Elastica/Query/ConstantScore.php index 34d860c721..9a5be6978b 100644 --- a/lib/Elastica/Query/ConstantScore.php +++ b/lib/Elastica/Query/ConstantScore.php @@ -14,7 +14,7 @@ class ConstantScore extends AbstractQuery /** * Construct constant score query. */ - public function __construct(AbstractQuery $filter = null) + public function __construct(?AbstractQuery $filter = null) { if (null !== $filter) { $this->setFilter($filter); diff --git a/lib/Elastica/Query/FunctionScore.php b/lib/Elastica/Query/FunctionScore.php index bb7d1e52c7..adf5d0d46c 100644 --- a/lib/Elastica/Query/FunctionScore.php +++ b/lib/Elastica/Query/FunctionScore.php @@ -73,8 +73,8 @@ public function setQuery(AbstractQuery $query): self public function addFunction( string $functionType, $functionParams, - AbstractQuery $filter = null, - float $weight = null + ?AbstractQuery $filter = null, + ?float $weight = null ): self { $function = [ $functionType => $functionParams, @@ -102,7 +102,7 @@ public function addFunction( * * @return $this */ - public function addScriptScoreFunction(AbstractScript $script, AbstractQuery $filter = null, float $weight = null) + public function addScriptScoreFunction(AbstractScript $script, ?AbstractQuery $filter = null, ?float $weight = null) { return $this->addFunction('script_score', $script, $filter, $weight); } @@ -127,11 +127,11 @@ public function addDecayFunction( string $field, string $origin, string $scale, - string $offset = null, - float $decay = null, - float $weight = null, - AbstractQuery $filter = null, - string $multiValueMode = null + ?string $offset = null, + ?float $decay = null, + ?float $weight = null, + ?AbstractQuery $filter = null, + ?string $multiValueMode = null ) { $functionParams = [ $field => [ @@ -158,11 +158,11 @@ public function addDecayFunction( */ public function addFieldValueFactorFunction( string $field, - float $factor = null, - string $modifier = null, - float $missing = null, - float $weight = null, - AbstractQuery $filter = null + ?float $factor = null, + ?string $modifier = null, + ?float $missing = null, + ?float $weight = null, + ?AbstractQuery $filter = null ): self { $functionParams = [ 'field' => $field, @@ -189,7 +189,7 @@ public function addFieldValueFactorFunction( * * @return $this */ - public function addWeightFunction(float $weight, AbstractQuery $filter = null): self + public function addWeightFunction(float $weight, ?AbstractQuery $filter = null): self { return $this->addFunction('weight', $weight, $filter); } @@ -206,9 +206,9 @@ public function addWeightFunction(float $weight, AbstractQuery $filter = null): */ public function addRandomScoreFunction( int $seed, - AbstractQuery $filter = null, - float $weight = null, - string $field = null + ?AbstractQuery $filter = null, + ?float $weight = null, + ?string $field = null ): self { $functionParams = [ 'seed' => $seed, @@ -260,7 +260,7 @@ public function setBoostMode(string $mode = self::BOOST_MODE_MULTIPLY): self * * @return $this */ - public function setRandomScore(int $seed = null): self + public function setRandomScore(?int $seed = null): self { $seedParam = new \stdClass(); if (null !== $seed) { diff --git a/lib/Elastica/Query/Fuzzy.php b/lib/Elastica/Query/Fuzzy.php index 3a4ed5dc91..3357e8ee79 100644 --- a/lib/Elastica/Query/Fuzzy.php +++ b/lib/Elastica/Query/Fuzzy.php @@ -16,10 +16,9 @@ class Fuzzy extends AbstractQuery /** * Construct a fuzzy query. * - * @param string $fieldName Field name - * @param string $value String to search for + * @param string $value String to search for */ - public function __construct(string $fieldName = null, string $value = null) + public function __construct(?string $fieldName = null, ?string $value = null) { if (null !== $fieldName && null !== $value) { $this->setField($fieldName, $value); @@ -29,8 +28,7 @@ public function __construct(string $fieldName = null, string $value = null) /** * Set field for fuzzy query. * - * @param string $fieldName Field name - * @param string $value String to search for + * @param string $value String to search for * * @return $this */ @@ -49,8 +47,7 @@ public function setField(string $fieldName, string $value): self /** * Set optional parameters on the existing query. * - * @param string $option option name - * @param mixed $value Value of the parameter + * @param mixed $value Value of the parameter * * @return $this */ diff --git a/lib/Elastica/Query/GeoBoundingBox.php b/lib/Elastica/Query/GeoBoundingBox.php index 59d61bc51e..743fccac58 100644 --- a/lib/Elastica/Query/GeoBoundingBox.php +++ b/lib/Elastica/Query/GeoBoundingBox.php @@ -16,8 +16,7 @@ class GeoBoundingBox extends AbstractQuery /** * Construct BoundingBoxQuery. * - * @param string $key Key - * @param array $coordinates Array with top left coordinate as first and bottom right coordinate as second element + * @param array $coordinates Array with top left coordinate as first and bottom right coordinate as second element */ public function __construct(string $key, array $coordinates) { @@ -27,8 +26,7 @@ public function __construct(string $key, array $coordinates) /** * Add coordinates. * - * @param string $key Key - * @param array $coordinates Array with top left coordinate as first and bottom right coordinate as second element + * @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 * diff --git a/lib/Elastica/Query/HasChild.php b/lib/Elastica/Query/HasChild.php index 99768ec411..026055d171 100644 --- a/lib/Elastica/Query/HasChild.php +++ b/lib/Elastica/Query/HasChild.php @@ -19,7 +19,7 @@ class HasChild extends AbstractQuery * @param string|BaseQuery|AbstractQuery $query * @param string $type Parent document type */ - public function __construct($query, string $type = null) + public function __construct($query, ?string $type = null) { $this->setType($type); $this->setQuery($query); @@ -44,7 +44,7 @@ public function setQuery($query): self * * @return $this */ - public function setType(string $type = null): self + public function setType(?string $type = null): self { return $this->setParam('type', $type); } diff --git a/lib/Elastica/Query/Match.php b/lib/Elastica/Query/Match.php index 090d2b93c4..4a70993be4 100644 --- a/lib/Elastica/Query/Match.php +++ b/lib/Elastica/Query/Match.php @@ -24,7 +24,7 @@ class Match extends AbstractQuery * @param string $field * @param mixed $values */ - public function __construct(string $field = null, $values = null) + public function __construct(?string $field = null, $values = null) { if (null !== $field && null !== $values) { $this->setParam($field, $values); diff --git a/lib/Elastica/Query/MatchPhrase.php b/lib/Elastica/Query/MatchPhrase.php index 5daa3f90a1..74ae2e8e0c 100644 --- a/lib/Elastica/Query/MatchPhrase.php +++ b/lib/Elastica/Query/MatchPhrase.php @@ -16,7 +16,7 @@ class MatchPhrase extends AbstractQuery * @param string $field * @param mixed $values */ - public function __construct(string $field = null, $values = null) + public function __construct(?string $field = null, $values = null) { if (null !== $field && null !== $values) { $this->setParam($field, $values); diff --git a/lib/Elastica/Query/Range.php b/lib/Elastica/Query/Range.php index b50c22704b..a36855723e 100644 --- a/lib/Elastica/Query/Range.php +++ b/lib/Elastica/Query/Range.php @@ -17,7 +17,7 @@ class Range extends AbstractQuery * @param string $fieldName Field name * @param array $args Field arguments */ - public function __construct(string $fieldName = null, array $args = []) + public function __construct(?string $fieldName = null, array $args = []) { if ($fieldName) { $this->addField($fieldName, $args); diff --git a/lib/Elastica/Query/Regexp.php b/lib/Elastica/Query/Regexp.php index 275094357f..89a3c3bb4e 100644 --- a/lib/Elastica/Query/Regexp.php +++ b/lib/Elastica/Query/Regexp.php @@ -18,7 +18,7 @@ class Regexp extends AbstractQuery * @param string $value OPTIONAL Regexp value * @param float $boost OPTIONAL Boost value (default = 1) */ - public function __construct(string $key = '', string $value = null, float $boost = 1.0) + public function __construct(string $key = '', ?string $value = null, float $boost = 1.0) { if (!empty($key)) { $this->setValue($key, $value, $boost); @@ -32,7 +32,7 @@ public function __construct(string $key = '', string $value = null, float $boost * * @return $this */ - public function setValue(string $key, string $value = null, float $boost = 1.0) + public function setValue(string $key, ?string $value = null, float $boost = 1.0) { return $this->setParam($key, ['value' => $value, 'boost' => $boost]); } diff --git a/lib/Elastica/Query/SpanContaining.php b/lib/Elastica/Query/SpanContaining.php index 8914a9816f..913d4fc4df 100644 --- a/lib/Elastica/Query/SpanContaining.php +++ b/lib/Elastica/Query/SpanContaining.php @@ -17,7 +17,7 @@ class SpanContaining extends AbstractSpanQuery * @param AbstractSpanQuery $little OPTIONAL * @param AbstractSpanQuery $big OPTIONAL */ - public function __construct(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null) + public function __construct(?AbstractSpanQuery $little = null, ?AbstractSpanQuery $big = null) { if (null !== $little) { $this->setLittle($little); diff --git a/lib/Elastica/Query/SpanFirst.php b/lib/Elastica/Query/SpanFirst.php index 1fb512290c..c913b98855 100644 --- a/lib/Elastica/Query/SpanFirst.php +++ b/lib/Elastica/Query/SpanFirst.php @@ -19,7 +19,7 @@ class SpanFirst extends AbstractSpanQuery * @param AbstractQuery|array $match * @param int $end */ - public function __construct($match = null, int $end = null) + public function __construct($match = null, ?int $end = null) { if (null !== $match) { $this->setMatch($match); diff --git a/lib/Elastica/Query/SpanNot.php b/lib/Elastica/Query/SpanNot.php index 25578a4a10..4947d52b95 100644 --- a/lib/Elastica/Query/SpanNot.php +++ b/lib/Elastica/Query/SpanNot.php @@ -17,7 +17,7 @@ class SpanNot extends AbstractSpanQuery * @param AbstractSpanQuery $include * @param AbstractSpanQuery $exclude */ - public function __construct(AbstractSpanQuery $include = null, AbstractSpanQuery $exclude = null) + public function __construct(?AbstractSpanQuery $include = null, ?AbstractSpanQuery $exclude = null) { if (null !== $include) { $this->setInclude($include); diff --git a/lib/Elastica/Query/SpanWithin.php b/lib/Elastica/Query/SpanWithin.php index 01b019036c..579bf2eb44 100644 --- a/lib/Elastica/Query/SpanWithin.php +++ b/lib/Elastica/Query/SpanWithin.php @@ -17,7 +17,7 @@ class SpanWithin extends AbstractSpanQuery * @param AbstractSpanQuery $little * @param AbstractSpanQuery $big */ - public function __construct(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null) + public function __construct(?AbstractSpanQuery $little = null, ?AbstractSpanQuery $big = null) { if (null !== $little) { $this->setLittle($little); diff --git a/lib/Elastica/Query/Wildcard.php b/lib/Elastica/Query/Wildcard.php index e7249720d4..8ce6e481f9 100644 --- a/lib/Elastica/Query/Wildcard.php +++ b/lib/Elastica/Query/Wildcard.php @@ -18,7 +18,7 @@ class Wildcard extends AbstractQuery * @param string $value OPTIONAL Wildcard value * @param float $boost OPTIONAL Boost value (default = 1) */ - public function __construct(string $key = '', string $value = null, float $boost = 1.0) + public function __construct(string $key = '', ?string $value = null, float $boost = 1.0) { if (!empty($key)) { $this->setValue($key, $value, $boost); diff --git a/lib/Elastica/QueryBuilder.php b/lib/Elastica/QueryBuilder.php index 6d3f768dd3..ebbb8c4872 100644 --- a/lib/Elastica/QueryBuilder.php +++ b/lib/Elastica/QueryBuilder.php @@ -27,7 +27,7 @@ class QueryBuilder /** * Constructor. */ - public function __construct(Version $version = null) + public function __construct(?Version $version = null) { $this->_version = $version ?? new Version\Latest(); diff --git a/lib/Elastica/QueryBuilder/DSL/Aggregation.php b/lib/Elastica/QueryBuilder/DSL/Aggregation.php index f32e05bcd2..aa48473cf2 100644 --- a/lib/Elastica/QueryBuilder/DSL/Aggregation.php +++ b/lib/Elastica/QueryBuilder/DSL/Aggregation.php @@ -90,7 +90,7 @@ public function sum(string $name): Sum * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-sum-bucket-aggregation.html */ - public function sum_bucket(string $name, string $bucketsPath = null): SumBucket + public function sum_bucket(string $name, ?string $bucketsPath = null): SumBucket { return new SumBucket($name, $bucketsPath); } @@ -110,7 +110,7 @@ public function avg(string $name): Avg * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-avg-bucket-aggregation.html */ - public function avg_bucket(string $name, string $bucketsPath = null): AvgBucket + public function avg_bucket(string $name, ?string $bucketsPath = null): AvgBucket { return new AvgBucket($name, $bucketsPath); } @@ -153,7 +153,7 @@ public function value_count(string $name, string $field): ValueCount * @param string $name the name of this aggregation * @param string $field the field on which to perform this aggregation */ - public function percentiles(string $name, string $field = null): Percentiles + public function percentiles(string $name, ?string $field = null): Percentiles { return new Percentiles($name, $field); } @@ -209,10 +209,10 @@ public function top_hits(string $name): TopHits */ public function scripted_metric( string $name, - string $initScript = null, - string $mapScript = null, - string $combineScript = null, - string $reduceScript = null + ?string $initScript = null, + ?string $mapScript = null, + ?string $combineScript = null, + ?string $reduceScript = null ): ScriptedMetric { return new ScriptedMetric($name, $initScript, $mapScript, $combineScript, $reduceScript); } @@ -234,7 +234,7 @@ public function global_agg(string $name): GlobalAggregation * * @param AbstractQuery $filter */ - public function filter(string $name, AbstractQuery $filter = null): Filter + public function filter(string $name, ?AbstractQuery $filter = null): Filter { return new Filter($name, $filter); } @@ -279,7 +279,7 @@ public function nested(string $name, string $path): Nested * @param string $name The name of this aggregation * @param string $path Optional path to the nested object for this aggregation. Defaults to the root of the main document. */ - public function reverse_nested(string $name, string $path = null): ReverseNested + public function reverse_nested(string $name, ?string $path = null): ReverseNested { return new ReverseNested($name, $path); } @@ -406,7 +406,7 @@ public function geohash_grid(string $name, string $field): GeohashGrid * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-bucket-script-aggregation.html */ - public function bucket_script(string $name, array $bucketsPath = null, string $script = null): BucketScript + public function bucket_script(string $name, ?array $bucketsPath = null, ?string $script = null): BucketScript { return new BucketScript($name, $bucketsPath, $script); } @@ -416,7 +416,7 @@ public function bucket_script(string $name, array $bucketsPath = null, string $s * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-pipeline-serialdiff-aggregation.html */ - public function serial_diff(string $name, string $bucketsPath = null): SerialDiff + public function serial_diff(string $name, ?string $bucketsPath = null): SerialDiff { return new SerialDiff($name, $bucketsPath); } diff --git a/lib/Elastica/QueryBuilder/DSL/Query.php b/lib/Elastica/QueryBuilder/DSL/Query.php index 4e71ad557e..228ac31f17 100644 --- a/lib/Elastica/QueryBuilder/DSL/Query.php +++ b/lib/Elastica/QueryBuilder/DSL/Query.php @@ -70,10 +70,9 @@ public function getType(): string * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html * - * @param string $field - * @param mixed $values + * @param mixed $values */ - public function match(string $field = null, $values = null): Match + public function match(?string $field = null, $values = null): Match { return new Match($field, $values); } @@ -125,7 +124,7 @@ public function common_terms(string $field, string $query, float $cutoffFrequenc * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-constant-score-query.html */ - public function constant_score(AbstractQuery $filter = null): ConstantScore + public function constant_score(?AbstractQuery $filter = null): ConstantScore { return new ConstantScore($filter); } @@ -155,10 +154,9 @@ public function function_score(): FunctionScore * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html * - * @param string $fieldName Field name - * @param string $value String to search for + * @param string $value String to search for */ - public function fuzzy(string $fieldName = null, string $value = null): Fuzzy + public function fuzzy(?string $fieldName = null, ?string $value = null): Fuzzy { return new Fuzzy($fieldName, $value); } @@ -213,7 +211,7 @@ public function geo_shape() * @param string|BaseQuery|AbstractQuery $query * @param string $type Parent document type */ - public function has_child($query, string $type = null): HasChild + public function has_child($query, ?string $type = null): HasChild { return new HasChild($query, $type); } @@ -266,7 +264,7 @@ public function match_none(): MatchNone * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html */ - public function match_phrase(string $field = null, $values = null): MatchPhrase + public function match_phrase(?string $field = null, $values = null): MatchPhrase { return new MatchPhrase($field, $values); } @@ -276,7 +274,7 @@ public function match_phrase(string $field = null, $values = null): MatchPhrase * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html */ - public function match_phrase_prefix(string $field = null, $values = null): MatchPhrasePrefix + public function match_phrase_prefix(?string $field = null, $values = null): MatchPhrasePrefix { return new MatchPhrasePrefix($field, $values); } @@ -303,8 +301,6 @@ public function nested(): Nested /** * @param int|string $id - * - * @return ParentId ParentId */ public function parent_id(string $type, $id, bool $ignoreUnmapped = false): ParentId { @@ -349,10 +345,8 @@ public function simple_query_string(string $query, array $fields = []): SimpleQu * range query. * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html - * - * @param string $fieldName */ - public function range(string $fieldName = null, array $args = []): Range + public function range(?string $fieldName = null, array $args = []): Range { return new Range($fieldName, $args); } @@ -360,11 +354,9 @@ public function range(string $fieldName = null, array $args = []): Range /** * regexp query. * - * @param string $value - * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html */ - public function regexp(string $key = '', string $value = null, float $boost = 1.0): Regexp + public function regexp(string $key = '', ?string $value = null, float $boost = 1.0): Regexp { return new Regexp($key, $value, $boost); } @@ -373,11 +365,10 @@ public function regexp(string $key = '', string $value = null, float $boost = 1. * span first query. * * @param AbstractQuery|array $match - * @param int $end * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-first-query.html */ - public function span_first($match = null, int $end = null): SpanFirst + public function span_first($match = null, ?int $end = null): SpanFirst { return new SpanFirst($match, $end); } @@ -409,7 +400,7 @@ public function span_near(array $clauses = [], int $slop = 1, bool $inOrder = fa * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-not-query.html */ - public function span_not(AbstractSpanQuery $include = null, AbstractSpanQuery $exclude = null): SpanNot + public function span_not(?AbstractSpanQuery $include = null, ?AbstractSpanQuery $exclude = null): SpanNot { return new SpanNot($include, $exclude); } @@ -439,7 +430,7 @@ public function span_term(array $term = []): SpanTerm * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-containing-query.html */ - public function span_containing(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null): SpanContaining + public function span_containing(?AbstractSpanQuery $little = null, ?AbstractSpanQuery $big = null): SpanContaining { return new SpanContaining($little, $big); } @@ -449,7 +440,7 @@ public function span_containing(AbstractSpanQuery $little = null, AbstractSpanQu * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-within-query.html */ - public function span_within(AbstractSpanQuery $little = null, AbstractSpanQuery $big = null): SpanWithin + public function span_within(?AbstractSpanQuery $little = null, ?AbstractSpanQuery $big = null): SpanWithin { return new SpanWithin($little, $big); } @@ -479,11 +470,11 @@ public function terms(string $key = '', array $terms = []): Terms * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html * - * @param string $key OPTIONAL Wildcard key - * @param string $value OPTIONAL Wildcard value - * @param float $boost OPTIONAL Boost value (default = 1) + * @param string $key OPTIONAL Wildcard key + * @param string|null $value OPTIONAL Wildcard value + * @param float $boost OPTIONAL Boost value (default = 1) */ - public function wildcard(string $key = '', string $value = null, float $boost = 1.0): Wildcard + public function wildcard(string $key = '', ?string $value = null, float $boost = 1.0): Wildcard { return new Wildcard($key, $value, $boost); } diff --git a/lib/Elastica/Request.php b/lib/Elastica/Request.php index 6044c42bf9..8c26983daf 100644 --- a/lib/Elastica/Request.php +++ b/lib/Elastica/Request.php @@ -27,16 +27,13 @@ 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 $contentType Content-Type sent with this request - * - * @return \Elastica\Request OPTIONAL Connection object + * @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 string $contentType Content-Type sent with this request */ - public function __construct($path, $method = self::GET, $data = [], array $query = [], Connection $connection = null, $contentType = self::DEFAULT_CONTENT_TYPE) + public function __construct(string $path, string $method = self::GET, $data = [], array $query = [], ?Connection $connection = null, string $contentType = self::DEFAULT_CONTENT_TYPE) { $this->setPath($path); $this->setMethod($method); @@ -52,21 +49,17 @@ public function __construct($path, $method = self::GET, $data = [], array $query /** * Sets the request method. Use one of the for consts. * - * @param string $method Request method - * * @return $this */ - public function setMethod($method) + public function setMethod(string $method) { return $this->setParam('method', $method); } /** * Get request method. - * - * @return string Request method */ - public function getMethod() + public function getMethod(): string { return $this->getParam('method'); } @@ -96,21 +89,17 @@ public function getData() /** * Sets the request path. * - * @param string $path Request path - * * @return $this */ - public function setPath($path) + public function setPath(string $path) { return $this->setParam('path', $path); } /** * Return request path. - * - * @return string Request path */ - public function getPath() + public function getPath(): string { return $this->getParam('path'); } @@ -120,7 +109,7 @@ public function getPath() * * @return array Query params */ - public function getQuery() + public function getQuery(): array { return $this->getParam('query'); } @@ -134,8 +123,6 @@ public function setQuery(array $query = []) } /** - * @param \Elastica\Connection $connection - * * @return $this */ public function setConnection(Connection $connection) @@ -148,13 +135,11 @@ public function setConnection(Connection $connection) /** * Return Connection Object. * - * @throws Exception\InvalidException If no valid connection was setted - * - * @return \Elastica\Connection + * @throws Exception\InvalidException If no valid connection was set */ - public function getConnection() + public function getConnection(): Connection { - if (empty($this->_connection)) { + if (null === $this->_connection) { throw new InvalidException('No valid connection object set'); } @@ -163,10 +148,8 @@ public function getConnection() /** * Set the Content-Type of this request. - * - * @param string $contentType */ - public function setContentType($contentType) + public function setContentType(string $contentType) { return $this->setParam('contentType', $contentType); } @@ -174,17 +157,15 @@ public function setContentType($contentType) /** * Get the Content-Type of this request. */ - public function getContentType() + public function getContentType(): string { return $this->getParam('contentType'); } /** * Sends request to server. - * - * @return \Elastica\Response Response object */ - public function send() + public function send(): Response { $transport = $this->getConnection()->getTransportObject(); diff --git a/lib/Elastica/ResultSet.php b/lib/Elastica/ResultSet.php index af66de11e4..c67ed4edcb 100644 --- a/lib/Elastica/ResultSet.php +++ b/lib/Elastica/ResultSet.php @@ -241,7 +241,7 @@ public function count() */ public function countSuggests() { - return \sizeof($this->getSuggests()); + return \count($this->getSuggests()); } /** diff --git a/lib/Elastica/Script/AbstractScript.php b/lib/Elastica/Script/AbstractScript.php index 2d1087fb99..dd01c9e0ca 100644 --- a/lib/Elastica/Script/AbstractScript.php +++ b/lib/Elastica/Script/AbstractScript.php @@ -87,7 +87,7 @@ private static function _createFromArray(array $data) * @param string|null $lang Script language, see constants * @param string|null $documentId Document ID the script action should be performed on (only relevant in update context) */ - public function __construct(array $params = null, string $lang = null, string $documentId = null) + public function __construct(?array $params = null, ?string $lang = null, ?string $documentId = null) { if ($params) { $this->setParams($params); diff --git a/lib/Elastica/Script/Script.php b/lib/Elastica/Script/Script.php index 55111c1329..d6dee4645a 100644 --- a/lib/Elastica/Script/Script.php +++ b/lib/Elastica/Script/Script.php @@ -22,17 +22,14 @@ class Script extends AbstractScript * @param string $scriptCode Script source code * @param string|null $documentId Document ID the script action should be performed on (only relevant in update context) */ - public function __construct(string $scriptCode, array $params = null, string $lang = null, string $documentId = null) + public function __construct(string $scriptCode, ?array $params = null, ?string $lang = null, ?string $documentId = null) { parent::__construct($params, $lang, $documentId); $this->setScript($scriptCode); } - /** - * @return $this - */ - public function setScript(string $scriptCode): Script + public function setScript(string $scriptCode): self { $this->_scriptCode = $scriptCode; diff --git a/lib/Elastica/Script/ScriptId.php b/lib/Elastica/Script/ScriptId.php index 6c613586e5..f5e746760b 100644 --- a/lib/Elastica/Script/ScriptId.php +++ b/lib/Elastica/Script/ScriptId.php @@ -18,10 +18,9 @@ class ScriptId extends AbstractScript private $_scriptId; /** - * @param string $scriptId Script ID * @param string|null $documentId Document ID the script action should be performed on (only relevant in update context) */ - public function __construct(string $scriptId, array $params = null, string $lang = null, string $documentId = null) + public function __construct(string $scriptId, ?array $params = null, ?string $lang = null, ?string $documentId = null) { parent::__construct($params, $lang, $documentId); diff --git a/lib/Elastica/Scroll.php b/lib/Elastica/Scroll.php index 0022337240..e1377b9e9a 100644 --- a/lib/Elastica/Scroll.php +++ b/lib/Elastica/Scroll.php @@ -44,10 +44,8 @@ class Scroll implements \Iterator /** * Constructor. - * - * @param string $expiryTime */ - public function __construct(Search $search, $expiryTime = '1m') + public function __construct(Search $search, string $expiryTime = '1m') { $this->_search = $search; $this->expiryTime = $expiryTime; @@ -57,10 +55,8 @@ public function __construct(Search $search, $expiryTime = '1m') * Returns current result set. * * @see http://php.net/manual/en/iterator.current.php - * - * @return ResultSet */ - public function current() + public function current(): ?ResultSet { return $this->_currentResultSet; } @@ -92,10 +88,8 @@ public function next() * Returns scroll id. * * @see http://php.net/manual/en/iterator.key.php - * - * @return string */ - public function key() + public function key(): ?string { return $this->_nextScrollId; } @@ -104,10 +98,8 @@ public function key() * Returns true if current result set contains at least one hit. * * @see http://php.net/manual/en/iterator.valid.php - * - * @return bool */ - public function valid() + public function valid(): bool { return null !== $this->_nextScrollId; } @@ -117,7 +109,7 @@ public function valid() * * @see http://php.net/manual/en/iterator.rewind.php */ - public function rewind() + public function rewind(): void { // reset state $this->_options = [null, null]; diff --git a/lib/Elastica/Search.php b/lib/Elastica/Search.php index 943ee66d1d..0244d9fc0c 100644 --- a/lib/Elastica/Search.php +++ b/lib/Elastica/Search.php @@ -77,11 +77,8 @@ class Search /** * Constructs search object. - * - * @param \Elastica\Client $client Client object - * @param BuilderInterface $builder */ - public function __construct(Client $client, BuilderInterface $builder = null) + public function __construct(Client $client, ?BuilderInterface $builder = null) { $this->_builder = $builder ?: new DefaultBuilder(); $this->_client = $client; @@ -441,12 +438,8 @@ public function setSuggest(Suggest $suggest) * Returns the Scroll Iterator. * * @see Scroll - * - * @param string $expiryTime - * - * @return Scroll */ - public function scroll($expiryTime = '1m') + public function scroll(string $expiryTime = '1m'): Scroll { return new Scroll($this, $expiryTime); } diff --git a/lib/Elastica/Suggest.php b/lib/Elastica/Suggest.php index 0cef285e59..52a84e3419 100644 --- a/lib/Elastica/Suggest.php +++ b/lib/Elastica/Suggest.php @@ -15,7 +15,7 @@ class Suggest extends Param /** * @param AbstractSuggest $suggestion */ - public function __construct(AbstractSuggest $suggestion = null) + public function __construct(?AbstractSuggest $suggestion = null) { if (!\is_null($suggestion)) { $this->addSuggestion($suggestion); diff --git a/lib/Elastica/Suggest/AbstractSuggest.php b/lib/Elastica/Suggest/AbstractSuggest.php index 5b6511b1d4..0ee209de37 100644 --- a/lib/Elastica/Suggest/AbstractSuggest.php +++ b/lib/Elastica/Suggest/AbstractSuggest.php @@ -27,7 +27,7 @@ public function __construct(string $name, string $field) * * @return $this */ - public function setText(string $text): AbstractSuggest + public function setText(string $text): self { return $this->_setRawParam('text', $text); } @@ -37,7 +37,7 @@ public function setText(string $text): AbstractSuggest * * @return $this */ - public function setPrefix(string $prefix): AbstractSuggest + public function setPrefix(string $prefix): self { return $this->_setRawParam('prefix', $prefix); } @@ -47,7 +47,7 @@ public function setPrefix(string $prefix): AbstractSuggest * * @return $this */ - public function setRegex(string $regex): AbstractSuggest + public function setRegex(string $regex): self { return $this->_setRawParam('regex', $regex); } @@ -58,7 +58,7 @@ public function setRegex(string $regex): AbstractSuggest * * @return $this */ - public function setRegexOptions(array $value): AbstractSuggest + public function setRegexOptions(array $value): self { return $this->setParam('regex', $value); } @@ -66,7 +66,7 @@ public function setRegexOptions(array $value): AbstractSuggest /** * @return $this */ - public function setField(string $field): AbstractSuggest + public function setField(string $field): self { return $this->setParam('field', $field); } @@ -74,7 +74,7 @@ public function setField(string $field): AbstractSuggest /** * @return $this */ - public function setSize(int $size): AbstractSuggest + public function setSize(int $size): self { return $this->setParam('size', $size); } @@ -84,7 +84,7 @@ public function setSize(int $size): AbstractSuggest * * @return $this */ - public function setShardSize(int $size): AbstractSuggest + public function setShardSize(int $size): self { return $this->setParam('shard_size', $size); } @@ -99,7 +99,7 @@ public function setShardSize(int $size): AbstractSuggest * * @return $this */ - public function setName(string $name): AbstractSuggest + public function setName(string $name): self { if (empty($name)) { throw new InvalidException('Suggest name has to be set'); diff --git a/lib/Elastica/Transport/AbstractTransport.php b/lib/Elastica/Transport/AbstractTransport.php index 2e0ea6f0b5..f25ffc4d34 100644 --- a/lib/Elastica/Transport/AbstractTransport.php +++ b/lib/Elastica/Transport/AbstractTransport.php @@ -22,27 +22,20 @@ abstract class AbstractTransport extends Param /** * Construct transport. - * - * @param Connection $connection Connection object */ - public function __construct(Connection $connection = null) + public function __construct(?Connection $connection = null) { if ($connection) { $this->setConnection($connection); } } - /** - * @return Connection Connection object - */ public function getConnection(): Connection { return $this->_connection; } /** - * @param Connection $connection Connection object - * * @return $this */ public function setConnection(Connection $connection): AbstractTransport @@ -57,8 +50,6 @@ public function setConnection(Connection $connection): AbstractTransport * * @param Request $request Request object * @param array $params Hostname, port, path, ... - * - * @return Response Response object */ abstract public function exec(Request $request, array $params): Response; diff --git a/lib/Elastica/Transport/HttpAdapter.php b/lib/Elastica/Transport/HttpAdapter.php index dcd3986d0d..62e9eb48ab 100644 --- a/lib/Elastica/Transport/HttpAdapter.php +++ b/lib/Elastica/Transport/HttpAdapter.php @@ -29,10 +29,8 @@ class HttpAdapter extends AbstractTransport /** * Construct transport. - * - * @param Connection $connection */ - public function __construct(Connection $connection = null, HttpAdapterInterface $httpAdapter) + public function __construct(?Connection $connection = null, HttpAdapterInterface $httpAdapter) { parent::__construct($connection); $this->httpAdapter = $httpAdapter; @@ -48,8 +46,6 @@ public function __construct(Connection $connection = null, HttpAdapterInterface * @throws \Elastica\Exception\ConnectionException * @throws \Elastica\Exception\ResponseException * @throws \Elastica\Exception\Connection\HttpException - * - * @return \Elastica\Response Response object */ public function exec(ElasticaRequest $elasticaRequest, array $params): Response { diff --git a/lib/Elastica/Util.php b/lib/Elastica/Util.php index 8925b554ae..5c9c8dcc94 100644 --- a/lib/Elastica/Util.php +++ b/lib/Elastica/Util.php @@ -198,11 +198,9 @@ public static function convertDate($date) * * Converts it to the lucene format, including the appropriate TimeZone * - * @param bool $includeTimezone - * * @return string */ - public static function convertDateTimeObject(\DateTime $dateTime, $includeTimezone = true) + public static function convertDateTimeObject(\DateTime $dateTime, bool $includeTimezone = true) { $formatString = 'Y-m-d\TH:i:s'.(true === $includeTimezone ? 'P' : '\Z'); $string = $dateTime->format($formatString); diff --git a/test/Elastica/Base.php b/test/Elastica/Base.php index 8e2a0eec34..f789dbca91 100644 --- a/test/Elastica/Base.php +++ b/test/Elastica/Base.php @@ -58,13 +58,9 @@ protected function finishCollectErrors() } /** - * @param array $params Additional configuration params. Host and Port are already set - * @param callback $callback - * @param LoggerInterface $logger - * - * @return Client + * @param array $params Additional configuration params. Host and Port are already set */ - protected function _getClient(array $params = [], $callback = null, LoggerInterface $logger = null) + protected function _getClient(array $params = [], ?callable $callback = null, ?LoggerInterface $logger = null): Client { $config = [ 'host' => $this->_getHost(), @@ -92,27 +88,21 @@ protected function _getPort() return \getenv('ES_PORT') ?: Connection::DEFAULT_PORT; } - /** - * @return string Proxy url string - */ - protected function _getProxyUrl() + protected function _getProxyUrl(): string { $proxyHost = \getenv('PROXY_HOST') ?: Connection::DEFAULT_HOST; return 'http://'.$proxyHost.':12345'; } - /** - * @return string Proxy url string to proxy which returns 403 - */ - protected function _getProxyUrl403() + protected function _getProxyUrl403(): string { $proxyHost = \getenv('PROXY_HOST') ?: Connection::DEFAULT_HOST; return 'http://'.$proxyHost.':12346'; } - protected function _createIndex(string $name = null, bool $delete = true, int $shards = 1): Index + protected function _createIndex(?string $name = null, bool $delete = true, int $shards = 1): Index { if (null === $name) { $name = \preg_replace('/[^a-z]/i', '', \strtolower(\get_called_class()).\uniqid()); diff --git a/test/Elastica/BasePipeline.php b/test/Elastica/BasePipeline.php index 3133e973c2..8496e9889d 100644 --- a/test/Elastica/BasePipeline.php +++ b/test/Elastica/BasePipeline.php @@ -9,12 +9,8 @@ class BasePipeline extends BaseTest { /** * Create Pipeline object. - * - * @param string $id - * - * @return Pipeline */ - protected function _createPipeline(string $id = null, string $description = '') + protected function _createPipeline(?string $id = null, string $description = ''): Pipeline { if (\is_null($id)) { $id = \preg_replace('/[^a-z]/i', '', \strtolower(\get_called_class()).\uniqid()); diff --git a/test/Elastica/ErrorsCollector.php b/test/Elastica/ErrorsCollector.php index 39a586d3a5..c2bc0d62c4 100644 --- a/test/Elastica/ErrorsCollector.php +++ b/test/Elastica/ErrorsCollector.php @@ -18,7 +18,7 @@ class ErrorsCollector */ private $testCase; - public function __construct(TestCase $testCase = null) + public function __construct(?TestCase $testCase = null) { $this->testCase = $testCase; } diff --git a/test/Elastica/Multi/SearchTest.php b/test/Elastica/Multi/SearchTest.php index eac9bb06b6..e335a639b8 100644 --- a/test/Elastica/Multi/SearchTest.php +++ b/test/Elastica/Multi/SearchTest.php @@ -15,7 +15,7 @@ class SearchTest extends BaseTest { - protected function _createIndex(string $name = null, bool $delete = true, int $shards = 1): Index + protected function _createIndex(?string $name = null, bool $delete = true, int $shards = 1): Index { $client = $this->_getClient();