James Cole 2 years ago
parent
commit
594a9f487a
No known key found for this signature in database GPG Key ID: B49A324B7EAD6D80
  1. 6
      .ci/phpstan.neon
  2. 4
      app/Console/AutoImports.php
  3. 2
      app/Console/Commands/AutoImport.php
  4. 2
      app/Console/Commands/Import.php
  5. 2
      app/Console/HaveAccess.php
  6. 37
      app/Services/Shared/Model/ImportServiceAccount.php
  7. 14
      app/Services/Spectre/Model/TransactionExtra.php
  8. 2
      app/Support/Internal/MergesAccountLists.php
  9. 22
      resources/views/import/004-configure/partials/account-title-generic.twig
  10. 23
      resources/views/import/004-configure/partials/account-title-nordigen.twig
  11. 17
      resources/views/import/004-configure/partials/account-title-spectre.twig
  12. 13
      resources/views/import/004-configure/partials/ff3-account-nordigen.twig
  13. 11
      resources/views/import/004-configure/partials/ff3-account-spectre.twig

6
.ci/phpstan.neon

@ -6,11 +6,7 @@ parameters:
checkGenericClassInNonGenericObjectType: false # remove this rule when all other issues are solved.
ignoreErrors:
# TODO: slowly remove these exceptions and fix the issues found.
- '#is not allowed to extend#'
- '#is neither abstract nor final#'
- '#has a nullable return type declaration#'
- '#with a nullable type declaration#'
- '#with null as default value#'
- '#Control structures using switch should not be used#'
paths:
- ../app
- ../database

4
app/Console/AutoImports.php

@ -298,7 +298,7 @@ trait AutoImports
foreach ($set as $index => $messages) {
if (count($messages) > 0) {
foreach ($messages as $message) {
$this->$func(sprintf('Conversion index %d: %s', $index, $message));
$this->$func(sprintf('Conversion index %d: %s', $index, $message)); // @phpstan-ignore-line
}
}
}
@ -323,7 +323,7 @@ trait AutoImports
foreach ($set as $index => $messages) {
if (count($messages) > 0) {
foreach ($messages as $message) {
$this->$func(sprintf('Import index %d: %s', $index, $message));
$this->$func(sprintf('Import index %d: %s', $index, $message)); // @phpstan-ignore-line
}
}
}

2
app/Console/Commands/AutoImport.php

