mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code optimisations.
This commit is contained in:
@@ -82,18 +82,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $this->user->accounts()->find($accountId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return account type by string.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return AccountType|null
|
||||
*/
|
||||
public function getAccountType(string $type): ?AccountType
|
||||
{
|
||||
return AccountType::whereType($type)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return meta value for account. Null if not found.
|
||||
*
|
||||
@@ -113,16 +101,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Note|null
|
||||
*/
|
||||
public function getNote(Account $account): ?Note
|
||||
{
|
||||
return $account->notes()->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get note text or null.
|
||||
*
|
||||
@@ -185,29 +163,6 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
return $journal->date->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of the very last transaction in this account.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function newestJournalDate(Account $account): Carbon
|
||||
{
|
||||
$last = new Carbon;
|
||||
$date = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.order', 'ASC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->first(['transaction_journals.date']);
|
||||
if (null !== $date) {
|
||||
$last = new Carbon($date->date);
|
||||
}
|
||||
|
||||
return $last;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the date of the very first transaction in this account.
|
||||
*
|
||||
@@ -253,7 +208,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user)
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
@@ -262,6 +217,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
* @param array $data
|
||||
*
|
||||
* @return Account
|
||||
* @throws \FireflyIII\Exceptions\FireflyException
|
||||
*/
|
||||
public function store(array $data): Account
|
||||
{
|
||||
@@ -286,20 +242,4 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function updateReconciliation(TransactionJournal $journal, array $data): TransactionJournal
|
||||
{
|
||||
/** @var JournalUpdateService $service */
|
||||
$service = app(JournalUpdateService::class);
|
||||
$journal = $service->update($journal, $data);
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -55,14 +55,8 @@ interface AccountRepositoryInterface
|
||||
public function destroy(Account $account, ?Account $moveTo): bool;
|
||||
|
||||
/**
|
||||
* @param int $accountId
|
||||
* Find by account number. Is used.
|
||||
*
|
||||
* @deprecated
|
||||
* @return Account
|
||||
*/
|
||||
public function find(int $accountId): Account;
|
||||
|
||||
/**
|
||||
* @param string $number
|
||||
* @param array $types
|
||||
*
|
||||
@@ -70,15 +64,6 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function findByAccountNumber(string $number, array $types): ?Account;
|
||||
|
||||
/**
|
||||
* @param string $iban
|
||||
* @param array $types
|
||||
*
|
||||
* @deprecated
|
||||
* @return Account
|
||||
*/
|
||||
public function findByIban(string $iban, array $types): Account;
|
||||
|
||||
/**
|
||||
* @param string $iban
|
||||
* @param array $types
|
||||
@@ -102,15 +87,6 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function findNull(int $accountId): ?Account;
|
||||
|
||||
/**
|
||||
* Return account type by string.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return AccountType|null
|
||||
*/
|
||||
public function getAccountType(string $type): ?AccountType;
|
||||
|
||||
/**
|
||||
* @param array $accountIds
|
||||
*
|
||||
@@ -147,13 +123,6 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function getMetaValue(Account $account, string $field): ?string;
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Note|null
|
||||
*/
|
||||
public function getNote(Account $account): ?Note;
|
||||
|
||||
/**
|
||||
* Get note text or null.
|
||||
*
|
||||
@@ -191,15 +160,6 @@ interface AccountRepositoryInterface
|
||||
*/
|
||||
public function getReconciliation(Account $account): ?Account;
|
||||
|
||||
/**
|
||||
* Returns the date of the very last transaction in this account.
|
||||
*
|
||||
* @param Account $account
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function newestJournalDate(Account $account): Carbon;
|
||||
|
||||
/**
|
||||
* Returns the date of the very first transaction in this account.
|
||||
*
|
||||
@@ -237,12 +197,4 @@ interface AccountRepositoryInterface
|
||||
* @return Account
|
||||
*/
|
||||
public function update(Account $account, array $data): Account;
|
||||
|
||||
/**
|
||||
* @param TransactionJournal $journal
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function updateReconciliation(TransactionJournal $journal, array $data): TransactionJournal;
|
||||
}
|
||||
|
@@ -44,6 +44,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function getAccountReport(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
@@ -182,7 +183,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user)
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
@@ -191,6 +192,7 @@ class AccountTasker implements AccountTaskerInterface
|
||||
* @param Collection $transactions
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
private function groupByOpposing(Collection $transactions): array
|
||||
{
|
||||
|
@@ -38,22 +38,6 @@ use Log;
|
||||
*/
|
||||
trait FindAccountsTrait
|
||||
{
|
||||
/**
|
||||
* @param $accountId
|
||||
*
|
||||
* @deprecated
|
||||
* @return Account
|
||||
*/
|
||||
public function find(int $accountId): Account
|
||||
{
|
||||
/** @var Account $account */
|
||||
$account = $this->user->accounts()->find($accountId);
|
||||
if (null === $account) {
|
||||
return new Account;
|
||||
}
|
||||
|
||||
return $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $number
|
||||
@@ -82,33 +66,6 @@ trait FindAccountsTrait
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $iban
|
||||
* @param array $types
|
||||
*
|
||||
* @deprecated
|
||||
* @return Account
|
||||
*/
|
||||
public function findByIban(string $iban, array $types): Account
|
||||
{
|
||||
$query = $this->user->accounts()->where('iban', '!=', '')->whereNotNull('iban');
|
||||
|
||||
if (\count($types) > 0) {
|
||||
$query->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id');
|
||||
$query->whereIn('account_types.type', $types);
|
||||
}
|
||||
|
||||
$accounts = $query->get(['accounts.*']);
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
if ($account->iban === $iban) {
|
||||
return $account;
|
||||
}
|
||||
}
|
||||
|
||||
return new Account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $iban
|
||||
* @param array $types
|
||||
@@ -158,7 +115,8 @@ trait FindAccountsTrait
|
||||
Log::debug(sprintf('Found #%d (%s) with type id %d', $account->id, $account->name, $account->account_type_id));
|
||||
|
||||
return $account;
|
||||
} else {
|
||||
}
|
||||
if ($account->name !== $name) {
|
||||
Log::debug(sprintf('"%s" does not equal "%s"', $account->name, $name));
|
||||
}
|
||||
}
|
||||
@@ -244,9 +202,11 @@ trait FindAccountsTrait
|
||||
/**
|
||||
* @return Account
|
||||
*
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getCashAccount(): Account
|
||||
{
|
||||
/** @var AccountType $type */
|
||||
$type = AccountType::where('type', AccountType::CASH)->first();
|
||||
/** @var AccountFactory $factory */
|
||||
$factory = app(AccountFactory::class);
|
||||
@@ -267,7 +227,8 @@ trait FindAccountsTrait
|
||||
if (AccountType::ASSET !== $account->accountType->type) {
|
||||
throw new FireflyException(sprintf('%s is not an asset account.', $account->name));
|
||||
}
|
||||
$name = $account->name . ' reconciliation';
|
||||
$name = $account->name . ' reconciliation';
|
||||
/** @var AccountType $type */
|
||||
$type = AccountType::where('type', AccountType::RECONCILIATION)->first();
|
||||
$accounts = $this->user->accounts()->where('account_type_id', $type->id)->get();
|
||||
/** @var Account $current */
|
||||
|
Reference in New Issue
Block a user