Clean up code for import routine.

This commit is contained in:
James Cole
2018-03-24 10:35:42 +01:00
parent 310ed9f504
commit 55602d632d
23 changed files with 363 additions and 181 deletions

View File

@@ -71,8 +71,6 @@ use Requests;
* Map accounts to existing accounts
*
* Stage 'do-import'?
*
*
*/
class BunqRoutine implements RoutineInterface
{
@@ -122,8 +120,8 @@ class BunqRoutine implements RoutineInterface
}
/**
*
* @return bool
*
* @throws FireflyException
*/
public function run(): bool
@@ -153,7 +151,7 @@ class BunqRoutine implements RoutineInterface
protected function continueJob()
{
// if in "configuring"
if ($this->getStatus() === 'configuring') {
if ('configuring' === $this->getStatus()) {
Log::debug('Job is in configuring stage, will do nothing.');
return;
@@ -203,7 +201,6 @@ class BunqRoutine implements RoutineInterface
}
/**
*
* @throws FireflyException
*/
protected function runStageInitial()
@@ -372,6 +369,7 @@ class BunqRoutine implements RoutineInterface
* Get the installation token, either from the users preferences or from Bunq.
*
* @return InstallationToken
*
* @throws FireflyException
*/
private function getInstallationToken(): InstallationToken
@@ -477,6 +475,7 @@ class BunqRoutine implements RoutineInterface
* Get the public key of the server, necessary to verify server signature.
*
* @return ServerPublicKey
*
* @throws FireflyException
*/
private function getServerPublicKey(): ServerPublicKey
@@ -573,16 +572,16 @@ class BunqRoutine implements RoutineInterface
$config = $this->getConfig();
$user = new UserPerson($config['user_person']);
$mapping = $config['accounts-mapped'];
$token = new SessionToken($config['session_token']);
$token = new SessionToken($config['session_token']);
$count = 0;
if ($user->getId() === 0) {
if (0 === $user->getId()) {
$user = new UserCompany($config['user_company']);
}
foreach ($config['accounts'] as $accountData) {
$account = new MonetaryAccountBank($accountData);
$importId = $account->getId();
if ($mapping[$importId] === 1) {
if (1 === $mapping[$importId]) {
// grab all transactions
$request = new ListPaymentRequest();
$request->setPrivateKey($this->getPrivateKey());
@@ -610,7 +609,6 @@ class BunqRoutine implements RoutineInterface
}
/**
*
* @throws FireflyException
*/
private function runStageLoggedIn(): void
@@ -619,7 +617,7 @@ class BunqRoutine implements RoutineInterface
$config = $this->getConfig();
$token = new SessionToken($config['session_token']);
$user = new UserPerson($config['user_person']);
if ($user->getId() === 0) {
if (0 === $user->getId()) {
$user = new UserCompany($config['user_company']);
}

View File

@@ -113,7 +113,6 @@ class FileRoutine implements RoutineInterface
$this->addStep();
Log::debug('Back in run()');
Log::debug('Updated job...');
Log::debug(sprintf('%d journals in $storage->journals', $storage->journals->count()));
$this->journals = $storage->journals;

View File

@@ -118,6 +118,7 @@ class SpectreRoutine implements RoutineInterface
*
*
* @return bool
*
* @throws FireflyException
* @throws SpectreException
* @throws \Illuminate\Container\EntryNotFoundException
@@ -166,6 +167,7 @@ class SpectreRoutine implements RoutineInterface
/**
* @return Customer
*
* @throws \FireflyIII\Exceptions\FireflyException
* @throws \FireflyIII\Services\Spectre\Exception\SpectreException
* @throws \Illuminate\Container\EntryNotFoundException
@@ -187,22 +189,21 @@ class SpectreRoutine implements RoutineInterface
$customers = $getCustomerRequest->getCustomers();
/** @var Customer $current */
foreach ($customers as $current) {
if ($current->getIdentifier() === 'default_ff3_customer') {
if ('default_ff3_customer' === $current->getIdentifier()) {
$customer = $current;
break;
}
}
}
Preferences::setForUser($this->job->user, 'spectre_customer', $customer->toArray());
return $customer;
}
/**
* @return Customer
*
* @throws FireflyException
* @throws SpectreException
* @throws \Illuminate\Container\EntryNotFoundException
@@ -232,6 +233,7 @@ class SpectreRoutine implements RoutineInterface
* @param string $returnUri
*
* @return Token
*
* @throws \FireflyIII\Exceptions\FireflyException
* @throws \FireflyIII\Services\Spectre\Exception\SpectreException
* @throws \Illuminate\Container\EntryNotFoundException
@@ -245,7 +247,6 @@ class SpectreRoutine implements RoutineInterface
Log::debug('Call to get token is finished');
return $request->getToken();
}
/**
@@ -460,12 +461,10 @@ class SpectreRoutine implements RoutineInterface
// date:
$importJournal->setValue(['role' => 'date-transaction', 'value' => $transaction->getMadeOn()->toIso8601String()]);
// amount
$importJournal->setValue(['role' => 'amount', 'value' => $transaction->getAmount()]);
$importJournal->setValue(['role' => 'currency-code', 'value' => $transaction->getCurrencyCode()]);
// various meta fields:
$importJournal->setValue(['role' => 'category-name', 'value' => $transaction->getCategory()]);
$importJournal->setValue(['role' => 'note', 'value' => $notes]);
@@ -540,7 +539,7 @@ class SpectreRoutine implements RoutineInterface
foreach ($accounts as $accountArray) {
$account = new Account($accountArray);
$importId = intval($config['accounts-mapped'][$account->getid()] ?? 0);
$doImport = $importId !== 0 ? true : false;
$doImport = 0 !== $importId ? true : false;
if (!$doImport) {
Log::debug(sprintf('Will NOT import from Spectre account #%d ("%s")', $account->getId(), $account->getName()));
continue;
@@ -560,7 +559,6 @@ class SpectreRoutine implements RoutineInterface
Log::debug(sprintf('Total number of transactions: %d', $count));
$this->addStep();
$this->importTransactions($all);
}