Skip to content

Commit

Permalink
Remove deprecations passing $options as int or null
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Feb 27, 2023
1 parent cec3102 commit 70593bd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 30 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
15 changes: 7 additions & 8 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed>|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);

Expand Down Expand Up @@ -382,29 +382,28 @@ public function count($query = '', bool $fullResult = false, string $method = Re
}

/**
* @param array|int $options
* @param array<string, mixed>|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);
}

Expand Down
10 changes: 5 additions & 5 deletions src/SearchableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed>|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.
Expand All @@ -60,7 +60,7 @@ public function count($query = '', string $method = Request::POST);
*
* @phpstan-param TCreateQueryArgs $query
*
* @param array|int|null $options
* @param array<string, mixed>|null $options
*/
public function createSearch($query = '', $options = null): Search;
public function createSearch($query = '', ?array $options = null): Search;
}
14 changes: 0 additions & 14 deletions tests/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 0 additions & 1 deletion tests/QueryBuilder/DSL/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function testMatch(): void

/**
* @group unit
* @group legacy
*/
public function testInterface(): void
{
Expand Down

0 comments on commit 70593bd

Please sign in to comment.