Browse Source

Drop all else / elseif.

pull/838/head
James Cole 4 months ago
parent
commit
551692767c
  1. 3
      app/Http/Controllers/Import/ConfigurationController.php
  2. 19
      app/Http/Controllers/Import/ConversionController.php
  3. 6
      app/Http/Controllers/Import/UploadController.php
  4. 9
      app/Services/SimpleFIN/Conversion/AccountMapper.php
  5. 3
      app/Services/SimpleFIN/Conversion/RoutineManager.php
  6. 3
      app/Services/SimpleFIN/Conversion/TransactionTransformer.php
  7. 6
      app/Services/SimpleFIN/Response/AccountsResponse.php
  8. 8
      app/Services/SimpleFIN/Response/TransactionsResponse.php
  9. 22
      app/Services/SimpleFIN/SimpleFINService.php

3
app/Http/Controllers/Import/ConfigurationController.php

@ -393,7 +393,8 @@ class ConfigurationController extends Controller
if (array_key_exists($identifier, $fromRequest['accounts'])) {
$accountValue = (int)$fromRequest['accounts'][$identifier];
$accounts[$identifier] = $accountValue;
} else {
}
if(!array_key_exists($identifier, $fromRequest['accounts'])) {
app('log')->warning(
sprintf(
'Account identifier %s in do_import but not in accounts array',

19
app/Http/Controllers/Import/ConversionController.php

@ -74,25 +74,26 @@ class ConversionController extends Controller
app('log')->debug('Will now verify configuration content.');
$flow = $configuration->getFlow();
// default back to mapping
$jobBackUrl = route('back.mapping');
// Set appropriate back URL based on flow
// SimpleFIN always goes back to configuration
if ('simplefin' === $flow) {
// SimpleFIN always goes back to configuration
$jobBackUrl = route('back.config');
app('log')->debug('SimpleFIN: Pressing "back" will send you to configure.');
} elseif (0 === count($configuration->getDoMapping()) && 'file' === $flow) {
// no mapping, back to roles
}
// no mapping, back to roles
if ('simplefin' !== $flow && 0 === count($configuration->getDoMapping()) && 'file' === $flow) {
app('log')->debug('Pressing "back" will send you to roles.');
$jobBackUrl = route('back.roles');
} elseif (0 === count($configuration->getMapping())) {
// back to mapping
}
// back to mapping
if ('simplefin' !== $flow && 0 === count($configuration->getMapping())) {
app('log')->debug('Pressing "back" will send you to mapping.');
$jobBackUrl = route('back.mapping');
} else {
// default back to mapping
$jobBackUrl = route('back.mapping');
}
// TODO option is not used atm.
// if (true === $configuration->isMapAllData()) {
// app('log')->debug('Pressing "back" will send you to mapping.');
// $jobBackUrl = route('back.mapping');

6
app/Http/Controllers/Import/UploadController.php

@ -386,7 +386,8 @@ class UploadController extends Controller
if ($isDemo) {
$simpleFINToken = config('importer.simplefin.demo_token');
$bridgeUrl = 'https://sfin.bridge.which.is'; // Demo mode uses known working Origin
} else {
}
if(!$isDemo) {
if (empty($simpleFINToken)) {
$errors->add('simplefin_token', 'SimpleFIN token is required.');
}
@ -395,7 +396,8 @@ class UploadController extends Controller
'simplefin_bridge_url',
'Bridge URL is required for CORS Origin header.'
);
} elseif (!filter_var($bridgeUrl, FILTER_VALIDATE_URL)) {
}
if (!empty($bridgeUrl) && !filter_var($bridgeUrl, FILTER_VALIDATE_URL)) {
$errors->add(
'simplefin_bridge_url',
'Bridge URL must be a valid URL.'

9
app/Services/SimpleFIN/Conversion/AccountMapper.php

@ -83,7 +83,8 @@ class AccountMapper
'action' => 'map',
];
}
} elseif ('create' === $mappingConfig['action']) {
}
if ('create' === $mappingConfig['action']) {
// Create new account
$fireflyAccount = $this->createFireflyAccount($simplefinAccount, $mappingConfig);
if ($fireflyAccount) {
@ -95,7 +96,8 @@ class AccountMapper
];
}
}
} else {
}
if (!isset($configuration['account_mapping'][$accountKey])) {
// Auto-map by searching for existing accounts
$fireflyAccount = $this->findMatchingFireflyAccount($simplefinAccount);
if ($fireflyAccount) {
@ -105,7 +107,8 @@ class AccountMapper
'firefly_account_name' => $fireflyAccount->name,
'action' => 'auto_map',
];
} else {
}
if (null === $fireflyAccount) {
// No mapping found - will need user input
$mapping[$accountKey] = [
'simplefin_account' => $simplefinAccount,

3
app/Services/SimpleFIN/Conversion/RoutineManager.php

@ -193,7 +193,8 @@ class RoutineManager implements RoutineManagerInterface
]
);
} else {
}
if (null === $createdAccount) {
// Account creation failed - this is a critical error that must be reported
$errorMessage = sprintf(
'CRITICAL: Failed to create Firefly III account "%s" (type: %s, currency: %s). Cannot proceed with transaction import for this account.',

3
app/Services/SimpleFIN/Conversion/TransactionTransformer.php

@ -74,7 +74,8 @@ class TransactionTransformer
$type = 'deposit';
$sourceAccount = $this->getCounterAccount($transactionData, $isDeposit);
$destinationAccount = $this->getFireflyAccount($simpleFINAccountData, $accountMapping, $newAccountConfig);
} else {
}
if (!$isDeposit) {
$type = 'withdrawal';
$sourceAccount = $this->getFireflyAccount($simpleFINAccountData, $accountMapping, $newAccountConfig);
$destinationAccount = $this->getCounterAccount($transactionData, $isDeposit);

6
app/Services/SimpleFIN/Response/AccountsResponse.php

@ -69,9 +69,9 @@ class AccountsResponse extends SimpleFINResponse
if (isset($data['accounts']) && is_array($data['accounts'])) {
$this->accounts = $data['accounts'];
app('log')->debug(sprintf('SimpleFIN AccountsResponse: Parsed %d accounts', count($this->accounts)));
} else {
app('log')->warning('SimpleFIN AccountsResponse: No accounts array found in response');
$this->accounts = [];
return;
}
app('log')->warning('SimpleFIN AccountsResponse: No accounts array found in response');
$this->accounts = [];
}
}

