Code cleanup

This commit is contained in:
James Cole
2018-04-02 15:10:40 +02:00
parent fa7ab45a40
commit a3c34e6b3c
151 changed files with 802 additions and 990 deletions

View File

@@ -325,7 +325,7 @@ class BunqRoutine implements RoutineInterface
Log::debug('in convertToAccount()');
// find opposing party by IBAN first.
$result = $this->accountRepository->findByIbanNull($party->getIban(), [$expectedType]);
if (!is_null($result)) {
if (null !== $result) {
Log::debug(sprintf('Search for %s resulted in account %s (#%d)', $party->getIban(), $result->name, $result->id));
return $result;
@@ -334,7 +334,7 @@ class BunqRoutine implements RoutineInterface
// try to find asset account just in case:
if ($expectedType !== AccountType::ASSET) {
$result = $this->accountRepository->findByIbanNull($party->getIban(), [AccountType::ASSET]);
if (!is_null($result)) {
if (nul !== $result) {
Log::debug(sprintf('Search for Asset "%s" resulted in account %s (#%d)', $party->getIban(), $result->name, $result->id));
return $result;
@@ -400,8 +400,6 @@ class BunqRoutine implements RoutineInterface
Preferences::setForUser($this->job->user, 'bunq_private_key', $privKey);
Preferences::setForUser($this->job->user, 'bunq_public_key', $pubKey['key']);
Log::debug('Created and stored key pair');
return;
}
/**
@@ -570,7 +568,7 @@ class BunqRoutine implements RoutineInterface
private function getServerPublicKey(): ServerPublicKey
{
$pref = Preferences::getForUser($this->job->user, 'bunq_server_public_key', null)->data;
if (is_null($pref)) {
if (null === $pref) {
throw new FireflyException('Cannot determine bunq server public key, but should have it at this point.');
}
@@ -721,8 +719,6 @@ class BunqRoutine implements RoutineInterface
// set status to "finished"?
// update job:
$this->setStatus('finished');
return;
}
/**
@@ -778,7 +774,7 @@ class BunqRoutine implements RoutineInterface
// we really have to quit at this point :(
throw new FireflyException($e->getMessage());
}
if (is_null($deviceServerId)) {
if (null === $deviceServerId) {
throw new FireflyException('Was not able to register server with bunq. Please see the log files.');
}
@@ -881,8 +877,6 @@ class BunqRoutine implements RoutineInterface
// update job, set status to "configuring".
$this->setStatus('configuring');
$this->addStep();
return;
}
/**
@@ -893,8 +887,6 @@ class BunqRoutine implements RoutineInterface
private function setConfig(array $config): void
{
$this->repository->setConfiguration($this->job, $config);
return;
}
/**
@@ -905,8 +897,6 @@ class BunqRoutine implements RoutineInterface
private function setExtendedStatus(array $extended): void
{
$this->repository->setExtendedStatus($this->job, $extended);
return;
}
/**

View File

@@ -24,13 +24,13 @@ namespace FireflyIII\Import\Routine;
use Carbon\Carbon;
use DB;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Object\ImportJournal;
use FireflyIII\Import\Storage\ImportStorage;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Services\Spectre\Exception\DuplicatedCustomerException;
use FireflyIII\Services\Spectre\Exception\SpectreException;
use FireflyIII\Services\Spectre\Object\Account;
use FireflyIII\Services\Spectre\Object\Customer;
@@ -179,11 +179,11 @@ class SpectreRoutine implements RoutineInterface
try {
$newCustomerRequest->call();
$customer = $newCustomerRequest->getCustomer();
} catch (DuplicatedCustomerException $e) {
} catch (Exception $e) {
// already exists, must fetch customer instead.
Log::warning('Customer exists already for user, fetch it.');
Log::warning(sprintf('Customer exists already for user, fetch it: %s', $e->getMessage()));
}
if (is_null($customer)) {
if (null === $customer) {
$getCustomerRequest = new ListCustomersRequest($this->job->user);
$getCustomerRequest->call();
$customers = $getCustomerRequest->getCustomers();
@@ -211,7 +211,7 @@ class SpectreRoutine implements RoutineInterface
protected function getCustomer(): Customer
{
$config = $this->getConfig();
if (!is_null($config['customer'])) {
if (null !== $config['customer']) {
$customer = new Customer($config['customer']);
return $customer;
@@ -306,13 +306,13 @@ class SpectreRoutine implements RoutineInterface
/** @var Login $login */
foreach ($logins as $login) {
$attempt = $login->getLastAttempt();
$attemptTime = intval($attempt->getCreatedAt()->format('U'));
if ($attemptTime > $time && is_null($attempt->getFailErrorClass())) {
$attemptTime = (int)$attempt->getCreatedAt()->format('U');
if ($attemptTime > $time && null === $attempt->getFailErrorClass()) {
$time = $attemptTime;
$final = $login;
}
}
if (is_null($final)) {
if (null === $final) {
Log::error('Could not find a valid login for this user.');
$this->repository->addError($this->job, 0, 'Spectre connection failed. Did you use invalid credentials, press Cancel or failed the 2FA challenge?');
$this->repository->setStatus($this->job, 'error');
@@ -420,8 +420,8 @@ class SpectreRoutine implements RoutineInterface
}
$extra = $transaction->getExtra()->toArray();
$notes = '';
$notes .= strval(trans('import.imported_from_account', ['account' => $account->getName()])) . ' '
. "\n"; // double space for newline in Markdown.
// double space for newline in Markdown.
$notes .= (string)trans('import.imported_from_account', ['account' => $account->getName()]) . ' ' . "\n";
foreach ($extra as $key => $value) {
switch ($key) {
@@ -535,8 +535,8 @@ class SpectreRoutine implements RoutineInterface
/** @var array $accountArray */
foreach ($accounts as $accountArray) {
$account = new Account($accountArray);
$importId = intval($config['accounts-mapped'][$account->getId()] ?? 0);
$doImport = 0 !== $importId ? true : false;
$importId = (int)($config['accounts-mapped'][$account->getId()] ?? 0.0);
$doImport = 0 !== $importId;
if (!$doImport) {
Log::debug(sprintf('Will NOT import from Spectre account #%d ("%s")', $account->getId(), $account->getName()));
continue;