Clean up code and comments.

This commit is contained in:
James Cole
2023-02-22 18:14:14 +01:00
parent e6dc881f56
commit e421b29b01
249 changed files with 647 additions and 1044 deletions

View File

@@ -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']]);
}
}