Refactor findNull to find

This commit is contained in:
James Cole
2021-06-30 06:17:38 +02:00
parent b7ae5eda35
commit 70da5917c9
68 changed files with 120 additions and 273 deletions

View File

@@ -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);

View File

@@ -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]));

View File

@@ -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.');
}

View File

@@ -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);

View File

@@ -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[] = [

View File

@@ -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];

View File

@@ -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;

View File

@@ -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);

View File

@@ -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) {

View File

@@ -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++;

View File

@@ -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')));

View File

@@ -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'));

View File

@@ -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));
}

View File

@@ -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);
}