Various code cleanup.

This commit is contained in:
James Cole
2016-12-28 16:45:44 +01:00
parent 71195aa789
commit a37f70947b
9 changed files with 80 additions and 92 deletions

View File

@@ -31,6 +31,7 @@ use Log;
/**
* Class BalanceReportHelper
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) // I can't really help it.
* @package FireflyIII\Helpers\Report
*/
class BalanceReportHelper implements BalanceReportHelperInterface

View File

@@ -43,6 +43,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
}
/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
@@ -57,12 +58,8 @@ class BudgetReportHelper implements BudgetReportHelperInterface
/** @var Budget $budget */
foreach ($set as $budget) {
$repetitions = $budget->limitrepetitions()->before($end)->after($start)->get();
// no repetition(s) for this budget:
if ($repetitions->count() == 0) {
// spent for budget in time range:
$spent = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);
if ($repetitions->count() == 0) { // no repetition(s) for this budget
$spent = $this->repository->spentInPeriod(new Collection([$budget]), $accounts, $start, $end);// spent for budget in time range
if ($spent > 0) {
$budgetLine = new BudgetLine;
$budgetLine->setBudget($budget)->setOverspent($spent);
@@ -70,11 +67,9 @@ class BudgetReportHelper implements BudgetReportHelperInterface
}
continue;
}
// one or more repetitions for budget:
/** @var LimitRepetition $repetition */
foreach ($repetitions as $repetition) {
$data = $this->calculateExpenses($budget, $repetition, $accounts);
foreach ($repetitions as $repetition) { // one or more repetitions for budget
$data = $this->calculateExpenses($budget, $repetition, $accounts);
$budgetLine = new BudgetLine;
$budgetLine->setBudget($budget)->setRepetition($repetition)
->setLeft($data['left'])->setSpent($data['expenses'])->setOverspent($data['overspent'])
@@ -84,12 +79,8 @@ class BudgetReportHelper implements BudgetReportHelperInterface
->addLeft($data['left'])->addOverspent($data['overspent'])->addBudgetLine($budgetLine);
}
}
// stuff outside of budgets:
$noBudget = $this->repository->spentInPeriodWithoutBudget($accounts, $start, $end);
$noBudget = $this->repository->spentInPeriodWithoutBudget($accounts, $start, $end); // stuff outside of budgets
$budgetLine = new BudgetLine;
$budgetLine->setOverspent($noBudget)->setSpent($noBudget);
$object->addOverspent($noBudget)->addBudgetLine($budgetLine);

View File

@@ -53,6 +53,8 @@ class ReportHelper implements ReportHelperInterface
* This method generates a full report for the given period on all
* the users bills and their payments.
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
*
* Excludes bills which have not had a payment on the mentioned accounts.
*
* @param Carbon $start
@@ -80,8 +82,6 @@ class ReportHelper implements ReportHelperInterface
$billLine->setMin(strval($bill->amount_min));
$billLine->setMax(strval($bill->amount_max));
$billLine->setHit(false);
// is hit in period?
$entry = $journals->filter(
function (Transaction $transaction) use ($bill) {
return $transaction->bill_id === $bill->id;
@@ -94,14 +94,10 @@ class ReportHelper implements ReportHelperInterface
$billLine->setLastHitDate($first->date);
$billLine->setHit(true);
}
// bill is active, or bill is hit:
if ($billLine->isActive() || $billLine->isHit()) {
$collection->addBill($billLine);
}
}
// do some extra filtering.
$collection->filterBills();
return $collection;