mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 22:21:42 +00:00
Refactor findNull to find
This commit is contained in:
@@ -87,9 +87,9 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
public function findNull(int $journalId): ?TransactionJournal
|
||||
public function find(int $journalId): ?TransactionJournal
|
||||
{
|
||||
return $this->user->transactionJournals()->where('id', $journalId)->first();
|
||||
return $this->user->transactionJournals()->find($journalId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,62 +123,6 @@ class JournalRepository implements JournalRepositoryInterface
|
||||
return $transaction->account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all destination accounts related to journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param bool $useCache
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournalDestinationAccounts(TransactionJournal $journal, bool $useCache = true): Collection
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty('destination-account-list');
|
||||
if ($useCache && $cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
$transactions = $journal->transactions()->where('amount', '>', 0)->orderBy('transactions.account_id')->with('account')->get();
|
||||
$list = new Collection;
|
||||
/** @var Transaction $t */
|
||||
foreach ($transactions as $t) {
|
||||
$list->push($t->account);
|
||||
}
|
||||
$list = $list->unique('id');
|
||||
$cache->store($list);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all source accounts related to journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
* @param bool $useCache
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournalSourceAccounts(TransactionJournal $journal, bool $useCache = true): Collection
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty('source-account-list');
|
||||
if ($useCache && $cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
$transactions = $journal->transactions()->where('amount', '<', 0)->orderBy('transactions.account_id')->with('account')->get();
|
||||
$list = new Collection;
|
||||
/** @var Transaction $t */
|
||||
foreach ($transactions as $t) {
|
||||
$list->push($t->account);
|
||||
}
|
||||
$list = $list->unique('id');
|
||||
$cache->store($list);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return total amount of journal. Is always positive.
|
||||
*
|
||||
|
||||
@@ -58,14 +58,14 @@ interface JournalRepositoryInterface
|
||||
public function findByType(array $types): Collection;
|
||||
|
||||
/**
|
||||
* See reference nr. 1
|
||||
* See reference nr. 1
|
||||
* Find a specific journal.
|
||||
*
|
||||
* @param int $journalId
|
||||
*
|
||||
* @return TransactionJournal|null
|
||||
*/
|
||||
public function findNull(int $journalId): ?TransactionJournal;
|
||||
public function find(int $journalId): ?TransactionJournal;
|
||||
|
||||
/**
|
||||
* Get users very first transaction journal.
|
||||
@@ -84,28 +84,6 @@ interface JournalRepositoryInterface
|
||||
*/
|
||||
public function getDestinationAccount(TransactionJournal $journal): Account;
|
||||
|
||||
/**
|
||||
* See reference nr. 2
|
||||
* Return a list of all destination accounts related to journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
* @deprecated
|
||||
*/
|
||||
public function getJournalDestinationAccounts(TransactionJournal $journal): Collection;
|
||||
|
||||
/**
|
||||
* See reference nr. 3
|
||||
* Return a list of all source accounts related to journal.
|
||||
*
|
||||
* @param TransactionJournal $journal
|
||||
*
|
||||
* @return Collection
|
||||
* @deprecated
|
||||
*/
|
||||
public function getJournalSourceAccounts(TransactionJournal $journal): Collection;
|
||||
|
||||
/**
|
||||
* Return total amount of journal. Is always positive.
|
||||
*
|
||||
@@ -121,7 +99,7 @@ interface JournalRepositoryInterface
|
||||
public function getLast(): ?TransactionJournal;
|
||||
|
||||
/**
|
||||
* See reference nr. 4
|
||||
* See reference nr. 4
|
||||
*
|
||||
* @param TransactionJournalLink $link
|
||||
*
|
||||
@@ -150,7 +128,7 @@ interface JournalRepositoryInterface
|
||||
public function getSourceAccount(TransactionJournal $journal): Account;
|
||||
|
||||
/**
|
||||
* See reference nr. 5
|
||||
* See reference nr. 5
|
||||
*
|
||||
* @param int $journalId
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user