Skip to content

Commit

Permalink
Fixed coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed Jan 12, 2018
1 parent d3876db commit 7b19542
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 14 deletions.
37 changes: 31 additions & 6 deletions src/WooCommerce/HttpClient/HttpClient.php
Expand Up @@ -154,10 +154,24 @@ protected function authenticate($url, $method, $parameters = [])
{
// Setup authentication.
if ($this->isSsl()) {
$basicAuth = new BasicAuth($this->ch, $this->consumerKey, $this->consumerSecret, $this->options->isQueryStringAuth(), $parameters);
$basicAuth = new BasicAuth(
$this->ch,
$this->consumerKey,
$this->consumerSecret,
$this->options->isQueryStringAuth(),
$parameters
);
$parameters = $basicAuth->getParameters();
} else {
$oAuth = new OAuth($url, $this->consumerKey, $this->consumerSecret, $this->options->getVersion(), $method, $parameters, $this->options->oauthTimestamp());
$oAuth = new OAuth(
$url,
$this->consumerKey,
$this->consumerSecret,
$this->options->getVersion(),
$method,
$parameters,
$this->options->oauthTimestamp()
);
$parameters = $oAuth->getParameters();
}

Expand All @@ -173,7 +187,7 @@ protected function setupMethod($method)
{
if ('POST' == $method) {
\curl_setopt($this->ch, CURLOPT_POST, true);
} else if (\in_array($method, ['PUT', 'DELETE', 'OPTIONS'])) {
} elseif (\in_array($method, ['PUT', 'DELETE', 'OPTIONS'])) {
\curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $method);
}
}
Expand Down Expand Up @@ -227,7 +241,13 @@ protected function createRequest($endpoint, $method, $data = [], $parameters = [
\curl_setopt($this->ch, CURLOPT_POSTFIELDS, $body);
}

$this->request = new Request($this->buildUrlQuery($url, $parameters), $method, $parameters, $this->getRequestHeaders($hasData), $body);
$this->request = new Request(
$this->buildUrlQuery($url, $parameters),
$method,
$parameters,
$this->getRequestHeaders($hasData),
$body
);

return $this->getRequest();
}
Expand Down Expand Up @@ -325,7 +345,12 @@ protected function lookForErrors($parsedResponse)
$errorCode = $errors->code;
}

throw new HttpClientException(\sprintf('Error: %s [%s]', $errorMessage, $errorCode), $this->response->getCode(), $this->request, $this->response);
throw new HttpClientException(
\sprintf('Error: %s [%s]', $errorMessage, $errorCode),
$this->response->getCode(),
$this->request,
$this->response
);
}
}

Expand All @@ -339,7 +364,7 @@ protected function processResponse()
$body = $this->response->getBody();

if (0 === strpos(bin2hex($body), 'efbbbf')) {
$body = substr($body, 3);
$body = substr($body, 3);
}

$parsedResponse = \json_decode($body);
Expand Down
24 changes: 16 additions & 8 deletions src/WooCommerce/HttpClient/OAuth.php
Expand Up @@ -81,8 +81,15 @@ class OAuth
* @param array $parameters Request parameters.
* @param string $timestamp Timestamp.
*/
public function __construct($url, $consumerKey, $consumerSecret, $apiVersion, $method, $parameters = [], $timestamp = '')
{
public function __construct(
$url,
$consumerKey,
$consumerSecret,
$apiVersion,
$method,
$parameters = [],
$timestamp = ''
) {
$this->url = $url;
$this->consumerKey = $consumerKey;
$this->consumerSecret = $consumerSecret;
Expand Down Expand Up @@ -201,17 +208,18 @@ protected function generateOauthSignature($parameters)
* @param string $key Optional Array key to append
* @return string Array of urlencoded strings
*/
protected function joinWithEqualsSign($params, $queryParams = [], $key = '') {
foreach ( $params as $paramKey => $paramValue ) {
if ( $key ) {
protected function joinWithEqualsSign($params, $queryParams = [], $key = '')
{
foreach ($params as $paramKey => $paramValue) {
if ($key) {
$paramKey = $key . '%5B' . $paramKey . '%5D'; // Handle multi-dimensional array.
}

if ( is_array( $paramValue ) ) {
$queryParams = $this->joinWithEqualsSign( $paramValue, $queryParams, $paramKey );
if (is_array($paramValue)) {
$queryParams = $this->joinWithEqualsSign($paramValue, $queryParams, $paramKey);
} else {
$string = $paramKey . '=' . $paramValue; // Join with equals sign.
$queryParams[] = $this->encode( $string );
$queryParams[] = $this->encode($string);
}
}

Expand Down

0 comments on commit 7b19542

Please sign in to comment.