Description
SearchClient::operationIndex() advertises array|OperationIndexParams as the type for its second argument (see the docblock for operationIndex in lib/Api/SearchClient.php), but passing an OperationIndexParams model object triggers a TypeError at runtime.
Reproduction
php
use Algolia\AlgoliaSearch\Api\SearchClient;
use Algolia\AlgoliaSearch\Model\Search\OperationIndexParams;
use Algolia\AlgoliaSearch\Model\Search\OperationType;
use Algolia\AlgoliaSearch\Model\Search\ScopeType;
$client = SearchClient::create('APP_ID', 'API_KEY');
$client->operationIndex(
'my_index',
(new OperationIndexParams())
->setOperation(OperationType::COPY)
->setDestination('my_index_temp')
->setScope([ScopeType::SETTINGS, ScopeType::SYNONYMS, ScopeType::RULES])
);
Passing an equivalent associative array succeeds, while the model-object variant fails immediately.
Root cause
SearchClient::operationIndexWithHttpInfo() (lib/Api/SearchClient.php, around line 3233) assigns the model directly to $httpBody without serialising it:
$httpBody = $operationIndexParams;
ApiWrapper::request() (lib/RetryStrategy/ApiWrapper.php, line 151) then calls:
$body = isset($data)
? array_merge($data, $requestOptions->getBody())
: $data;
Expected
Either:
- The model-object path is serialised before the transporter sees it, matching the docblock contract; or
- The docblock is corrected to
array only, and the OperationIndexParams model is removed from the public surface of operationIndex().
Environment
- PHP 8.4.17
algolia/algoliasearch-client-php: 4.41.1 (also reproduces on 4.39.1)
Related
Client
Search
Version
4.41.1
Relevant log output
TypeError: array_merge(): Argument #1 must be of type array,
Algolia\AlgoliaSearch\Model\Search\OperationIndexParams given
at vendor/algolia/algoliasearch-client-php/lib/RetryStrategy/ApiWrapper.php:151
/vendor/algolia/algoliasearch-client-php/lib/RetryStrategy/ApiWrapper.php(102): request()
/vendor/algolia/algoliasearch-client-php/lib/Api/SearchClient.php(4624): sendRequestWithHttpInfo()
/vendor/algolia/algoliasearch-client-php/lib/Api/SearchClient.php(3244): operationIndexWithHttpInfo()
/vendor/algolia/algoliasearch-client-php/lib/Api/SearchClient.php(1062): operationIndex()
/vendor/algolia/scout-extended/src/Console/Commands/ReImportCommand.php(68): handle()
Description
SearchClient::operationIndex()advertisesarray|OperationIndexParamsas the type for its second argument (see the docblock foroperationIndexinlib/Api/SearchClient.php), but passing anOperationIndexParamsmodel object triggers aTypeErrorat runtime.Reproduction
Passing an equivalent associative array succeeds, while the model-object variant fails immediately.
Root cause
SearchClient::operationIndexWithHttpInfo()(lib/Api/SearchClient.php, around line 3233) assigns the model directly to$httpBodywithout serialising it:ApiWrapper::request()(lib/RetryStrategy/ApiWrapper.php, line 151) then calls:Expected
Either:
arrayonly, and theOperationIndexParamsmodel is removed from the public surface ofoperationIndex().Environment
algolia/algoliasearch-client-php: 4.41.1 (also reproduces on 4.39.1)Related
Client
Search
Version
4.41.1
Relevant log output