mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Clean up code and comments.
This commit is contained in:
@@ -42,11 +42,11 @@ use Validator;
|
||||
class TransactionFactory
|
||||
{
|
||||
private Account $account;
|
||||
private array $accountInformation;
|
||||
private TransactionCurrency $currency;
|
||||
private ?TransactionCurrency $foreignCurrency;
|
||||
private TransactionJournal $journal;
|
||||
private bool $reconciled;
|
||||
private array $accountInformation;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -140,6 +140,38 @@ class TransactionFactory
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function updateAccountInformation(): void
|
||||
{
|
||||
if (!array_key_exists('iban', $this->accountInformation)) {
|
||||
Log::debug('No IBAN information in array, will not update.');
|
||||
return;
|
||||
}
|
||||
if ('' !== (string)$this->account->iban) {
|
||||
Log::debug('Account already has IBAN information, will not update.');
|
||||
return;
|
||||
}
|
||||
if ($this->account->iban === $this->accountInformation['iban']) {
|
||||
Log::debug('Account already has this IBAN, will not update.');
|
||||
return;
|
||||
}
|
||||
// validate info:
|
||||
$validator = Validator::make(['iban' => $this->accountInformation['iban']], [
|
||||
'iban' => ['required', new UniqueIban($this->account, $this->account->accountType->type)],
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
Log::debug('Invalid or non-unique IBAN, will not update.');
|
||||
return;
|
||||
}
|
||||
|
||||
Log::debug('Will update account with IBAN information.');
|
||||
$service = app(AccountUpdateService::class);
|
||||
$service->update($this->account, ['iban' => $this->accountInformation['iban']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create transaction with positive amount (for destination accounts).
|
||||
*
|
||||
@@ -171,6 +203,14 @@ class TransactionFactory
|
||||
$this->account = $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountInformation
|
||||
*/
|
||||
public function setAccountInformation(array $accountInformation): void
|
||||
{
|
||||
$this->accountInformation = $accountInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
*
|
||||
@@ -220,45 +260,4 @@ class TransactionFactory
|
||||
{
|
||||
// empty function.
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $accountInformation
|
||||
*/
|
||||
public function setAccountInformation(array $accountInformation): void
|
||||
{
|
||||
$this->accountInformation = $accountInformation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function updateAccountInformation(): void
|
||||
{
|
||||
if (!array_key_exists('iban', $this->accountInformation)) {
|
||||
Log::debug('No IBAN information in array, will not update.');
|
||||
return;
|
||||
}
|
||||
if ('' !== (string)$this->account->iban) {
|
||||
Log::debug('Account already has IBAN information, will not update.');
|
||||
return;
|
||||
}
|
||||
if ($this->account->iban === $this->accountInformation['iban']) {
|
||||
Log::debug('Account already has this IBAN, will not update.');
|
||||
return;
|
||||
}
|
||||
// validate info:
|
||||
$validator = Validator::make(['iban' => $this->accountInformation['iban']], [
|
||||
'iban' => ['required', new UniqueIban($this->account, $this->account->accountType->type)],
|
||||
]);
|
||||
if ($validator->fails()) {
|
||||
Log::debug('Invalid or non-unique IBAN, will not update.');
|
||||
return;
|
||||
}
|
||||
|
||||
Log::debug('Will update account with IBAN information.');
|
||||
$service = app(AccountUpdateService::class);
|
||||
$service->update($this->account, ['iban' => $this->accountInformation['iban']]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user