8
app/Services/SimpleFIN/Response/TransactionsResponse.php

@ -67,7 +67,7 @@ class TransactionsResponse extends SimpleFINResponse
// SimpleFIN API returns transactions in the 'transactions' array within accounts
if (isset($data['accounts']) && is_array($data['accounts'])) {
$transactions = [];
$transactions = [];
foreach ($data['accounts'] as $account) {
if (isset($account['transactions']) && is_array($account['transactions'])) {
$transactions = array_merge($transactions, $account['transactions']);
@ -75,9 +75,9 @@ class TransactionsResponse extends SimpleFINResponse
}
$this->transactions = $transactions;
app('log')->debug(sprintf('SimpleFIN TransactionsResponse: Parsed %d transactions', count($this->transactions)));
} else {
app('log')->warning('SimpleFIN TransactionsResponse: No accounts array found in response');
$this->transactions = [];
return;
}
app('log')->warning('SimpleFIN TransactionsResponse: No accounts array found in response');
$this->transactions = [];
}
}

22
app/Services/SimpleFIN/SimpleFINService.php

@ -55,7 +55,8 @@ class SimpleFINService
$actualApiUrl = $this->exchangeClaimUrlForAccessUrl($token);
$actualToken = ''; // Access URL contains auth info
app('log')->debug(sprintf('Successfully exchanged claim URL for access URL: %s', $actualApiUrl));
} else {
}
if (!$this->isBase64ClaimUrl($token)) {
// Token is not a base64 claim URL, we need an API URL
if (empty($apiUrl)) {
throw new ImporterErrorException('SimpleFIN API URL is required when token is not a base64-encoded claim URL');
@ -122,11 +123,10 @@ class SimpleFINService
if (is_array($accountData) && isset($accountData['id']) && is_string($accountData['id']) && $accountData['id'] === $accountId) {
$accountFound = true;
// Transactions are expected to be in $accountData['transactions'] as an array
$accountTransactions = [];
if (isset($accountData['transactions']) && is_array($accountData['transactions'])) {
$accountTransactions = $accountData['transactions'];
} else {
// If 'transactions' key is missing or not an array, treat as no transactions.
$accountTransactions = [];
}
break;
@ -196,11 +196,13 @@ class SimpleFINService
count($accountTransactions),
count($filteredTransactions)
));
} else {
$filteredTransactions = $accountTransactions;
app('log')->debug(sprintf('SimpleFIN extracted %d transactions for account ID "%s" (after potential filtering).', count($filteredTransactions), $accountId));
return $filteredTransactions;
}
$filteredTransactions = $accountTransactions;
app('log')->debug(sprintf('SimpleFIN extracted %d transactions for account ID "%s" (after potential filtering).', count($filteredTransactions), $accountId));
app('log')->debug(sprintf('SimpleFIN extracted %d transactions for account ID "%s" (no date filtering was applied).', count($filteredTransactions), $accountId));
return $filteredTransactions;
}
@ -340,9 +342,11 @@ class SimpleFINService
if (empty($apiUrl)) {
$errors[] = 'SimpleFIN bridge URL is required';
} elseif (!filter_var($apiUrl, FILTER_VALIDATE_URL)) {
}
if (!empty($apiUrl) && !filter_var($apiUrl, FILTER_VALIDATE_URL)) {
$errors[] = 'SimpleFIN bridge URL must be a valid URL';
} elseif (!str_starts_with($apiUrl, 'https://')) {
}
if (!empty($apiUrl) && !str_starts_with($apiUrl, 'https://')) {
$errors[] = 'SimpleFIN bridge URL must use HTTPS';
}

Loading…
Cancel
Save