From 70593bd79a64c80ba410e7effba679cae15392a2 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sun, 26 Feb 2023 12:34:33 +0100 Subject: [PATCH] Remove deprecations passing $options as int or null --- CHANGELOG.md | 8 ++++++++ src/Index.php | 4 ++-- src/Search.php | 15 +++++++-------- src/SearchableInterface.php | 10 +++++----- tests/IndexTest.php | 14 -------------- tests/QueryBuilder/DSL/QueryTest.php | 1 - 6 files changed, 22 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 485b8fe360..416eec0ee1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Changed return type of `Elastica\Cluster\Health::getActiveShardsPercentAsNumber()` method to `float` [#2144](https://github.com/ruflin/Elastica/pull/2144) * Changed `$origin` and `$scale` parameter types of `Elastica\Query\FunctionScore::addDecayFunction()` to allow `float|int|string` [#2144](https://github.com/ruflin/Elastica/pull/2144) * Changed `$key` parameter type of `Elastica\Multi\Search::addSearch()` to allow `int|string|null` [#2144](https://github.com/ruflin/Elastica/pull/2144) +* Changed `$options` argument to not accept `int` in the following methods [#2148](https://github.com/ruflin/Elastica/pull/2148) + * `Elastica\SearchableInterface::search()` + * `Elastica\SearchableInterface::createSearch()` + * `Elastica\Search::search()` + * `Elastica\Search::createSearch()` + * `Elastica\Search::setOptionsAndQuery()` + * `Elastica\Index::search()` + * `Elastica\Index::createSearch()` ### Added * Added support for PHP 8.2 [#2136](https://github.com/ruflin/Elastica/pull/2136) ### Changed diff --git a/src/Index.php b/src/Index.php index aa99ef3bc6..0e3502121a 100644 --- a/src/Index.php +++ b/src/Index.php @@ -465,7 +465,7 @@ public function exists(): bool /** * {@inheritdoc} */ - public function createSearch($query = '', $options = null, ?BuilderInterface $builder = null): Search + public function createSearch($query = '', ?array $options = null, ?BuilderInterface $builder = null): Search { $search = new Search($this->getClient(), $builder); $search->addIndex($this); @@ -477,7 +477,7 @@ public function createSearch($query = '', $options = null, ?BuilderInterface $bu /** * {@inheritdoc} */ - public function search($query = '', $options = null, string $method = Request::POST): ResultSet + public function search($query = '', ?array $options = null, string $method = Request::POST): ResultSet { $search = $this->createSearch($query, $options); diff --git a/src/Search.php b/src/Search.php index c9114d7ebe..20ee7fde66 100644 --- a/src/Search.php +++ b/src/Search.php @@ -326,12 +326,12 @@ public function getPath(): string * * @phpstan-param TCreateQueryArgs $query * - * @param array|int $options Limit or associative array of options (option=>value) + * @param array|null $options associative array of options (option=>value) * * @throws InvalidException * @throws ResponseException */ - public function search($query = '', $options = null, string $method = Request::POST): ResultSet + public function search($query = '', ?array $options = null, string $method = Request::POST): ResultSet { $this->setOptionsAndQuery($options, $query); @@ -382,29 +382,28 @@ public function count($query = '', bool $fullResult = false, string $method = Re } /** - * @param array|int $options + * @param array|null $options * @param AbstractQuery|AbstractSuggest|array|Collapse|Query|string|Suggest|null $query * * @phpstan-param TCreateQueryArgs $query */ - public function setOptionsAndQuery($options = null, $query = ''): self + public function setOptionsAndQuery(?array $options = null, $query = ''): self { if ('' !== $query) { $this->setQuery($query); } - if (\is_int($options)) { - \trigger_deprecation('ruflin/elastica', '7.1.3', 'Passing an int as 1st argument to "%s()" is deprecated, pass an array with the key "size" instead. It will be removed in 8.0.', __METHOD__); - $this->getQuery()->setSize($options); - } elseif (\is_array($options)) { + if (null !== $options) { if (isset($options['limit'])) { $this->getQuery()->setSize($options['limit']); unset($options['limit']); } + if (isset($options['explain'])) { $this->getQuery()->setExplain($options['explain']); unset($options['explain']); } + $this->setOptions($options); } diff --git a/src/SearchableInterface.php b/src/SearchableInterface.php index 8c71179900..3d38370b27 100644 --- a/src/SearchableInterface.php +++ b/src/SearchableInterface.php @@ -35,10 +35,10 @@ interface SearchableInterface * * @phpstan-param TCreateQueryArgs $query * - * @param array|int|null $options Limit or associative array of options (option=>value) - * @param string $method Request method, see Request's constants + * @param array|null $options associative array of options (option=>value) + * @param string $method Request method, see Request's constants */ - public function search($query = '', $options = null, string $method = Request::POST): ResultSet; + public function search($query = '', ?array $options = null, string $method = Request::POST): ResultSet; /** * Counts results for a query. @@ -60,7 +60,7 @@ public function count($query = '', string $method = Request::POST); * * @phpstan-param TCreateQueryArgs $query * - * @param array|int|null $options + * @param array|null $options */ - public function createSearch($query = '', $options = null): Search; + public function createSearch($query = '', ?array $options = null): Search; } diff --git a/tests/IndexTest.php b/tests/IndexTest.php index 604837d9cb..ebe0a1af06 100644 --- a/tests/IndexTest.php +++ b/tests/IndexTest.php @@ -763,20 +763,6 @@ public function testCreateWithInvalidOption(): void $index->create([], $opts); } - /** - * @group unit - * @group legacy - */ - public function testLegacyCreateSearch(): void - { - $client = $this->createMock(Client::class); - $index = new Index($client, 'test'); - $query = new QueryString('test'); - - $this->expectDeprecation('Since ruflin/elastica 7.1.3: Passing an int as 1st argument to "Elastica\Search::setOptionsAndQuery()" is deprecated, pass an array with the key "size" instead. It will be removed in 8.0.'); - $index->createSearch($query, 5); - } - /** * @group unit */ diff --git a/tests/QueryBuilder/DSL/QueryTest.php b/tests/QueryBuilder/DSL/QueryTest.php index 75d11f82f0..cbe713ecfb 100644 --- a/tests/QueryBuilder/DSL/QueryTest.php +++ b/tests/QueryBuilder/DSL/QueryTest.php @@ -39,7 +39,6 @@ public function testMatch(): void /** * @group unit - * @group legacy */ public function testInterface(): void {