@ -66,7 +66,7 @@ class AutoImport extends Command
return 1;
}
$argument = (string)($this->argument('directory') ?? './');
$argument = (string)($this->argument('directory') ?? './'); // @phpstan-ignore-line
$directory = realpath($argument);
if (!$this->isAllowedPath($directory)) {
$this->error(sprintf('Path "%s" is not in the list of allowed paths (IMPORT_DIR_ALLOWLIST).', $directory));

2
app/Console/Commands/Import.php

@ -75,7 +75,7 @@ class Import extends Command
$this->info(sprintf('Welcome to the Firefly III data importer, v%s', config('importer.version')));
app('log')->debug(sprintf('Now in %s', __METHOD__));
$file = (string)$this->argument('file');
$config = (string)$this->argument('config');
$config = (string)$this->argument('config'); // @phpstan-ignore-line
// validate config path:
if ('' !== $config) {

2
app/Console/HaveAccess.php

@ -66,7 +66,7 @@ trait HaveAccess
return false;
}
$reportedVersion = (string)$result->version;
$reportedVersion = $result->version;
if(str_starts_with($reportedVersion, 'v')) {
$reportedVersion = substr($reportedVersion, 1);
}

37
app/Services/Shared/Model/ImportServiceAccount.php

@ -38,9 +38,10 @@ class ImportServiceAccount
public string $id;
public string $name;
public string $status;
public array $extra;
/**
* @param array $accounts
* @param array $accounts
*
* @return array
*/
@ -51,7 +52,7 @@ class ImportServiceAccount
/** @var NordigenAccount $account */
foreach ($accounts as $account) {
$iban = $account->getIban();
if('' !== $iban && false === IbanConverter::isValidIban($iban)) {
if ('' !== $iban && false === IbanConverter::isValidIban($iban)) {
app('log')->debug(sprintf('IBAN "%s" is invalid so it will be ignored.', $iban));
$iban = '';
}
@ -59,11 +60,19 @@ class ImportServiceAccount
$return[] = self::fromArray(
[
'id' => $account->getIdentifier(),
'name' => $account->getName(),
'name' => $account->getFullName(),
'currency_code' => $account->getCurrency(),
'iban' => $iban,
'bban' => $account->getBban(),
'currency_code' => $account->getCurrency(),
'status' => '',
'extra' => [
'Name' => $account->getName(),
'Display name' => $account->getDisplayName(),
'Owner name' => $account->getOwnerName(),
'Currency' => $account->getCurrency(),
'IBAN' => $iban,
'BBAN' => $account->getBban(),
],
]
);
}
@ -72,7 +81,7 @@ class ImportServiceAccount
}
/**
* @param array $spectre
* @param array $spectre
*
* @return array
*/
@ -81,8 +90,8 @@ class ImportServiceAccount
$return = [];
/** @var SpectreAccount $account */
foreach ($spectre as $account) {
$iban = (string) $account->iban;
if('' !== $iban && false === IbanConverter::isValidIban($iban)) {
$iban = (string)$account->iban;
if ('' !== $iban && false === IbanConverter::isValidIban($iban)) {
app('log')->debug(sprintf('IBAN "%s" is invalid so it will be ignored.', $iban));
$iban = '';
}
@ -90,10 +99,15 @@ class ImportServiceAccount
[
'id' => $account->id,
'name' => $account->name,
'currency_code' => $account->currencyCode,
'iban' => $iban,
'bban' => $account->accountNumber,
'currency_code' => $account->currencyCode,
'status' => $account->status,
'extra' => [
'Currency' => $account->currencyCode,
'IBAN' => $iban,
'BBAN' => $account->accountNumber,
],
]
);
}
@ -102,15 +116,15 @@ class ImportServiceAccount
}
/**
* @param array $array
* @param array $array
*
* @return $this
*/
public static function fromArray(array $array): self
{
app('log')->debug('Create generic account from', $array);
$iban = (string) ($array['iban'] ?? '');
if('' !== $iban && false === IbanConverter::isValidIban($iban)) {
$iban = (string)($array['iban'] ?? '');
if ('' !== $iban && false === IbanConverter::isValidIban($iban)) {
app('log')->debug(sprintf('IBAN "%s" is invalid so it will be ignored.', $iban));
$iban = '';
}
@ -121,6 +135,7 @@ class ImportServiceAccount
$account->bban = $array['bban'];
$account->currencyCode = $array['currency_code'];
$account->status = $array['status'];
$account->extra = $array['extra'];
return $account;
}

14
app/Services/Spectre/Model/TransactionExtra.php

@ -67,9 +67,7 @@ class TransactionExtra
*
* @throws Exception
*/
private function __construct()
{
}
private function __construct() {}
/**
* TransactionExtra constructor.
@ -84,9 +82,9 @@ class TransactionExtra
$model->id = $data['id'] ?? null;
$model->recordNumber = $data['record_number'] ?? null;
$model->information = $data['information'] ?? null;
$model->time = isset($data['time']) ? new Carbon($data['time']) : null;
$model->postingDate = isset($data['posting_date']) ? new Carbon($data['posting_date']) : null;
$model->postingTime = isset($data['posting_time']) ? new Carbon($data['posting_time']) : null;
$model->time = array_key_exists('time', $data) ? new Carbon($data['time']) : null;
$model->postingDate = array_key_exists('posting_date', $data) ? new Carbon($data['posting_date']) : null;
$model->postingTime = array_key_exists('posting_time', $data) ? new Carbon($data['posting_time']) : null;
$model->accountNumber = $data['account_number'] ?? null;
$model->originalAmount = isset($data['original_amount']) ? (string)$data['original_amount'] : null;
$model->originalCurrencyCode = $data['original_currency_code'] ?? null;
@ -108,8 +106,8 @@ class TransactionExtra
$model->units = array_key_exists('units', $data) ? (string)$data['units'] : null;
$model->additional = $data['additional'] ?? null;
$model->unitPrice = $data['unit_price'] ?? null;
$model->accountBalanceSnapshot = isset($data['account_balance_snapshot']) ? (string)$data['account_balance_snapshot'] : null;
$model->categorizationConfidence = isset($data['categorization_confidence']) ? (string)$data['categorization_confidence'] : null;
$model->accountBalanceSnapshot = array_key_exists('account_balance_snapshot', $data) ? (string)$data['account_balance_snapshot'] : null;
$model->categorizationConfidence = array_key_exists('categorization_confidence', $data) ? (string)$data['categorization_confidence'] : null;
return $model;
}

2
app/Support/Internal/MergesAccountLists.php

@ -101,7 +101,7 @@ trait MergesAccountLists
*/
protected function mergeSpectreAccountLists(array $spectre, array $fireflyIII): array
{
app('log')->debug('Now merging Nordigen account lists.');
app('log')->debug('Now merging Spectre account lists.');
$generic = ImportServiceAccount::convertSpectreArray($spectre);
return $this->mergeGenericAccountList($generic, $fireflyIII);

22
resources/views/import/004-configure/partials/account-title-generic.twig

@ -11,12 +11,28 @@
/> <label class="form-check-label"
{% if '' != information.import_account.iban %}title="IBAN: {{ information.import_account.iban }}"{% endif %}
for="do_import_{{ information.import_account.id }}">
Account "{{ information.import_account.name }}"
{% if '' != information.import_account.name %}
Account "{{ information.import_account.name }}"
{% else %}
Account with no name
{% endif %}
</label>
{% if '' != information.import_account.iban %}
<br>
<small>
{% for key, item in information.import_account.extra %}
{% if '' != item %}
{{ key }}: {{ item }}<br>
{% endif %}
{# {% if '' != information.import_account.iban %}
<br><small>
IBAN: {{ information.import_account.iban }}</small>
{% endif %}
{% endif %} #}
{% endfor %}
</small>
{% if 'disabled' == information.import_account.status %}<br>
<small class="text-danger">(this account is
disabled)</small>{% endif %}

23
resources/views/import/004-configure/partials/account-title-nordigen.twig

@ -1,23 +0,0 @@
{# Nordigen uses identifier #}
<input
id="do_import_{{ information.import_account.identifier }}"
type="checkbox"
{% if 'disabled' == information.import_account.status %}
disabled="disabled"
{% endif %}
name="do_import[{{ information.import_account.identifier }}]"
value="1"
aria-describedby="accountsHelp"
{% if(information.firefly|length==0) %}disabled="disabled"{% endif %}
/>
<label class="form-check-label"
{% if '' != information.import_account.iban %}title="IBAN: {{ information.import_account.iban }}"{% endif %}
for="do_import_{{ information.import_account.identifier }}">
Account "{{ information.import_account.getFullName }}"
</label>
{% if 'disabled' != information.import_account.status and '' != information.import_account.iban %}
<br><small>
IBAN: {{ information.import_account.iban }}</small>{% endif %}
{% if 'disabled' == information.import_account.status %}<br>
<small class="text-danger">(this account is
disabled)</small>{% endif %}

17
resources/views/import/004-configure/partials/account-title-spectre.twig

@ -1,17 +0,0 @@
<input
id="do_import_{{ information.import_account.id }}"
type="checkbox"
name="do_import[{{ information.import_account.id }}]"
value="1"
{% if 0 != configuration.getAccounts[information.import_account.id] %}checked="checked"{% endif %}
aria-describedby="accountsHelp"
{% if(information.firefly|length==0) %}disabled="disabled"{% endif %}
/> <label class="form-check-label"
{% if '' != information.import_account.iban %}title="IBAN: {{ information.import_account.iban }}"{% endif %}
for="do_import_{{ information.import_account.id }}">
Account "{{ information.import_account.name }}"
</label>
{% if '' != information.import_account.iban %}
<br><small>
IBAN: {{ information.import_account.iban }}</small>
{% endif %}

13
resources/views/import/004-configure/partials/ff3-account-nordigen.twig

@ -1,13 +0,0 @@
{% if 'disabled' != information.import_account.status %}
<select style="width:100%;"
class="custom-select custom-select-sm form-control"
name="accounts[{{ information.import_account.identifier }}]">
{% for ff3Account in information.firefly_iii_accounts %}
{# {% if configuration.getAccounts[spectreAccount.id] == ff3Account.id %}selected{% endif %} #}
<option value="{{ ff3Account.id }}"
label="{{ ff3Account.name }}{% if ff3Account.iban %} ({{ ff3Account.iban }}){% endif %}">
{{ ff3Account.name }}{% if ff3Account.iban %} ({{ ff3Account.iban }}){% endif %}
</option>
{% endfor %}
</select>
{% endif %}

11
resources/views/import/004-configure/partials/ff3-account-spectre.twig

@ -1,11 +0,0 @@
<select style="width:100%;"
class="custom-select custom-select-sm form-control"
name="accounts[{{ information.import_account.id }}]">
{% for ff3Account in information.firefly_iii_accounts %}
<option value="{{ ff3Account.id }}"
{% if ff3Account.id == configuration.getAccounts[information.import_account.id] %}selected{% endif %}
label="{{ ff3Account.name }}{% if ff3Account.iban %} ({{ ff3Account.iban }}){% endif %}">
{{ ff3Account.name }}{% if ff3Account.iban %} ({{ ff3Account.iban }}){% endif %}
</option>
{% endfor %}
</select>
Loading…
Cancel
Save