Skip to content

Commit

Permalink
Merge pull request #60 from offline-agency/analysis-M1Z1Y4
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
Giacomo92 authored Nov 3, 2021
2 parents d1c6329 + b1ba494 commit 8c759a2
Showing 1 changed file with 27 additions and 33 deletions.
60 changes: 27 additions & 33 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace OfflineAgency\FattureInCloud;

use Exception;
use Illuminate\Support\Arr;
use OfflineAgency\FattureInCloud\Events\DocumentRequestPerformed;

class Auth
Expand All @@ -12,16 +11,15 @@ class Auth
private $params = [];

/**
* @param string $apiUid
* @param string $apiKey
* @param string $apiUid
* @param string $apiKey
*
* @throws Exception
*/
public function __construct(
string $apiUid = '',
string $apiKey = ''
)
{
) {
$this->attempts = 0;

if (empty($apiUid) || empty($apiKey)) {
Expand All @@ -35,25 +33,24 @@ public function __construct(
}

/**
* @param string $url
* @param array $data
* @param string $method
* @param array $additional_data
* @param string $action
* @param string $type
* @param string $url
* @param array $data
* @param string $method
* @param array $additional_data
* @param string $action
* @param string $type
* @return mixed|object
*/
private function call(
string $url = '',
array $data = [],
array $data = [],
string $method = 'post',
array $additional_data = [],
array $additional_data = [],
string $action = '',
string $type = ''
)
{
) {
try {
$full_url = config('fatture-in-cloud.endpoint') . $url;
$full_url = config('fatture-in-cloud.endpoint').$url;

$options = [
'http' => [
Expand Down Expand Up @@ -91,7 +88,7 @@ private function call(

return $response;
} catch (Exception $e) {
$response = (object)[
$response = (object) [
'error' => $e->getMessage(),
'code' => $e->getCode(),
'success' => false,
Expand All @@ -106,7 +103,7 @@ private function call(
$this->parseHeaders($http_response_header)
));

return (object)[
return (object) [
'error' => $e->getMessage(),
'code' => $e->getCode(),
'success' => false,
Expand All @@ -123,6 +120,7 @@ private function call(
* @param $action
* @param $type
* @return mixed|object
*
* @throws Exception
*/
private function parseResponse(
Expand All @@ -133,8 +131,7 @@ private function parseResponse(
$additional_data,
$action,
$type
)
{
) {
$json = json_decode($response);
if (
isset($json->error)
Expand Down Expand Up @@ -168,6 +165,7 @@ private function parseResponse(
* @param $action
* @param $type
* @return mixed|object
*
* @throws Exception
*/
private function handleThrottle(
Expand All @@ -178,8 +176,7 @@ private function handleThrottle(
$additional_data,
$action,
$type
)
{
) {
$attempts = $this->attempts;
$times = config('fatture-in-cloud.times', 3);

Expand Down Expand Up @@ -211,24 +208,23 @@ private function handleThrottle(
*/
private function getRetrySeconds(
$error_message
)
{
) {
$seconds = 0;
$split_error_message = explode('Attendi ', $error_message);
if (count($split_error_message) > 1) {
$split_error_message = explode(' secondi', $split_error_message[1]);
$seconds = (int)$split_error_message[0];
$seconds = (int) $split_error_message[0];
}

return $seconds * 1000;
}

/**
* @param $path
* @param array $data
* @param array $additional_data
* @param string $action
* @param string $type
* @param array $data
* @param array $additional_data
* @param string $action
* @param string $type
* @return mixed|object
*/
public function post(
Expand All @@ -237,8 +233,7 @@ public function post(
array $additional_data = [],
string $action = '',
string $type = ''
)
{
) {
$params = array_merge($this->params, $data);

return $this->call(
Expand All @@ -256,8 +251,7 @@ public function post(
*/
private function parseHeaders(
$headers
): array
{
): array {
$head = [];
foreach ($headers as $k => $v) {
$t = explode(':', $v, 2);
Expand Down

0 comments on commit 8c759a2

Please sign in to comment.