Clean up code.

This commit is contained in:
James Cole
2020-10-23 19:11:25 +02:00
parent 0845e1cb7d
commit 8dbd785ab8
57 changed files with 84 additions and 441 deletions

View File

@@ -148,13 +148,11 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
{
// both are NULL:
if (null === $start && null === $end) {
$set = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
return BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->with(['budget'])
->where('budgets.user_id', $this->user->id)
->whereNull('budgets.deleted_at')
->get(['budget_limits.*']);
return $set;
}
// one of the two is NULL.
if (null === $start xor null === $end) {
@@ -170,12 +168,10 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
// start date must be after $start.
$query->where('start_date', '>=', $start->format('Y-m-d 00:00:00'));
}
$set = $query->get(['budget_limits.*']);
return $set;
return $query->get(['budget_limits.*']);
}
// neither are NULL:
$set = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
return BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
->with(['budget'])
->where('budgets.user_id', $this->user->id)
->whereNull('budgets.deleted_at')
@@ -206,8 +202,6 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
);
}
)->get(['budget_limits.*']);
return $set;
}
/**
@@ -250,13 +244,11 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
// start date must be after $start.
$query->where('start_date', '>=', $start->format('Y-m-d 00:00:00'));
}
$set = $query->get(['budget_limits.*']);
return $set;
return $query->get(['budget_limits.*']);
}
// when both dates are set:
$set = $budget->budgetlimits()
return $budget->budgetlimits()
->where(
static function (Builder $q5) use ($start, $end) {
$q5->where(
@@ -286,8 +278,6 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
);
}
)->orderBy('budget_limits.start_date', 'DESC')->get(['budget_limits.*']);
return $set;
}
/**

View File

@@ -170,12 +170,10 @@ class BudgetRepository implements BudgetRepositoryInterface
*/
public function getActiveBudgets(): Collection
{
/** @var Collection $set */
$set = $this->user->budgets()->where('active', 1)
return $this->user->budgets()->where('active', 1)
->orderBy('order', 'ASC')
->orderBy('name', 'ASC')
->get();
return $set;
}
/**
@@ -183,11 +181,8 @@ class BudgetRepository implements BudgetRepositoryInterface
*/
public function getBudgets(): Collection
{
/** @var Collection $set */
$set = $this->user->budgets()->orderBy('order', 'ASC')
return $this->user->budgets()->orderBy('order', 'ASC')
->orderBy('name', 'ASC')->get();
return $set;
}
/**
@@ -207,12 +202,9 @@ class BudgetRepository implements BudgetRepositoryInterface
*/
public function getInactiveBudgets(): Collection
{
/** @var Collection $set */
$set = $this->user->budgets()
return $this->user->budgets()
->orderBy('order', 'ASC')
->orderBy('name', 'ASC')->where('active', 0)->get();
return $set;
}
/**
@@ -475,7 +467,7 @@ class BudgetRepository implements BudgetRepositoryInterface
/** @var Storage $disk */
$disk = Storage::disk('upload');
$set = $set->each(
return $set->each(
static function (Attachment $attachment) use ($disk) {
$notes = $attachment->notes()->first();
$attachment->file_exists = $disk->exists($attachment->fileName());
@@ -484,8 +476,6 @@ class BudgetRepository implements BudgetRepositoryInterface
return $attachment;
}
);
return $set;
}
public function getMaxOrder(): int