Skip to content

Commit

Permalink
Merge pull request #271 from mailjet/code-styles-adj
Browse files Browse the repository at this point in the history
Code style changes only
  • Loading branch information
oleksandr-mykhailenko authored Jun 11, 2023
2 parents 6125a15 + 4abe78a commit 34bac76
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 64 deletions.
19 changes: 1 addition & 18 deletions src/Mailjet/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class Client

/**
* Client constructor requires:.
*
* @param string $key Mailjet API Key
* @param string|null $secret Mailjet API Secret
* @param bool $call performs the call or not
Expand All @@ -73,7 +72,6 @@ public function __construct(string $key, string $secret = null, bool $call = tru

/**
* Trigger a POST request.
*
* @param array $resource Mailjet Resource/Action pair
* @param array $args Request arguments
* @param array $options
Expand All @@ -96,7 +94,6 @@ public function post(array $resource, array $args = [], array $options = []): Re

/**
* Trigger a GET request.
*
* @param array $resource Mailjet Resource/Action pair
* @param array $args Request arguments
* @param array $options
Expand All @@ -119,7 +116,6 @@ public function get(array $resource, array $args = [], array $options = []): Res

/**
* Trigger a POST request.
*
* @param array $resource Mailjet Resource/Action pair
* @param array $args Request arguments
* @param array $options
Expand All @@ -142,7 +138,6 @@ public function put(array $resource, array $args = [], array $options = []): Res

/**
* Trigger a GET request.
*
* @param array $resource Mailjet Resource/Action pair
* @param array $args Request arguments
* @param array $options
Expand All @@ -165,9 +160,7 @@ public function delete(array $resource, array $args = [], array $options = []):

/**
* Sets if we need to use https or http protocol while using API Url.
*
* @param bool|mixed $bIsSecured True use https / false use http
*
* @return bool true if we set value false otherwise
*/
public function setSecureProtocol($bIsSecured = null): bool
Expand Down Expand Up @@ -229,12 +222,10 @@ public function getConnectionTimeout(): ?int

/**
* Add a HTTP request option.
*
* @param string $key
* @param mixed $value
* [IMPORTANT]Default options will be overwritten
* if such option is provided
*
* @see \GuzzleHttp\RequestOptions for a list of available request options.
*/
public function addRequestOption(string $key, $value): void
Expand All @@ -255,7 +246,6 @@ public function getRequestOptions(): array

/**
* Set auth.
*
* @param string $key
* @param string|null $secret
* @param bool $call
Expand All @@ -279,12 +269,10 @@ public function setAuthentication(string $key, ?string $secret, bool $call, arra

/**
* Magic method to call a mailjet resource.
*
* @param string $method Http method
* @param string $resource mailjet resource
* @param string $action mailjet resource action
* @param array $args Request arguments
*
* @return Response server response
*/
private function _call(string $method, string $resource, string $action, array $args): Response
Expand All @@ -296,7 +284,7 @@ private function _call(string $method, string $resource, string $action, array $
'body' => 'GET' === $method ? null : '{}',
], array_change_key_case($args));

$url = $this->buildURL($resource, $action, (string) $args['id'], $args['actionid']);
$url = $this->buildURL($resource, $action, (string)$args['id'], $args['actionid']);

