Skip to content
Closed
Changes from 1 commit
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
Next Next commit
use PHP8's match expression instead of switch
Signed-off-by: Hamid Dehnavi <[email protected]>
  • Loading branch information
shdehnavi committed Jul 5, 2023
commit 7387ace591fa720acf5c7e023fca55f25cdf8045
27 changes: 8 additions & 19 deletions lib/private/Remote/Api/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,14 @@ protected function request($method, $url, array $body = [], array $query = [], a

$client = $this->getHttpClient();

switch ($method) {
case 'get':
$response = $client->get($fullUrl, $options);
break;
case 'post':
$response = $client->post($fullUrl, $options);
break;
case 'put':
$response = $client->put($fullUrl, $options);
break;
case 'delete':
$response = $client->delete($fullUrl, $options);
break;
case 'options':
$response = $client->options($fullUrl, $options);
break;
default:
throw new \InvalidArgumentException('Invalid method ' . $method);
}
$response = match ($method) {
'get' => $client->get($fullUrl, $options),
'post' => $client->post($fullUrl, $options),
'put' => $client->put($fullUrl, $options),
'delete' => $client->delete($fullUrl, $options),
'options' => $client->options($fullUrl, $options),
default => throw new \InvalidArgumentException('Invalid method ' . $method),
};

return $response->getBody();
}
Expand Down