Code cleanup

This commit is contained in:
James Cole
2018-04-02 14:50:17 +02:00
parent 379b104778
commit fa7ab45a40
100 changed files with 440 additions and 517 deletions

View File

@@ -41,7 +41,7 @@ class Customer extends SpectreObject
*/
public function __construct(array $data)
{
$this->id = intval($data['id']);
$this->id = (int)$data['id'];
$this->identifier = $data['identifier'];
$this->secret = $data['secret'];
}

View File

@@ -84,7 +84,7 @@ class Transaction extends SpectreObject
*/
public function getAmount(): string
{
return strval($this->amount);
return (string)$this->amount;
}
/**
@@ -124,7 +124,7 @@ class Transaction extends SpectreObject
*/
public function getHash(): string
{
$array = [
$array = [
'id' => $this->id,
'mode' => $this->mode,
'status' => $this->status,
@@ -139,9 +139,8 @@ class Transaction extends SpectreObject
'created_at' => $this->createdAt->toIso8601String(),
'updated_at' => $this->updatedAt->toIso8601String(),
];
$hashed = hash('sha256', json_encode($array));
return $hashed;
return hash('sha256', json_encode($array));
}
/**

View File

@@ -136,9 +136,9 @@ class TransactionExtra extends SpectreObject
'id' => $this->id,
'record_number' => $this->recordNumber,
'information' => $this->information,
'time' => is_null($this->time) ? null : $this->time->toIso8601String(),
'posting_date' => is_null($this->postingDate) ? null : $this->postingDate->toIso8601String(),
'posting_time' => is_null($this->postingTime) ? null : $this->postingTime->toIso8601String(),
'time' => null === $this->time ? null : $this->time->toIso8601String(),
'posting_date' => null === $this->postingDate ? null : $this->postingDate->toIso8601String(),
'posting_time' => null === $this->postingTime ? null : $this->postingTime->toIso8601String(),
'account_number' => $this->accountNumber,
'original_amount' => $this->originalAmount,
'original_currency_code' => $this->originalCurrencyCode,

View File

@@ -58,7 +58,7 @@ class ListAccountsRequest extends SpectreRequest
// extract next ID
$hasNextPage = false;
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) {
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
$hasNextPage = true;
$nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -55,7 +55,7 @@ class ListCustomersRequest extends SpectreRequest
// extract next ID
$hasNextPage = false;
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) {
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
$hasNextPage = true;
$nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -58,7 +58,7 @@ class ListLoginsRequest extends SpectreRequest
// extract next ID
$hasNextPage = false;
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) {
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
$hasNextPage = true;
$nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -58,7 +58,7 @@ class ListTransactionsRequest extends SpectreRequest
// extract next ID
$hasNextPage = false;
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) {
if (isset($response['meta']['next_id']) && (int)$response['meta']['next_id'] > $nextId) {
$hasNextPage = true;
$nextId = $response['meta']['next_id'];
Log::debug(sprintf('Next ID is now %d.', $nextId));

View File

@@ -22,12 +22,11 @@ declare(strict_types=1);
namespace FireflyIII\Services\Spectre\Request;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Services\Spectre\Exception\SpectreException;
use FireflyIII\User;
use Log;
use Requests;
use Requests_Exception;
use Requests_Response;
/**
@@ -44,9 +43,9 @@ abstract class SpectreRequest
/** @var string */
protected $serviceSecret = '';
/** @var string */
private $privateKey = '';
private $privateKey;
/** @var string */
private $server = '';
private $server;
/** @var User */
private $user;
@@ -198,11 +197,11 @@ abstract class SpectreRequest
Log::debug('Final headers for spectre signed get request:', $headers);
try {
$response = Requests::get($fullUri, $headers);
} catch (Requests_Exception $e) {
} catch (Exception $e) {
throw new FireflyException(sprintf('Request Exception: %s', $e->getMessage()));
}
$this->detectError($response);
$statusCode = intval($response->status_code);
$statusCode = (int)$response->status_code;
$body = $response->body;
$array = json_decode($body, true);
@@ -241,7 +240,7 @@ abstract class SpectreRequest
Log::debug('Final headers for spectre signed POST request:', $headers);
try {
$response = Requests::post($fullUri, $headers, $body);
} catch (Requests_Exception $e) {
} catch (Exception $e) {
throw new FireflyException(sprintf('Request Exception: %s', $e->getMessage()));
}
$this->detectError($response);
@@ -274,7 +273,7 @@ abstract class SpectreRequest
throw new FireflyException(sprintf('Error of class %s: %s', $errorClass, $message));
}
$statusCode = intval($response->status_code);
$statusCode = (int)$response->status_code;
if (200 !== $statusCode) {
throw new FireflyException(sprintf('Status code %d: %s', $statusCode, $response->body));
}