mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Refactor findNull to find
This commit is contained in:
@@ -104,7 +104,7 @@ class DeleteController extends Controller
|
||||
$type = $account->accountType->type;
|
||||
$typeName = config(sprintf('firefly.shortNamesByFullName.%s', $type));
|
||||
$name = $account->name;
|
||||
$moveTo = $this->repository->findNull((int)$request->get('move_account_before_delete'));
|
||||
$moveTo = $this->repository->find((int)$request->get('move_account_before_delete'));
|
||||
|
||||
$this->repository->destroy($account, $moveTo);
|
||||
|
||||
|
@@ -130,7 +130,7 @@ class LinkController extends Controller
|
||||
{
|
||||
Log::channel('audit')->info(sprintf('User destroyed link type #%d', $linkType->id));
|
||||
$name = $linkType->name;
|
||||
$moveTo = $this->repository->findNull((int)$request->get('move_link_type_before_delete'));
|
||||
$moveTo = $this->repository->find((int)$request->get('move_link_type_before_delete'));
|
||||
$this->repository->destroy($linkType, $moveTo);
|
||||
|
||||
$request->session()->flash('success', (string)trans('firefly.deleted_link_type', ['name' => $name]));
|
||||
|
@@ -131,7 +131,7 @@ class BudgetLimitController extends Controller
|
||||
Log::debug('Going to store new budget-limit.', $request->all());
|
||||
// first search for existing one and update it if necessary.
|
||||
$currency = $this->currencyRepos->find((int)$request->get('transaction_currency_id'));
|
||||
$budget = $this->repository->findNull((int)$request->get('budget_id'));
|
||||
$budget = $this->repository->find((int)$request->get('budget_id'));
|
||||
if (null === $currency || null === $budget) {
|
||||
throw new FireflyException('No valid currency or budget.');
|
||||
}
|
||||
|
@@ -306,7 +306,7 @@ class IndexController extends Controller
|
||||
|
||||
foreach ($budgetIds as $index => $budgetId) {
|
||||
$budgetId = (int)$budgetId;
|
||||
$budget = $repository->findNull($budgetId);
|
||||
$budget = $repository->find($budgetId);
|
||||
if (null !== $budget) {
|
||||
Log::debug(sprintf('Set budget #%d ("%s") to position %d', $budget->id, $budget->name, $index + 1));
|
||||
$repository->setBudgetOrder($budget, $index + 1);
|
||||
|
@@ -123,7 +123,7 @@ class AccountController extends Controller
|
||||
// grab the difference and find the currency.
|
||||
$startAmount = $startBalances[$accountId][$currencyId] ?? '0';
|
||||
$diff = bcsub($endAmount, $startAmount);
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->findNull($currencyId);
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->find($currencyId);
|
||||
if (0 !== bccomp($diff, '0')) {
|
||||
// store the values in a temporary array.
|
||||
$tempData[] = [
|
||||
@@ -568,7 +568,7 @@ class AccountController extends Controller
|
||||
// grab the difference and find the currency.
|
||||
$startAmount = $startBalances[$accountId][$currencyId] ?? '0';
|
||||
$diff = bcsub($endAmount, $startAmount);
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->findNull($currencyId);
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $this->currencyRepository->find($currencyId);
|
||||
if (0 !== bccomp($diff, '0')) {
|
||||
// store the values in a temporary array.
|
||||
$tempData[] = [
|
||||
|
@@ -78,13 +78,13 @@ class BillController extends Controller
|
||||
$unpaid = $repository->getBillsUnpaidInRangePerCurrency($start, $end); // will be a positive amount.
|
||||
|
||||
foreach ($paid as $currencyId => $amount) {
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId);
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->find($currencyId);
|
||||
$label = (string)trans('firefly.paid_in_currency', ['currency' => $currencies[$currencyId]->name]);
|
||||
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol,
|
||||
'currency_code' => $currencies[$currencyId]->code];
|
||||
}
|
||||
foreach ($unpaid as $currencyId => $amount) {
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->findNull($currencyId);
|
||||
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->find($currencyId);
|
||||
$label = (string)trans('firefly.unpaid_in_currency', ['currency' => $currencies[$currencyId]->name]);
|
||||
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol,
|
||||
'currency_code' => $currencies[$currencyId]->code];
|
||||
|
@@ -131,7 +131,7 @@ class JavascriptController extends Controller
|
||||
*/
|
||||
public function variables(Request $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response
|
||||
{
|
||||
$account = $repository->findNull((int) $request->get('account'));
|
||||
$account = $repository->find((int) $request->get('account'));
|
||||
$currency = app('amount')->getDefaultCurrency();
|
||||
if(null !== $account) {
|
||||
$currency = $repository->getAccountCurrency($account) ?? $currency;
|
||||
|
@@ -184,7 +184,7 @@ class BoxController extends Controller
|
||||
// format amounts:
|
||||
$keys = array_keys($sums);
|
||||
foreach ($keys as $currencyId) {
|
||||
$currency = $repository->findNull($currencyId);
|
||||
$currency = $repository->find($currencyId);
|
||||
$sums[$currencyId] = app('amount')->formatAnything($currency, $sums[$currencyId], false);
|
||||
$incomes[$currencyId] = app('amount')->formatAnything($currency, $incomes[$currencyId] ?? '0', false);
|
||||
$expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false);
|
||||
|
@@ -98,7 +98,7 @@ class NewUserController extends Controller
|
||||
// set language preference:
|
||||
app('preferences')->set('language', $language);
|
||||
// Store currency preference from input:
|
||||
$currency = $currencyRepository->findNull((int) $request->input('amount_currency_id_bank_balance'));
|
||||
$currency = $currencyRepository->find((int) $request->input('amount_currency_id_bank_balance'));
|
||||
|
||||
// if is null, set to EUR:
|
||||
if (null === $currency) {
|
||||
|
@@ -208,7 +208,7 @@ class TagController extends Controller
|
||||
$count = 0;
|
||||
foreach ($tags as $tagId) {
|
||||
$tagId = (int)$tagId;
|
||||
$tag = $this->repository->findNull($tagId);
|
||||
$tag = $this->repository->find($tagId);
|
||||
if (null !== $tag) {
|
||||
$this->repository->destroy($tag);
|
||||
$count++;
|
||||
|
@@ -104,7 +104,7 @@ class BulkController extends Controller
|
||||
|
||||
foreach ($journalIds as $journalId) {
|
||||
$journalId = (int)$journalId;
|
||||
$journal = $this->repository->findNull($journalId);
|
||||
$journal = $this->repository->find($journalId);
|
||||
if (null !== $journal) {
|
||||
$resultA = $this->updateJournalBudget($journal, $ignoreBudget, $request->integer('budget_id'));
|
||||
$resultB = $this->updateJournalTags($journal, $tagsAction, explode(',', $request->string('tags')));
|
||||
|
@@ -123,7 +123,7 @@ class LinkController extends Controller
|
||||
$linkInfo = $request->getLinkInfo();
|
||||
|
||||
Log::debug('We are here (store)');
|
||||
$other = $this->journalRepository->findNull($linkInfo['transaction_journal_id']);
|
||||
$other = $this->journalRepository->find($linkInfo['transaction_journal_id']);
|
||||
if (null === $other) {
|
||||
session()->flash('error', (string)trans('firefly.invalid_link_selection'));
|
||||
|
||||
|
@@ -103,7 +103,7 @@ class MassController extends Controller
|
||||
foreach ($ids as $journalId) {
|
||||
|
||||
/** @var TransactionJournal $journal */
|
||||
$journal = $this->repository->findNull((int)$journalId);
|
||||
$journal = $this->repository->find((int)$journalId);
|
||||
if (null !== $journal && (int)$journalId === $journal->id) {
|
||||
$this->repository->destroyJournal($journal);
|
||||
++$count;
|
||||
@@ -197,7 +197,7 @@ class MassController extends Controller
|
||||
*/
|
||||
private function updateJournal(int $journalId, MassEditJournalRequest $request): void
|
||||
{
|
||||
$journal = $this->repository->findNull($journalId);
|
||||
$journal = $this->repository->find($journalId);
|
||||
if (null === $journal) {
|
||||
throw new FireflyException(sprintf('Trying to edit non-existent or deleted journal #%d', $journalId));
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ class ReportFormRequest extends FormRequest
|
||||
$collection = new Collection;
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $accountId) {
|
||||
$account = $repository->findNull((int)$accountId);
|
||||
$account = $repository->find((int)$accountId);
|
||||
if (null !== $account) {
|
||||
$collection->push($account);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class ReportFormRequest extends FormRequest
|
||||
$collection = new Collection;
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $budgetId) {
|
||||
$budget = $repository->findNull((int)$budgetId);
|
||||
$budget = $repository->find((int)$budgetId);
|
||||
if (null !== $budget) {
|
||||
$collection->push($budget);
|
||||
}
|
||||
@@ -101,7 +101,7 @@ class ReportFormRequest extends FormRequest
|
||||
$collection = new Collection;
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $categoryId) {
|
||||
$category = $repository->findNull((int)$categoryId);
|
||||
$category = $repository->find((int)$categoryId);
|
||||
if (null !== $category) {
|
||||
$collection->push($category);
|
||||
}
|
||||
@@ -124,7 +124,7 @@ class ReportFormRequest extends FormRequest
|
||||
$collection = new Collection;
|
||||
if (is_array($set)) {
|
||||
foreach ($set as $accountId) {
|
||||
$account = $repository->findNull((int)$accountId);
|
||||
$account = $repository->find((int)$accountId);
|
||||
if (null !== $account) {
|
||||
$collection->push($account);
|
||||
}
|
||||
@@ -209,7 +209,7 @@ class ReportFormRequest extends FormRequest
|
||||
$collection->push($tag);
|
||||
continue;
|
||||
}
|
||||
$tag = $repository->findNull((int)$tagTag);
|
||||
$tag = $repository->find((int)$tagTag);
|
||||
if (null !== $tag) {
|
||||
$collection->push($tag);
|
||||
}
|
||||
|
Reference in New Issue
Block a user