Skip to content

Commit

Permalink
Removed more deprecated code, refactored deprecation warnings to accu…
Browse files Browse the repository at this point in the history
…rately point to the source, fixed tests
  • Loading branch information
Radiergummi committed May 15, 2024
1 parent 2d09adb commit f3ab172
Show file tree
Hide file tree
Showing 31 changed files with 493 additions and 631 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,7 @@ $documents->url($page)

### Getting the query array without execution
```php
ES::type("my_type")->search("hello")->where("views", ">", 150)->query();
ES::type("my_type")->search("hello")->where("views", ">", 150)->toArray();
```

### Getting the original elasticsearch response
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/CreateIndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,14 @@ public function handle(ConnectionResolverInterface $resolver): void
}

if (isset($config['mappings'])) {
foreach ($config['mappings'] as $type => $mapping) {
foreach ($config['mappings'] as $mapping) {
$this->info(
"Creating mapping for type: {$type} in index: {$index}"
"Creating mapping for index: {$index}"
);

// Create mapping for type from config file
$client->indices()->putMapping([
'index' => $index,
'type' => $type,
'body' => $mapping,
'include_type_name' => true,
]);
Expand Down
5 changes: 2 additions & 3 deletions src/Commands/UpdateIndexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ public function handle(ConnectionResolverInterface $resolver): void

// Create mapping for type from config file
if (isset($config['mappings'])) {
foreach ($config['mappings'] as $type => $mapping) {
foreach ($config['mappings'] as $mapping) {
$this->info(
"Creating mapping for type: {$type} in index: {$index}"
"Creating mapping for index: {$index}"
);

$client->indices()->putMapping([
'index' => $index,
'type' => $type,
'body' => $mapping,
]);
}
Expand Down
86 changes: 0 additions & 86 deletions src/Concerns/BuildsFluentQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Closure;
use InvalidArgumentException;
use JetBrains\PhpStorm\Deprecated;
use Matchory\Elasticsearch\Classes\Search;
use Matchory\Elasticsearch\Model;
use Matchory\Elasticsearch\Query;
Expand Down Expand Up @@ -276,28 +275,6 @@ trait BuildsFluentQueries
*/
protected array|null $source = null;

/**
* Mapping type
*
* Each document indexed is associated with a `_type` and an `_id`.
* The `_type` field is indexed in order to make searching by type name fast
* The value of the `_type` field is accessible in queries, aggregations,
* scripts, and when sorting.
* Note that mapping types are deprecated as of 6.0.0:
* Indices created in Elasticsearch 7.0.0 or later no longer accept a
* `_default_` mapping. Indices created in 6.x will continue to function as
* before in Elasticsearch 6.x. Types are deprecated in APIs in 7.0, with
* breaking changes to the index creation, put mapping, get mapping, put
* template, get template and get field mappings APIs.
*
* @var string|null
* @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0
* @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html
* @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/mapping-type-field.html
*/
#[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')]
protected string|null $type = null;

/**
* Retrieves the ID the query is restricted to.
*
Expand Down Expand Up @@ -355,36 +332,6 @@ public function getSearchType(): string|null
return $this->searchType;
}

/**
* Retrieves the document mapping type the query is restricted to.
*
* @return string|null
* @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0
* @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html
*/
#[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')]
public function getType(): string|null
{
/**
* @noinspection PhpDeprecationInspection
* @psalm-suppress DeprecatedProperty
*/
return $this->type;
}

/**
* @param string|null $id ID to filter by
*
* @return $this
* @deprecated Use id() instead
* @see Query::id()
*/
#[Deprecated(replacement: '%class%->id(%parameter0%)')]
public function _id(string|null $id = null): static
{
return $this->id($id);
}

/**
* Adds a term filter for the `_id` field.
*
Expand Down Expand Up @@ -1156,27 +1103,6 @@ public function take(int $size = Query::DEFAULT_LIMIT): static
return $this;
}

/**
* Sets the document mapping type to restrict the query to.
*
* @param string $type Name of the document mapping type
*
* @return $this
* @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0
* @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html
*/
#[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')]
public function type(string $type): static
{
/**
* @noinspection PhpDeprecationInspection
* @psalm-suppress DeprecatedProperty
*/
$this->type = $type;

return $this;
}

/**
* Set the ignored fields to not be returned
*
Expand Down Expand Up @@ -1507,18 +1433,6 @@ protected function getSkip(): int
return $this->from;
}

/**
* Get the query limit
*
* @return int
* @deprecated Use getSize() instead
*/
#[Deprecated(replacement: '%class%->getSize()')]
protected function getTake(): int
{
return $this->getSize();
}

/**
* Retrieves the number of hits to limit the query to.
*
Expand Down
14 changes: 0 additions & 14 deletions src/Concerns/ExecutesQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use DateTime;
use Illuminate\Support\Facades\Request;
use JetBrains\PhpStorm\Deprecated;
use JsonException;
use Matchory\Elasticsearch\Classes\Bulk;
use Matchory\Elasticsearch\Collection;
Expand Down Expand Up @@ -629,19 +628,6 @@ public function paginate(
);
}

/**
* Keeping around for backwards compatibility
*
* @return array
* @deprecated Use toArray() instead
* @see Query::toArray()
*/
#[Deprecated(replacement: '%class%->toArray()')]
public function query(): array
{
return $this->toArray();
}

/**
* Indicate that the query results should be cached forever.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/ManagesIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ trait ManagesIndices
*
* @return array
*/
public function createIndex(string $name, ?callable $callback = null): array
public function createIndex(string $name, callable|null $callback = null): array
{
$index = new Index($name, $callback);

Expand All @@ -35,7 +35,7 @@ public function createIndex(string $name, ?callable $callback = null): array
* @throws RuntimeException
* @see Query::createIndex()
*/
public function create(?callable $callback = null): array
public function create(callable|null $callback = null): array
{
$index = $this->getIndex();

Expand Down
88 changes: 53 additions & 35 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@

use function assert;
use function json_encode;
use function trigger_deprecation;
use function sprintf;
use function trigger_error;

use const E_USER_DEPRECATED;
use const JSON_THROW_ON_ERROR;

/**
Expand Down Expand Up @@ -126,6 +128,16 @@ final public function __construct(
#[Deprecated]
public static function setConnectionResolver(Resolver $resolver): void
{
@trigger_error(
sprintf(
'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' .
'Use the connection manager to create connections instead. It provides a simpler ' .
'way to manage connections. This method will be removed in the next major version.',
__METHOD__
),
E_USER_DEPRECATED
);

static::$resolver = $resolver;
}

Expand All @@ -145,12 +157,14 @@ public static function configureLogging(
ClientBuilder $clientBuilder,
array $config
): ClientBuilder {
trigger_deprecation(
'matchory/elasticsearch',
'3.0.0',
'The %s method is deprecated. Use the connection manager to create connections instead. It provides a ' .
'simpler way to manage connections. This method will be removed in the next major version.',
__METHOD__
@trigger_error(
sprintf(
'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' .
'Use the connection manager to create connections instead. It provides a simpler ' .
'way to manage connections. This method will be removed in the next major version.',
__METHOD__
),
E_USER_DEPRECATED
);

if (Arr::get($config, 'logging.enabled')) {
Expand Down Expand Up @@ -184,12 +198,14 @@ public static function configureLogging(
#[Deprecated(reason: 'Use the connection manager to create connections instead.')]
public static function create(mixed $config): Query
{
trigger_deprecation(
'matchory/elasticsearch',
'3.0.0',
'The %s method is deprecated. Use the connection manager to create connections instead. It provides a ' .
'simpler way to manage connections. This method will be removed in the next major version.',
__METHOD__
@trigger_error(
sprintf(
'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' .
'Use the connection manager to create connections instead. It provides a simpler ' .
'way to manage connections. This method will be removed in the next major version.',
__METHOD__
),
E_USER_DEPRECATED
);

$app = App::getFacadeApplication();
Expand Down Expand Up @@ -218,10 +234,6 @@ public function insert(
$parameters[Query::PARAM_INDEX] = $index;
}

if ($type) {
$parameters[Query::PARAM_TYPE] = $type;
}

if ($this->reportQueries) {
$this->reportQuery($parameters);
}
Expand Down Expand Up @@ -278,12 +290,14 @@ public function newQuery(string|null $connection = null): Query
// TODO: This is deprecated behaviour and should be removed in the next
// major version.
if ($connection) {
trigger_deprecation(
'matchory/elasticsearch',
'3.0.0',
'Passing the connection name to %s is deprecated. Use the proper connection instance directly ' .
'instead. This parameter will be removed in the next major version.',
__METHOD__
@trigger_error(
sprintf(
'Passing the connection name to %s is deprecated. ' .
'Use the proper connection instance directly instead. ' .
'This parameter will be removed in the next major version.',
__METHOD__
),
E_USER_DEPRECATED
);

/** @noinspection PhpDeprecationInspection */
Expand All @@ -307,12 +321,14 @@ public function newQuery(string|null $connection = null): Query
#[Deprecated(reason: 'Use the connection manager to create connections instead.')]
public function connection(string $name): Query
{
trigger_deprecation(
'matchory/elasticsearch',
'3.0.0',
'The %s method is deprecated. Use the connection manager to create connections instead. It provides a ' .
'simpler way to manage connections. This method will be removed in the next major version.',
__METHOD__
@trigger_error(
sprintf(
'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' .
'Use the connection manager to create connections instead. It provides a simpler ' .
'way to manage connections. This method will be removed in the next major version.',
__METHOD__
),
E_USER_DEPRECATED
);

return $this->newQuery($name);
Expand Down Expand Up @@ -367,12 +383,14 @@ public function __call(string $name, array $arguments)
#[Deprecated(reason: 'Use the connection manager to create connections instead.')]
public function isLoaded(string $name): bool
{
trigger_deprecation(
'matchory/elasticsearch',
'3.0.0',
'The %s method is deprecated. Use the connection manager to create connections instead. It provides a ' .
'simpler way to manage connections. This method will be removed in the next major version.',
__METHOD__
@trigger_error(
sprintf(
'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' .
'Use the connection manager to create connections instead. It provides a simpler ' .
'way to manage connections. This method will be removed in the next major version.',
__METHOD__
),
E_USER_DEPRECATED
);

return (bool)static::$resolver->connection($name);
Expand Down
4 changes: 2 additions & 2 deletions src/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ConnectionManager implements ConnectionResolverInterface
public function __construct(
protected array $configuration,
protected readonly ClientFactoryInterface $clientFactory,
protected readonly ?CacheInterface $cache = null,
protected readonly CacheInterface|null $cache = null,
) {
}

Expand All @@ -77,7 +77,7 @@ public function __call(string $method, array $parameters)
* @return ConnectionInterface
* @throws InvalidArgumentException
*/
public function connection(?string $name = null): ConnectionInterface
public function connection(string|null $name = null): ConnectionInterface
{
if (is_null($name)) {
$name = $this->getDefaultConnection();
Expand Down
Loading

0 comments on commit f3ab172

Please sign in to comment.