mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clean up code and comments.
This commit is contained in:
@@ -30,6 +30,7 @@ use FireflyIII\Services\Internal\Support\RecurringTransactionTrait;
|
||||
use FireflyIII\Services\Internal\Support\TransactionTypeTrait;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use JsonException;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -58,7 +59,7 @@ class RecurrenceFactory
|
||||
*
|
||||
* @return Recurrence
|
||||
* @throws FireflyException
|
||||
* @throws \JsonException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function create(array $data): Recurrence
|
||||
{
|
||||
|
||||
@@ -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']]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,6 @@ class TransactionJournalFactory
|
||||
* Constructor.
|
||||
*
|
||||
* @throws Exception
|
||||
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@@ -25,7 +25,6 @@ namespace FireflyIII\Factory;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user