Refactor to remove deprecated methods.

This commit is contained in:
James Cole
2020-11-08 14:06:49 +01:00
parent 7efb77e000
commit d268931187
7 changed files with 7 additions and 175 deletions

View File

@@ -74,53 +74,6 @@ class OperationsRepository implements OperationsRepositoryInterface
return $avg;
}
/**
* This method collects various info on budgets, used on the budget page and on the index.
*
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @deprecated
*
*/
public function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array
{
// get account information
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$defaultCurrency = app('amount')->getDefaultCurrency();
$return = [];
/** @var Budget $budget */
foreach ($budgets as $budget) {
$budgetId = $budget->id;
$return[$budgetId] = [
'spent' => $this->spentInPeriod(new Collection([$budget]), $accounts, $start, $end),
'budgeted' => '0',
];
$budgetLimits = $this->getBudgetLimits($budget, $start, $end);
$otherLimits = new Collection;
// get all the budget limits relevant between start and end and examine them:
/** @var BudgetLimit $limit */
foreach ($budgetLimits as $limit) {
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)
) {
$return[$budgetId]['currentLimit'] = $limit;
$return[$budgetId]['budgeted'] = round($limit->amount, $defaultCurrency->decimal_places);
continue;
}
// otherwise it's just one of the many relevant repetitions:
$otherLimits->push($limit);
}
$return[$budgetId]['otherLimits'] = $otherLimits;
}
return $return;
}
/**
* This method is being used to generate the budget overview in the year/multi-year report. Its used
* in both the year/multi-year budget overview AND in the accompanying chart.
@@ -260,30 +213,6 @@ class OperationsRepository implements OperationsRepositoryInterface
$this->user = $user;
}
/**
* @param Collection $budgets
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @deprecated
*/
public function spentInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): string
{
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user);
$collector->setRange($start, $end)->setBudgets($budgets)->withBudgetInformation();
if ($accounts->count() > 0) {
$collector->setAccounts($accounts);
}
return $collector->getSum();
}
/** @noinspection MoreThanThreeArgumentsInspection */
/**
@@ -360,7 +289,8 @@ class OperationsRepository implements OperationsRepositoryInterface
): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
$start->startOfDay();
$end->endOfDay();
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setUser($this->user)->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL]);

View File

@@ -44,17 +44,6 @@ interface OperationsRepositoryInterface
*/
public function budgetedPerDay(Budget $budget): string;
/**
* This method collects various info on budgets, used on the budget page and on the index.
*
* @param Collection $budgets
* @param Carbon $start
* @param Carbon $end
*
* @return array
* @deprecated
*/
public function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array;
/**
* @param Collection $budgets
@@ -72,17 +61,6 @@ interface OperationsRepositoryInterface
*/
public function setUser(User $user): void;
/**
* @param Collection $budgets
* @param Collection $accounts
* @param Carbon $start
* @param Carbon $end
*
* @return string
* @deprecated
*/
public function spentInPeriod(Collection $budgets, Collection $accounts, Carbon $start, Carbon $end): string;
/**
* Return multi-currency spent information.
*