Skip to content

Commit

Permalink
Fix deprecated class instantiation warnings (#295)
Browse files Browse the repository at this point in the history
* Fix some deprecation warnings

Signed-off-by: Kim Pepper <[email protected]>

* Generate API

Signed-off-by: Kim Pepper <[email protected]>

* Move the deprecation trigger to the methods

Signed-off-by: Kim Pepper <[email protected]>

---------

Signed-off-by: Kim Pepper <[email protected]>
  • Loading branch information
kimpepper authored Feb 11, 2025
1 parent ae12b9e commit ce3d284
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 105 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Security
### Dependencies
### Updated APIs
- Updated opensearch-php APIs to reflect [opensearch-api-specification@22483a2](https://github.com/opensearch-project/opensearch-api-specification/commit/22483a2bdfe1022611b1de7db5f45af9289a8654)

## [2.4.1]
### Added
Expand Down Expand Up @@ -47,6 +48,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed PHP 8.4 deprecations ([#229](https://github.com/opensearch-project/opensearch-php/pull/229))
- Fixed outdated tests ([#245](https://github.com/opensearch-project/opensearch-php/pull/245))
### Updated APIs
- Updated opensearch-php APIs to reflect [opensearch-api-specification@22483a2](https://github.com/opensearch-project/opensearch-api-specification/commit/22483a2bdfe1022611b1de7db5f45af9289a8654)
- Updated opensearch-php APIs to reflect [opensearch-api-specification@b9dcb25](https://github.com/opensearch-project/opensearch-api-specification/commit/b9dcb251d551e90ecfc416ba134efe83cbcbc1b3)
- Updated opensearch-php APIs to reflect [opensearch-api-specification@9df46f8](https://github.com/opensearch-project/opensearch-api-specification/commit/9df46f8134641ae5b429e3e9269858c7cb27e4f0)
- Updated opensearch-php APIs to reflect [opensearch-api-specification@592336a](https://github.com/opensearch-project/opensearch-api-specification/commit/592336afb88844f0c5785ba4b085dba3884ac580)
Expand Down
80 changes: 0 additions & 80 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,85 +1,5 @@
parameters:
ignoreErrors:
-
message: """
#^Instantiation of deprecated class OpenSearch\\\\Namespaces\\\\AsyncSearchNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\. Use AsynchronousSearchNamespace instead\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Instantiation of deprecated class OpenSearch\\\\Namespaces\\\\DataFrameTransformDeprecatedNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Instantiation of deprecated class OpenSearch\\\\Namespaces\\\\MonitoringNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Instantiation of deprecated class OpenSearch\\\\Namespaces\\\\SearchableSnapshotsNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Instantiation of deprecated class OpenSearch\\\\Namespaces\\\\SslNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\. Use SslNamespace instead\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Return type of method OpenSearch\\\\Client\\:\\:asyncSearch\\(\\) has typehint with deprecated class OpenSearch\\\\Namespaces\\\\AsyncSearchNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\. Use AsynchronousSearchNamespace instead\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Return type of method OpenSearch\\\\Client\\:\\:dataFrameTransformDeprecated\\(\\) has typehint with deprecated class OpenSearch\\\\Namespaces\\\\DataFrameTransformDeprecatedNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Return type of method OpenSearch\\\\Client\\:\\:monitoring\\(\\) has typehint with deprecated class OpenSearch\\\\Namespaces\\\\MonitoringNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Return type of method OpenSearch\\\\Client\\:\\:searchableSnapshots\\(\\) has typehint with deprecated class OpenSearch\\\\Namespaces\\\\SearchableSnapshotsNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Return type of method OpenSearch\\\\Client\\:\\:ssl\\(\\) has typehint with deprecated class OpenSearch\\\\Namespaces\\\\SslNamespace\\:
in 2\\.4\\.0 and will be removed in 3\\.0\\.0\\. Use SslNamespace instead\\.$#
"""
count: 1
path: src/OpenSearch/Client.php

-
message: """
#^Instantiation of deprecated class OpenSearch\\\\Common\\\\Exceptions\\\\InvalidArgumentException\\:
Expand Down
32 changes: 31 additions & 1 deletion src/OpenSearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class Client

/**
* @var AsyncSearchNamespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
protected $asyncSearch;

Expand All @@ -165,6 +167,8 @@ class Client

/**
* @var DataFrameTransformDeprecatedNamespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
protected $dataFrameTransformDeprecated;

Expand Down Expand Up @@ -210,6 +214,8 @@ class Client

/**
* @var MonitoringNamespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
protected $monitoring;

Expand Down Expand Up @@ -260,6 +266,8 @@ class Client

/**
* @var SearchableSnapshotsNamespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
protected $searchableSnapshots;

Expand All @@ -285,6 +293,8 @@ class Client

/**
* @var SslNamespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
protected $ssl;

Expand Down Expand Up @@ -340,11 +350,13 @@ public function __construct(
// @phpstan-ignore property.deprecated
$this->endpoints = $endpoints;
$this->endpointFactory = $endpointFactory;
// @phpstan-ignore new.deprecated, property.deprecated
$this->asyncSearch = new AsyncSearchNamespace($transport, $this->endpointFactory);
$this->asynchronousSearch = new AsynchronousSearchNamespace($transport, $this->endpointFactory);
$this->cat = new CatNamespace($transport, $this->endpointFactory);
$this->cluster = new ClusterNamespace($transport, $this->endpointFactory);
$this->danglingIndices = new DanglingIndicesNamespace($transport, $this->endpointFactory);
// @phpstan-ignore new.deprecated, property.deprecated
$this->dataFrameTransformDeprecated = new DataFrameTransformDeprecatedNamespace($transport, $this->endpointFactory);
$this->flowFramework = new FlowFrameworkNamespace($transport, $this->endpointFactory);
$this->indices = new IndicesNamespace($transport, $this->endpointFactory);
Expand All @@ -354,6 +366,7 @@ public function __construct(
$this->knn = new KnnNamespace($transport, $this->endpointFactory);
$this->list = new ListNamespace($transport, $this->endpointFactory);
$this->ml = new MlNamespace($transport, $this->endpointFactory);
// @phpstan-ignore new.deprecated, property.deprecated
$this->monitoring = new MonitoringNamespace($transport, $this->endpointFactory);
$this->nodes = new NodesNamespace($transport, $this->endpointFactory);
$this->notifications = new NotificationsNamespace($transport, $this->endpointFactory);
Expand All @@ -364,11 +377,13 @@ public function __construct(
$this->replication = new ReplicationNamespace($transport, $this->endpointFactory);
$this->rollups = new RollupsNamespace($transport, $this->endpointFactory);
$this->searchPipeline = new SearchPipelineNamespace($transport, $this->endpointFactory);
// @phpstan-ignore new.deprecated, property.deprecated
$this->searchableSnapshots = new SearchableSnapshotsNamespace($transport, $this->endpointFactory);
$this->security = new SecurityNamespace($transport, $this->endpointFactory);
$this->sm = new SmNamespace($transport, $this->endpointFactory);
$this->snapshot = new SnapshotNamespace($transport, $this->endpointFactory);
$this->sql = new SqlNamespace($transport, $this->endpointFactory);
// @phpstan-ignore new.deprecated, property.deprecated
$this->ssl = new SslNamespace($transport, $this->endpointFactory);
$this->tasks = new TasksNamespace($transport, $this->endpointFactory);
$this->transforms = new TransformsNamespace($transport, $this->endpointFactory);
Expand Down Expand Up @@ -666,7 +681,7 @@ public function deleteByQuery(array $params = [])
/**
* Changes the number of requests per second for a particular Delete By Query operation.
*
* $params['task_id'] = (number) The ID for the task. (Required)
* $params['task_id'] = (string) The ID for the task. (Required)
* $params['requests_per_second'] = (number) The throttle for this request in sub-requests per second.
* $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false)
* $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true)
Expand Down Expand Up @@ -1844,9 +1859,12 @@ public function deletePointInTime(array $params = [])
}
/**
* Returns the asyncSearch namespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
public function asyncSearch(): AsyncSearchNamespace
{
@trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED);
return $this->asyncSearch;
}
/**
Expand Down Expand Up @@ -1879,9 +1897,12 @@ public function danglingIndices(): DanglingIndicesNamespace
}
/**
* Returns the dataFrameTransformDeprecated namespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
public function dataFrameTransformDeprecated(): DataFrameTransformDeprecatedNamespace
{
@trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED);
return $this->dataFrameTransformDeprecated;
}
/**
Expand Down Expand Up @@ -1942,9 +1963,12 @@ public function ml(): MlNamespace
}
/**
* Returns the monitoring namespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
public function monitoring(): MonitoringNamespace
{
@trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED);
return $this->monitoring;
}
/**
Expand Down Expand Up @@ -2012,9 +2036,12 @@ public function searchPipeline(): SearchPipelineNamespace
}
/**
* Returns the searchableSnapshots namespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
public function searchableSnapshots(): SearchableSnapshotsNamespace
{
@trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED);
return $this->searchableSnapshots;
}
/**
Expand Down Expand Up @@ -2047,9 +2074,12 @@ public function sql(): SqlNamespace
}
/**
* Returns the ssl namespace
*
* @deprecated in 2.4.2 and will be removed in 3.0.0.
*/
public function ssl(): SslNamespace
{
@trigger_error(__METHOD__ . '() is deprecated since 2.4.2 and will be removed in 3.0.0.', E_USER_DEPRECATED);
return $this->ssl;
}
/**
Expand Down
72 changes: 72 additions & 0 deletions src/OpenSearch/Endpoints/Ml/ExecuteAlgorithm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

/**
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

namespace OpenSearch\Endpoints\Ml;

use OpenSearch\Exception\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

/**
* NOTE: This file is autogenerated using util/GenerateEndpoints.php
*/
class ExecuteAlgorithm extends AbstractEndpoint
{
protected $algorithm_name;

public function getURI(): string
{
$algorithm_name = $this->algorithm_name ?? null;
if (isset($algorithm_name)) {
return "/_plugins/_ml/_execute/$algorithm_name";
}
throw new RuntimeException('Missing parameter for the endpoint ml.execute_algorithm');
}

public function getParamWhitelist(): array
{
return [
'pretty',
'human',
'error_trace',
'source',
'filter_path'
];
}

public function getMethod(): string
{
return 'POST';
}

public function setBody($body): static
{
if (is_null($body)) {
return $this;
}
$this->body = $body;

return $this;
}

public function setAlgorithmName($algorithm_name): static
{
if (is_null($algorithm_name)) {
return $this;
}
$this->algorithm_name = $algorithm_name;

return $this;
}
}
3 changes: 0 additions & 3 deletions src/OpenSearch/Namespaces/AsyncSearchNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

namespace OpenSearch\Namespaces;

// @phpstan-ignore classConstant.deprecatedClass
@trigger_error(AsyncSearchNamespace::class . ' is deprecated in 2.4.0 and will be removed in 3.0.0. Use AsynchronousSearchNamespace instead.', E_USER_DEPRECATED);

/**
* Class AsyncSearchNamespace
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

namespace OpenSearch\Namespaces;

// @phpstan-ignore classConstant.deprecatedClass
@trigger_error(DataFrameTransformDeprecatedNamespace::class . ' is deprecated in 2.4.0 and will be removed in 3.0.0.', E_USER_DEPRECATED);

/**
* Class DataFrameTransformDeprecatedNamespace
*
Expand Down
27 changes: 27 additions & 0 deletions src/OpenSearch/Namespaces/MlNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use OpenSearch\Endpoints\Ml\DeleteTask;
use OpenSearch\Endpoints\Ml\DeployModel;
use OpenSearch\Endpoints\Ml\ExecuteAgent;
use OpenSearch\Endpoints\Ml\ExecuteAlgorithm;
use OpenSearch\Endpoints\Ml\GetAgent;
use OpenSearch\Endpoints\Ml\GetAllMemories;
use OpenSearch\Endpoints\Ml\GetAllMessages;
Expand Down Expand Up @@ -380,6 +381,32 @@ public function executeAgent(array $params = [])
return $this->performRequest($endpoint);
}

/**
* Execute an algorithm.
*
* $params['algorithm_name'] = (string)
* $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false)
* $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true)
* $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false)
* $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests.
* $params['filter_path'] = (any) Used to reduce the response. This parameter takes a comma-separated list of filters. It supports using wildcards to match any field or part of a field’s name. You can also exclude fields with "-".
*
* @param array $params Associative array of parameters
* @return array
*/
public function executeAlgorithm(array $params = [])
{
$algorithm_name = $this->extractArgument($params, 'algorithm_name');
$body = $this->extractArgument($params, 'body');

$endpoint = $this->endpointFactory->getEndpoint(ExecuteAlgorithm::class);
$endpoint->setParams($params);
$endpoint->setAlgorithmName($algorithm_name);
$endpoint->setBody($body);

return $this->performRequest($endpoint);
}

/**
* Get an agent.
*
Expand Down
Loading

0 comments on commit ce3d284

Please sign in to comment.