mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-02 10:22:09 +00:00
chore: reformat code.
This commit is contained in:
@@ -63,19 +63,11 @@ class AccountUpdateService
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update account data.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws FireflyException
|
||||
@@ -122,8 +114,83 @@ class AccountUpdateService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
private function updateAccount(Account $account, array $data): Account
|
||||
{
|
||||
// update the account itself:
|
||||
if (array_key_exists('name', $data)) {
|
||||
$account->name = $data['name'];
|
||||
}
|
||||
if (array_key_exists('active', $data)) {
|
||||
$account->active = $data['active'];
|
||||
}
|
||||
if (array_key_exists('iban', $data)) {
|
||||
$account->iban = app('steam')->filterSpaces((string)$data['iban']);
|
||||
}
|
||||
|
||||
// set liability, but account must already be a liability.
|
||||
//$liabilityType = $data['liability_type'] ?? '';
|
||||
if ($this->isLiability($account) && array_key_exists('liability_type', $data)) {
|
||||
$type = $this->getAccountType($data['liability_type']);
|
||||
$account->account_type_id = $type->id;
|
||||
}
|
||||
// set liability, alternative method used in v1 layout:
|
||||
|
||||
if ($this->isLiability($account) && array_key_exists('account_type_id', $data)) {
|
||||
$type = AccountType::find((int)$data['account_type_id']);
|
||||
|
||||
if (null !== $type && in_array($type->type, config('firefly.valid_liabilities'), true)) {
|
||||
$account->account_type_id = $type->id;
|
||||
}
|
||||
}
|
||||
|
||||
// update virtual balance (could be set to zero if empty string).
|
||||
if (array_key_exists('virtual_balance', $data) && null !== $data['virtual_balance']) {
|
||||
$account->virtual_balance = '' === trim($data['virtual_balance']) ? '0' : $data['virtual_balance'];
|
||||
}
|
||||
|
||||
$account->save();
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isLiability(Account $account): bool
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
|
||||
return in_array($type, [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return AccountType
|
||||
*/
|
||||
private function getAccountType(string $type): AccountType
|
||||
{
|
||||
return AccountType::whereType(ucfirst($type))->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
@@ -174,16 +241,6 @@ class AccountUpdateService
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @return AccountType
|
||||
*/
|
||||
private function getAccountType(string $type): AccountType
|
||||
{
|
||||
return AccountType::whereType(ucfirst($type))->first();
|
||||
}
|
||||
|
||||
private function getTypeIds(array $array): array
|
||||
{
|
||||
$return = [];
|
||||
@@ -198,65 +255,8 @@ class AccountUpdateService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isLiability(Account $account): bool
|
||||
{
|
||||
$type = $account->accountType->type;
|
||||
|
||||
return in_array($type, [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
private function updateAccount(Account $account, array $data): Account
|
||||
{
|
||||
// update the account itself:
|
||||
if (array_key_exists('name', $data)) {
|
||||
$account->name = $data['name'];
|
||||
}
|
||||
if (array_key_exists('active', $data)) {
|
||||
$account->active = $data['active'];
|
||||
}
|
||||
if (array_key_exists('iban', $data)) {
|
||||
$account->iban = app('steam')->filterSpaces((string)$data['iban']);
|
||||
}
|
||||
|
||||
// set liability, but account must already be a liability.
|
||||
//$liabilityType = $data['liability_type'] ?? '';
|
||||
if ($this->isLiability($account) && array_key_exists('liability_type', $data)) {
|
||||
$type = $this->getAccountType($data['liability_type']);
|
||||
$account->account_type_id = $type->id;
|
||||
}
|
||||
// set liability, alternative method used in v1 layout:
|
||||
|
||||
if ($this->isLiability($account) && array_key_exists('account_type_id', $data)) {
|
||||
$type = AccountType::find((int)$data['account_type_id']);
|
||||
|
||||
if (null !== $type && in_array($type->type, config('firefly.valid_liabilities'), true)) {
|
||||
$account->account_type_id = $type->id;
|
||||
}
|
||||
}
|
||||
|
||||
// update virtual balance (could be set to zero if empty string).
|
||||
if (array_key_exists('virtual_balance', $data) && null !== $data['virtual_balance']) {
|
||||
$account->virtual_balance = '' === trim($data['virtual_balance']) ? '0' : $data['virtual_balance'];
|
||||
}
|
||||
|
||||
$account->save();
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*/
|
||||
private function updateLocation(Account $account, array $data): void
|
||||
{
|
||||
@@ -285,8 +285,8 @@ class AccountUpdateService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
* @param Account $account
|
||||
* @param array $data
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
@@ -321,7 +321,7 @@ class AccountUpdateService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param Account $account
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user