$contentType = 'application/json';
if ('csvdata/text:plain' === $action) {
Expand Down Expand Up @@ -324,7 +312,6 @@ private function _call(string $method, string $resource, string $action, array $
/**
* Build the base API url depending on wether user need a secure connection
* or not.
*
* @return string the API url;
*/
private function getApiUrl(): string
Expand All @@ -337,7 +324,6 @@ private function getApiUrl(): string
/**
* Checks that both parameters are strings, which means
* that basic authentication will be required.
*
* @param mixed $key
* @param mixed $secret
* @return bool flag
Expand All @@ -349,12 +335,10 @@ private function isBasicAuthentication($key, $secret): bool

/**
* Build the final call url without query strings.
*
* @param string $resource Mailjet resource
* @param string $action Mailjet resource action
* @param string $id mailjet resource id
* @param string $actionid mailjet resource actionid
*
* @return string final call url
*/
private function buildURL(string $resource, string $action, string $id, string $actionid): string
Expand All @@ -376,7 +360,6 @@ private function buildURL(string $resource, string $action, string $id, string $

/**
* Temporary set the variables generating the url.
*
* @param array $options contain temporary modifications for the client
* @param array $resource may contain the version linked to the resource
*/
Expand Down
12 changes: 6 additions & 6 deletions src/Mailjet/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

class Config
{
const WRAPPER_VERSION = 'v2.0.0';
const USER_AGENT = 'mailjet-apiv3-php/';
const MAIN_VERSION = 'v3';
const MAIN_URL = 'api.mailjet.com';
const SECURED = true;
const SMS_VERSION = 'v4';
public const WRAPPER_VERSION = 'v2.0.0';
public const USER_AGENT = 'mailjet-apiv3-php/';
public const MAIN_VERSION = 'v3';
public const MAIN_URL = 'api.mailjet.com';
public const SECURED = true;
public const SMS_VERSION = 'v4';
}
49 changes: 18 additions & 31 deletions src/Mailjet/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class Request
{
use GuzzleClientTrait;

/**
* @var string
*/
Expand Down Expand Up @@ -67,7 +67,6 @@ class Request

/**
* Build a new Http request.
*
* @param array $auth [apikey, apisecret]
* @param string $method http method
* @param string $url call url
Expand All @@ -77,13 +76,13 @@ class Request
* @param array $requestOptions
*/
public function __construct(
array $auth,
array $auth,
string $method,
string $url,
array $filters,
$body,
array $filters,
$body,
string $type,
array $requestOptions = []
array $requestOptions = []
) {
$this->type = $type;
$this->auth = $auth;
Expand All @@ -95,19 +94,16 @@ public function __construct(
$this->guzzleClient = new GuzzleClient(
['defaults' => [
'headers' => [
'user-agent' => Config::USER_AGENT . PHP_VERSION.'/' . Client::WRAPPER_VERSION,
],
]
'user-agent' => Config::USER_AGENT . PHP_VERSION . '/' . Client::WRAPPER_VERSION,
],
],
]
);
}

/**
* Trigger the actual call
* TODO: DATA API.
*
* @param $call
*
* @return Response the call response
*/
public function call($call)
Expand All @@ -125,7 +121,7 @@ public function call($call)
if ($authArgsCount > 1) {
$payload['auth'] = $this->auth;
} else {
$headers['Authorization'] = 'Bearer '.$this->auth[0];
$headers['Authorization'] = 'Bearer ' . $this->auth[0];
}

$payload['headers'] = $headers;
Expand All @@ -151,7 +147,6 @@ public function call($call)

/**
* Filters getters.
*
* @return array Request filters
*/
public function getFilters(): array
Expand All @@ -161,7 +156,6 @@ public function getFilters(): array

/**
* Http method getter.
*
* @return string Request method
*/
public function getMethod(): string
Expand All @@ -171,7 +165,6 @@ public function getMethod(): string

/**
* Call Url getter.
*
* @return string Request Url
*/
public function getUrl(): string
Expand All @@ -181,7 +174,6 @@ public function getUrl(): string

/**
* Request body getter.
*
* @return array request body
*/
public function getBody(): array
Expand All @@ -191,7 +183,6 @@ public function getBody(): array

/**
* Auth getter. to discuss.
*
* @return array Request auth
*/
public function getAuth(): array
Expand All @@ -201,9 +192,8 @@ public function getAuth(): array

/**
* @param RequestInterface $request Request to send
* @param array $options Request options to apply to the given
* @param array $options Request options to apply to the given
* request and to the transfer.
*
* @throws GuzzleException
*/
public function send(RequestInterface $request, array $options = []): ResponseInterface
Expand All @@ -213,9 +203,7 @@ public function send(RequestInterface $request, array $options = []): ResponseIn

/**
* @param RequestInterface $request
*
* @return ResponseInterface
*
* @throws \Psr\Http\Client\ClientExceptionInterface
*/
public function sendRequest(RequestInterface $request): ResponseInterface
Expand All @@ -225,19 +213,18 @@ public function sendRequest(RequestInterface $request): ResponseInterface

/**
* @param RequestInterface $request Request to send
* @param array $options Request options to apply to the given
* @param array $options Request options to apply to the given
* request and to the transfer.
*/
public function sendAsync(RequestInterface $request, array $options = []): PromiseInterface
{
return $this->guzzleClient->sendAsync($request,$options);
return $this->guzzleClient->sendAsync($request, $options);
}

/**
* @param string $method HTTP method.
* @param string|UriInterface $uri URI object or string.
* @param array $options Request options to apply.
*
* @param string $method HTTP method.
* @param string|UriInterface $uri URI object or string.
* @param array $options Request options to apply.
* @throws GuzzleException
*/
public function request(string $method, $uri, array $options = []): ResponseInterface
Expand All @@ -246,9 +233,9 @@ public function request(string $method, $uri, array $options = []): ResponseInte
}

/**
* @param string $method HTTP method
* @param string|UriInterface $uri URI object or string.
* @param array $options Request options to apply.
* @param string $method HTTP method
* @param string|UriInterface $uri URI object or string.
* @param array $options Request options to apply.
*/
public function requestAsync(string $method, $uri, array $options = []): PromiseInterface
{
Expand Down
10 changes: 1 addition & 9 deletions src/Mailjet/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class Response

/**
* Construct a Mailjet response.
*
* @param Request $request Mailjet actual request
* @param Request $request Mailjet actual request
* @param ResponseInterface|null $response Guzzle response
*/
public function __construct(Request $request, ?ResponseInterface $response)
Expand All @@ -61,7 +60,6 @@ public function __construct(Request $request, ?ResponseInterface $response)
/**
* Status Getter
* return the http status code.
*
* @return int|null status
*/
public function getStatus(): ?int
Expand All @@ -81,7 +79,6 @@ public function getBody(): array
/**
* Data Getter
* The data returned by the mailjet call.
*
* @return array data
*/
public function getData(): array
Expand All @@ -101,7 +98,6 @@ public function getCount(): ?int
/**
* Error Reason getter
* return the resulting error message.
*
* @return string|null
*/
public function getReasonPhrase(): ?string
Expand All @@ -112,7 +108,6 @@ public function getReasonPhrase(): ?string
/**
* Total getter
* return the total count of all results.
*
* @return int|null count
*/
public function getTotal(): ?int
Expand All @@ -122,7 +117,6 @@ public function getTotal(): ?int

/**
* Success getter.
*
* @return bool|null true is return code is 2**
*/
public function success(): ?bool
Expand All @@ -137,9 +131,7 @@ public function getRequest(): Request

/**
* Decodes a mailjet string response to an object representing that response.
*
* @param string $body The mailjet response as string
*
* @return array Object representing the mailjet response
*/
protected function decodeBody(string $body): array
Expand Down

0 comments on commit 34bac76

Please sign in to comment.