From c9c043712a996dbce7d988b573b5fe9f378a6fa9 Mon Sep 17 00:00:00 2001 From: James Cole Date: Fri, 20 Aug 2021 20:49:42 +0200 Subject: [PATCH] Sort and clean up some code. --- app/Repositories/Budget/BudgetRepository.php | 24 +++++++-------- .../Budget/BudgetRepositoryInterface.php | 16 +++++----- .../Budget/NoBudgetRepository.php | 5 ++-- .../Budget/NoBudgetRepositoryInterface.php | 1 + .../Budget/OperationsRepository.php | 29 ++++++++++--------- .../Budget/OperationsRepositoryInterface.php | 1 + 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 5354c9ab41..706a9632c8 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -117,6 +117,18 @@ class BudgetRepository implements BudgetRepositoryInterface } } + /** + * Find a budget or return NULL + * + * @param int|null $budgetId |null + * + * @return Budget|null + */ + public function find(int $budgetId = null): ?Budget + { + return $this->user->budgets()->find($budgetId); + } + /** * @param int|null $budgetId * @param string|null $budgetName @@ -157,18 +169,6 @@ class BudgetRepository implements BudgetRepositoryInterface return $this->user->budgets()->where('name', 'LIKE', $query)->first(); } - /** - * Find a budget or return NULL - * - * @param int|null $budgetId |null - * - * @return Budget|null - */ - public function find(int $budgetId = null): ?Budget - { - return $this->user->budgets()->find($budgetId); - } - /** * This method returns the oldest journal or transaction date known to this budget. * Will cache result. diff --git a/app/Repositories/Budget/BudgetRepositoryInterface.php b/app/Repositories/Budget/BudgetRepositoryInterface.php index 576cac2c7d..d3f30b2f1e 100644 --- a/app/Repositories/Budget/BudgetRepositoryInterface.php +++ b/app/Repositories/Budget/BudgetRepositoryInterface.php @@ -56,6 +56,14 @@ interface BudgetRepositoryInterface */ public function destroyAutoBudget(Budget $budget): void; + /** + * + * @param int|null $budgetId + * + * @return Budget|null + */ + public function find(int $budgetId = null): ?Budget; + /** * @param int|null $budgetId * @param string|null $budgetName @@ -73,14 +81,6 @@ interface BudgetRepositoryInterface */ public function findByName(?string $name): ?Budget; - /** - * - * @param int|null $budgetId - * - * @return Budget|null - */ - public function find(int $budgetId = null): ?Budget; - /** * This method returns the oldest journal or transaction date known to this budget. * Will cache result. diff --git a/app/Repositories/Budget/NoBudgetRepository.php b/app/Repositories/Budget/NoBudgetRepository.php index f0874b6cd4..eb2dd385f9 100644 --- a/app/Repositories/Budget/NoBudgetRepository.php +++ b/app/Repositories/Budget/NoBudgetRepository.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace FireflyIII\Repositories\Budget; + use Carbon\Carbon; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Models\TransactionCurrency; @@ -146,8 +147,8 @@ class NoBudgetRepository implements NoBudgetRepositoryInterface /** @noinspection MoreThanThreeArgumentsInspection */ /** -* See reference nr. 15 -* See reference nr. 16 + * See reference nr. 15 + * See reference nr. 16 * * @param Carbon $start * @param Carbon $end diff --git a/app/Repositories/Budget/NoBudgetRepositoryInterface.php b/app/Repositories/Budget/NoBudgetRepositoryInterface.php index 74ddcedffb..0f6da40270 100644 --- a/app/Repositories/Budget/NoBudgetRepositoryInterface.php +++ b/app/Repositories/Budget/NoBudgetRepositoryInterface.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace FireflyIII\Repositories\Budget; + use Carbon\Carbon; use FireflyIII\Models\TransactionCurrency; use FireflyIII\User; diff --git a/app/Repositories/Budget/OperationsRepository.php b/app/Repositories/Budget/OperationsRepository.php index 198c82533e..5b6686a7e0 100644 --- a/app/Repositories/Budget/OperationsRepository.php +++ b/app/Repositories/Budget/OperationsRepository.php @@ -180,7 +180,7 @@ class OperationsRepository implements OperationsRepositoryInterface // add journal to array: // only a subset of the fields. - $journalId = (int)$journal['transaction_journal_id']; + $journalId = (int)$journal['transaction_journal_id']; $array[$currencyId]['budgets'][$budgetId]['transaction_journals'][$journalId] = [ 'amount' => app('steam')->negative($journal['amount']), 'destination_account_id' => $journal['destination_account_id'], @@ -227,7 +227,7 @@ class OperationsRepository implements OperationsRepositoryInterface if ($accounts->count() > 0) { $collector->setAccounts($accounts); } -// See reference nr. 13 + // See reference nr. 13 $set = $collector->getGroups(); $return = []; $total = []; @@ -343,23 +343,13 @@ class OperationsRepository implements OperationsRepositoryInterface $array[$foreignId]['sum'] = bcadd($array[$foreignId]['sum'], app('steam')->negative($journal['foreign_amount'])); } } + return $array; } - /** - * @return Collection - */ - private function getBudgets(): Collection - { - /** @var BudgetRepositoryInterface $repos */ - $repos = app(BudgetRepositoryInterface::class); - - return $repos->getActiveBudgets(); - } - /** * For now, simply refer to whichever repository holds this function. -* See reference nr. 14 + * See reference nr. 14 * * @param Budget $budget * @param Carbon|null $start @@ -374,4 +364,15 @@ class OperationsRepository implements OperationsRepositoryInterface return $blRepository->getBudgetLimits($budget, $start, $end); } + + /** + * @return Collection + */ + private function getBudgets(): Collection + { + /** @var BudgetRepositoryInterface $repos */ + $repos = app(BudgetRepositoryInterface::class); + + return $repos->getActiveBudgets(); + } } diff --git a/app/Repositories/Budget/OperationsRepositoryInterface.php b/app/Repositories/Budget/OperationsRepositoryInterface.php index 265dbbbc66..691ff64805 100644 --- a/app/Repositories/Budget/OperationsRepositoryInterface.php +++ b/app/Repositories/Budget/OperationsRepositoryInterface.php @@ -43,6 +43,7 @@ interface OperationsRepositoryInterface * @return string */ public function budgetedPerDay(Budget $budget): string; + /** * @param Collection $budgets * @param Collection $accounts