1
0
mirror of https://github.com/ovh/php-ovh.git synced 2023-11-05 03:20:26 +01:00

style: psr2

This commit is contained in:
Stéphane Bour 2020-12-08 13:14:50 +01:00
parent f322f6a819
commit 6bfd3cac33
No known key found for this signature in database
GPG Key ID: 2CEC3F826D073CA7
4 changed files with 19 additions and 33 deletions

View File

@ -130,17 +130,12 @@ class Api
throw new Exceptions\InvalidParameterException("Endpoint parameter is empty"); throw new Exceptions\InvalidParameterException("Endpoint parameter is empty");
} }
if (preg_match('/^https?:\/\/..*/',$api_endpoint)) if (preg_match('/^https?:\/\/..*/', $api_endpoint)) {
{
$this->endpoint = $api_endpoint; $this->endpoint = $api_endpoint;
} } else {
else
{
if (!array_key_exists($api_endpoint, $this->endpoints)) { if (!array_key_exists($api_endpoint, $this->endpoints)) {
throw new Exceptions\InvalidParameterException("Unknown provided endpoint"); throw new Exceptions\InvalidParameterException("Unknown provided endpoint");
} } else {
else
{
$this->endpoint = $this->endpoints[$api_endpoint]; $this->endpoint = $this->endpoints[$api_endpoint];
} }
} }
@ -228,8 +223,7 @@ class Api
*/ */
protected function rawCall($method, $path, $content = null, $is_authenticated = true, $headers = null) protected function rawCall($method, $path, $content = null, $is_authenticated = true, $headers = null)
{ {
if ( $is_authenticated ) if ($is_authenticated) {
{
if (!isset($this->application_key)) { if (!isset($this->application_key)) {
throw new Exceptions\InvalidParameterException("Application key parameter is empty"); throw new Exceptions\InvalidParameterException("Application key parameter is empty");
} }
@ -276,14 +270,12 @@ class Api
} else { } else {
$body = ""; $body = "";
} }
if(!is_array($headers)) if (!is_array($headers)) {
{
$headers = []; $headers = [];
} }
$headers['Content-Type'] = 'application/json; charset=utf-8'; $headers['Content-Type'] = 'application/json; charset=utf-8';
if ($is_authenticated) { if ($is_authenticated) {
$headers['X-Ovh-Application'] = $this->application_key; $headers['X-Ovh-Application'] = $this->application_key;
if (!isset($this->time_delta)) { if (!isset($this->time_delta)) {
@ -331,15 +323,12 @@ class Api
*/ */
public function get($path, $content = null, $headers = null, $is_authenticated = true) public function get($path, $content = null, $headers = null, $is_authenticated = true)
{ {
if(preg_match('/^\/[^\/]+\.json$/', $path)) if (preg_match('/^\/[^\/]+\.json$/', $path)) {
{
// Schema description must be access without authentication // Schema description must be access without authentication
return $this->decodeResponse( return $this->decodeResponse(
$this->rawCall("GET", $path, $content, false, $headers) $this->rawCall("GET", $path, $content, false, $headers)
); );
} } else {
else
{
return $this->decodeResponse( return $this->decodeResponse(
$this->rawCall("GET", $path, $content, $is_authenticated, $headers) $this->rawCall("GET", $path, $content, $is_authenticated, $headers)
); );

View File

@ -43,5 +43,4 @@ use Exception;
*/ */
class ApiException extends Exception class ApiException extends Exception
{ {
} }

View File

@ -43,5 +43,4 @@ use Exception;
*/ */
class InvalidParameterException extends Exception class InvalidParameterException extends Exception
{ {
} }

View File

@ -42,5 +42,4 @@ use Exception;
*/ */
class NotLoggedException extends Exception class NotLoggedException extends Exception
{ {
} }