Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate bool and null for 2nd argument of Index::create() #1828

Merged
merged 2 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated
* Deprecated Match query class and introduced MatchQuery instead for PHP 8.0 compatibility reason [#1799](https://github.com/ruflin/Elastica/pull/1799)
* Deprecated `version`/`version_type` options [(deprecated in `6.7.0`)](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update.html) and added `if_seq_no` / `if_primary_term` that replaced it
* Deprecated passing `bool` or `null` as 2nd argument to `Elastica\Index::create()` [#1828](https://github.com/ruflin/Elastica/pull/1828)
### Removed
* Removed HHVM proxy detection [#1818](https://github.com/ruflin/Elastica/pull/1818)
### Fixed
Expand Down
12 changes: 8 additions & 4 deletions src/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,16 @@ public function refresh(): Response
*/
public function create(array $args = [], $options = null): Response
{
$options = $options ?? [];

if (\is_bool($options)) {
if (null === $options) {
if (\func_num_args() >= 2) {
@\trigger_error(\sprintf('Passing null as 2nd argument to "%s()" is deprecated since Elastica 7.0.1, avoid passing this argument or pass an array instead.', __METHOD__), \E_USER_DEPRECATED);
}
$options = [];
} elseif (\is_bool($options)) {
@\trigger_error(\sprintf('Passing a bool as 2nd argument to "%s()" is deprecated since Elastica 7.0.1, pass an array with the key "recreate" instead.', __METHOD__), \E_USER_DEPRECATED);
$options = ['recreate' => $options];
} elseif (!\is_array($options)) {
throw new \TypeError(\sprintf('Argument 2 passed to %s::create() must be of type array|bool|null, %s given.', self::class, \is_object($options) ? \get_class($options) : \gettype($options)));
throw new \TypeError(\sprintf('Argument 2 passed to "%s()" must be of type array|bool|null, %s given.', __METHOD__, \is_object($options) ? \get_class($options) : \gettype($options)));
}

$invalidOptions = \array_diff(\array_keys($options), $allowedOptions = [
Expand Down