Skip to content

Commit a1f7642

Browse files
algolia-botdamcou
andcommitted
chore: generated code for commit b000072. [skip ci]
Co-authored-by: Damien Couchez <[email protected]>
1 parent b000072 commit a1f7642

32 files changed

+1627
-636
lines changed

clients/algoliasearch-client-php/lib/Api/AbtestingClient.php

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function __construct(
4848
*/
4949
public static function create($appId = null, $apiKey = null, $region = null)
5050
{
51-
$allowedRegions = ['de', 'us'];
51+
$allowedRegions = self::getAllowedRegions();
5252
$config = AbtestingConfig::create(
5353
$appId,
5454
$apiKey,
@@ -59,6 +59,14 @@ public static function create($appId = null, $apiKey = null, $region = null)
5959
return static::createWithConfig($config);
6060
}
6161

62+
/**
63+
* Returns the allowed regions for the config
64+
*/
65+
public static function getAllowedRegions()
66+
{
67+
return ['de', 'us'];
68+
}
69+
6270
/**
6371
* Instantiate the client with configuration
6472
*
@@ -68,25 +76,40 @@ public static function createWithConfig(AbtestingConfig $config)
6876
{
6977
$config = clone $config;
7078

79+
$apiWrapper = new ApiWrapper(
80+
Algolia::getHttpClient(),
81+
$config,
82+
self::getClusterHosts($config)
83+
);
84+
85+
return new static($apiWrapper, $config);
86+
}
87+
88+
/**
89+
* Gets the cluster hosts depending on the config
90+
*
91+
* @param AbtestingConfig $config
92+
*
93+
* @return ClusterHosts
94+
*/
95+
public static function getClusterHosts(AbtestingConfig $config)
96+
{
7197
if ($hosts = $config->getHosts()) {
7298
// If a list of hosts was passed, we ignore the cache
7399
$clusterHosts = ClusterHosts::create($hosts);
74100
} else {
75-
$url = str_replace(
76-
'{region}',
77-
$config->getRegion(),
78-
'analytics.{region}.algolia.com'
79-
);
101+
$url =
102+
$config->getRegion() !== null && $config->getRegion() !== ''
103+
? str_replace(
104+
'{region}',
105+
$config->getRegion(),
106+
'analytics.{region}.algolia.com'
107+
)
108+
: 'analytics.algolia.com';
80109
$clusterHosts = ClusterHosts::create($url);
81110
}
82111

83-
$apiWrapper = new ApiWrapper(
84-
Algolia::getHttpClient(),
85-
$config,
86-
$clusterHosts
87-
);
88-
89-
return new static($apiWrapper, $config);
112+
return $clusterHosts;
90113
}
91114

92115
/**
@@ -114,12 +137,9 @@ public function getClientConfig()
114137
public function addABTests($addABTestsRequest, $requestOptions = [])
115138
{
116139
// verify the required parameter 'addABTestsRequest' is set
117-
if (
118-
$addABTestsRequest === null ||
119-
(is_array($addABTestsRequest) && count($addABTestsRequest) === 0)
120-
) {
140+
if ($addABTestsRequest === null) {
121141
throw new \InvalidArgumentException(
122-
'Missing the required parameter $addABTestsRequest when calling addABTests'
142+
'Parameter `addABTestsRequest` is required when calling `addABTests`.'
123143
);
124144
}
125145

@@ -154,9 +174,9 @@ public function addABTests($addABTestsRequest, $requestOptions = [])
154174
public function del($path, $parameters = null, $requestOptions = [])
155175
{
156176
// verify the required parameter 'path' is set
157-
if ($path === null || (is_array($path) && count($path) === 0)) {
177+
if ($path === null) {
158178
throw new \InvalidArgumentException(
159-
'Missing the required parameter $path when calling del'
179+
'Parameter `path` is required when calling `del`.'
160180
);
161181
}
162182

@@ -195,9 +215,9 @@ public function del($path, $parameters = null, $requestOptions = [])
195215
public function deleteABTest($id, $requestOptions = [])
196216
{
197217
// verify the required parameter 'id' is set
198-
if ($id === null || (is_array($id) && count($id) === 0)) {
218+
if ($id === null) {
199219
throw new \InvalidArgumentException(
200-
'Missing the required parameter $id when calling deleteABTest'
220+
'Parameter `id` is required when calling `deleteABTest`.'
201221
);
202222
}
203223

@@ -237,9 +257,9 @@ public function deleteABTest($id, $requestOptions = [])
237257
public function get($path, $parameters = null, $requestOptions = [])
238258
{
239259
// verify the required parameter 'path' is set
240-
if ($path === null || (is_array($path) && count($path) === 0)) {
260+
if ($path === null) {
241261
throw new \InvalidArgumentException(
242-
'Missing the required parameter $path when calling get'
262+
'Parameter `path` is required when calling `get`.'
243263
);
244264
}
245265

@@ -278,9 +298,9 @@ public function get($path, $parameters = null, $requestOptions = [])
278298
public function getABTest($id, $requestOptions = [])
279299
{
280300
// verify the required parameter 'id' is set
281-
if ($id === null || (is_array($id) && count($id) === 0)) {
301+
if ($id === null) {
282302
throw new \InvalidArgumentException(
283-
'Missing the required parameter $id when calling getABTest'
303+
'Parameter `id` is required when calling `getABTest`.'
284304
);
285305
}
286306

@@ -362,9 +382,9 @@ public function post(
362382
$requestOptions = []
363383
) {
364384
// verify the required parameter 'path' is set
365-
if ($path === null || (is_array($path) && count($path) === 0)) {
385+
if ($path === null) {
366386
throw new \InvalidArgumentException(
367-
'Missing the required parameter $path when calling post'
387+
'Parameter `path` is required when calling `post`.'
368388
);
369389
}
370390

@@ -413,9 +433,9 @@ public function put(
413433
$requestOptions = []
414434
) {
415435
// verify the required parameter 'path' is set
416-
if ($path === null || (is_array($path) && count($path) === 0)) {
436+
if ($path === null) {
417437
throw new \InvalidArgumentException(
418-
'Missing the required parameter $path when calling put'
438+
'Parameter `path` is required when calling `put`.'
419439
);
420440
}
421441

@@ -458,9 +478,9 @@ public function put(
458478
public function stopABTest($id, $requestOptions = [])
459479
{
460480
// verify the required parameter 'id' is set
461-
if ($id === null || (is_array($id) && count($id) === 0)) {
481+
if ($id === null) {
462482
throw new \InvalidArgumentException(
463-
'Missing the required parameter $id when calling stopABTest'
483+
'Parameter `id` is required when calling `stopABTest`.'
464484
);
465485
}
466486

0 commit comments

Comments
 (0)