From 6bfd3cac336317af3b6709649e6f0e17f5d29b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bour?= Date: Tue, 8 Dec 2020 13:14:50 +0100 Subject: [PATCH] style: psr2 --- src/Api.php | 49 ++++++++------------ src/Exceptions/ApiException.php | 1 - src/Exceptions/InvalidParameterException.php | 1 - src/Exceptions/NotLoggedException.php | 1 - 4 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/Api.php b/src/Api.php index 77b189e..bc69d2f 100644 --- a/src/Api.php +++ b/src/Api.php @@ -130,19 +130,14 @@ class Api throw new Exceptions\InvalidParameterException("Endpoint parameter is empty"); } - if (preg_match('/^https?:\/\/..*/',$api_endpoint)) - { - $this->endpoint = $api_endpoint; - } - else - { - if (!array_key_exists($api_endpoint, $this->endpoints)) { - throw new Exceptions\InvalidParameterException("Unknown provided endpoint"); - } - else - { - $this->endpoint = $this->endpoints[$api_endpoint]; - } + if (preg_match('/^https?:\/\/..*/', $api_endpoint)) { + $this->endpoint = $api_endpoint; + } else { + if (!array_key_exists($api_endpoint, $this->endpoints)) { + throw new Exceptions\InvalidParameterException("Unknown provided endpoint"); + } else { + $this->endpoint = $this->endpoints[$api_endpoint]; + } } if (!isset($http_client)) { @@ -228,8 +223,7 @@ class Api */ protected function rawCall($method, $path, $content = null, $is_authenticated = true, $headers = null) { - if ( $is_authenticated ) - { + if ($is_authenticated) { if (!isset($this->application_key)) { throw new Exceptions\InvalidParameterException("Application key parameter is empty"); } @@ -276,14 +270,12 @@ class Api } else { $body = ""; } - if(!is_array($headers)) - { + if (!is_array($headers)) { $headers = []; } $headers['Content-Type'] = 'application/json; charset=utf-8'; if ($is_authenticated) { - $headers['X-Ovh-Application'] = $this->application_key; if (!isset($this->time_delta)) { @@ -331,18 +323,15 @@ class Api */ public function get($path, $content = null, $headers = null, $is_authenticated = true) { - if(preg_match('/^\/[^\/]+\.json$/', $path)) - { - // Schema description must be access without authentication - return $this->decodeResponse( - $this->rawCall("GET", $path, $content, false, $headers) - ); - } - else - { - return $this->decodeResponse( - $this->rawCall("GET", $path, $content, $is_authenticated, $headers) - ); + if (preg_match('/^\/[^\/]+\.json$/', $path)) { + // Schema description must be access without authentication + return $this->decodeResponse( + $this->rawCall("GET", $path, $content, false, $headers) + ); + } else { + return $this->decodeResponse( + $this->rawCall("GET", $path, $content, $is_authenticated, $headers) + ); } } diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index c2b866a..4c8d2e2 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -43,5 +43,4 @@ use Exception; */ class ApiException extends Exception { - } diff --git a/src/Exceptions/InvalidParameterException.php b/src/Exceptions/InvalidParameterException.php index 78902f9..6df582b 100644 --- a/src/Exceptions/InvalidParameterException.php +++ b/src/Exceptions/InvalidParameterException.php @@ -43,5 +43,4 @@ use Exception; */ class InvalidParameterException extends Exception { - } diff --git a/src/Exceptions/NotLoggedException.php b/src/Exceptions/NotLoggedException.php index 23b2f6d..6384fc5 100644 --- a/src/Exceptions/NotLoggedException.php +++ b/src/Exceptions/NotLoggedException.php @@ -42,5 +42,4 @@ use Exception; */ class NotLoggedException extends Exception { - }