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

@@ -614,9 +614,7 @@ class AccountRepository implements AccountRepositoryInterface
{
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
return $account;
return $service->update($account, $data);
}
/**
@@ -661,7 +659,7 @@ class AccountRepository implements AccountRepositoryInterface
/** @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());
@@ -670,8 +668,6 @@ class AccountRepository implements AccountRepositoryInterface
return $attachment;
}
);
return $set;
}
/**

View File

@@ -140,13 +140,10 @@ class BillRepository implements BillRepositoryInterface
*/
public function getActiveBills(): Collection
{
/** @var Collection $set */
$set = $this->user->bills()
return $this->user->bills()
->where('active', 1)
->orderBy('bills.name', 'ASC')
->get(['bills.*', DB::raw('((bills.amount_min + bills.amount_max) / 2) AS expectedAmount'),]);
return $set;
}
/**
@@ -163,7 +160,7 @@ class BillRepository implements BillRepositoryInterface
/** @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());
@@ -172,8 +169,6 @@ class BillRepository implements BillRepositoryInterface
return $attachment;
}
);
return $set;
}
/**
@@ -198,7 +193,7 @@ class BillRepository implements BillRepositoryInterface
$fields = ['bills.id', 'bills.created_at', 'bills.updated_at', 'bills.deleted_at', 'bills.user_id', 'bills.name', 'bills.amount_min',
'bills.amount_max', 'bills.date', 'bills.transaction_currency_id', 'bills.repeat_freq', 'bills.skip', 'bills.automatch', 'bills.active',];
$ids = $accounts->pluck('id')->toArray();
$set = $this->user->bills()
return $this->user->bills()
->leftJoin(
'transaction_journals',
static function (JoinClause $join) {
@@ -217,7 +212,6 @@ class BillRepository implements BillRepositoryInterface
->orderBy('bills.name', 'ASC')
->groupBy($fields)
->get($fields);
return $set;
}
/**

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

View File

@@ -168,10 +168,7 @@ class CategoryRepository implements CategoryRepositoryInterface
*/
public function getCategories(): Collection
{
/** @var Collection $set */
$set = $this->user->categories()->with(['attachments'])->orderBy('name', 'ASC')->get();
return $set;
return $this->user->categories()->with(['attachments'])->orderBy('name', 'ASC')->get();
}
/**
@@ -376,7 +373,7 @@ class CategoryRepository implements CategoryRepositoryInterface
/** @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());
@@ -385,7 +382,5 @@ class CategoryRepository implements CategoryRepositoryInterface
return $attachment;
}
);
return $set;
}
}

View File

@@ -312,9 +312,6 @@ class OperationsRepository implements OperationsRepositoryInterface
*/
private function getCategories(): Collection
{
/** @var Collection $set */
$set = $this->user->categories()->get();
return $set;
return $this->user->categories()->get();
}
}

View File

@@ -58,10 +58,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
{
$count = $currency->transactions()->whereNull('deleted_at')->count() + $currency->transactionJournals()->whereNull('deleted_at')->count();
// also count foreign:
$count += Transaction::where('foreign_currency_id', $currency->id)->count();
return $count;
return $count + Transaction::where('foreign_currency_id', $currency->id)->count();
}
/**

View File

@@ -37,18 +37,7 @@ use Storage;
*/
class JournalAPIRepository implements JournalAPIRepositoryInterface
{
/** @var User */
private $user;
/**
* Constructor.
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
private User $user;
/**
* Returns transaction by ID. Used to validate attachments.
@@ -59,12 +48,10 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
*/
public function findTransaction(int $transactionId): ?Transaction
{
$transaction = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
return Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.user_id', $this->user->id)
->where('transactions.id', $transactionId)
->first(['transactions.*']);
return $transaction;
}
/**
@@ -81,7 +68,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
/** @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());
@@ -90,8 +77,6 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
return $attachment;
}
);
return $set;
}
/**

View File

@@ -210,13 +210,11 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
$inward = TransactionJournalLink::whereDestinationId($journal->id)->get();
$merged = $outward->merge($inward);
$filtered = $merged->filter(
return $merged->filter(
function (TransactionJournalLink $link) {
return (null !== $link->source && null !== $link->destination);
}
);
return $filtered;
}
/**

View File

@@ -161,10 +161,7 @@ trait ModifiesPiggyBanks
if (0 === bccomp('0', $amount)) {
return new PiggyBankEvent;
}
/** @var PiggyBankEvent $event */
$event = PiggyBankEvent::create(['date' => Carbon::now(), 'amount' => $amount, 'piggy_bank_id' => $piggyBank->id]);
return $event;
return PiggyBankEvent::create(['date' => Carbon::now(), 'amount' => $amount, 'piggy_bank_id' => $piggyBank->id]);
}
/**
@@ -176,16 +173,13 @@ trait ModifiesPiggyBanks
*/
public function createEventWithJournal(PiggyBank $piggyBank, string $amount, TransactionJournal $journal): PiggyBankEvent
{
/** @var PiggyBankEvent $event */
$event = PiggyBankEvent::create(
return PiggyBankEvent::create(
[
'piggy_bank_id' => $piggyBank->id,
'transaction_journal_id' => $journal->id,
'date' => $journal->date->format('Y-m-d'),
'amount' => $amount]
);
return $event;
}
/**

View File

@@ -44,19 +44,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
{
use ModifiesPiggyBanks;
/** @var User */
private $user;
/**
* Constructor.
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
private User $user;
/**
* Find by name or return NULL.
@@ -384,7 +372,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
/** @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());
@@ -393,8 +381,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return $attachment;
}
);
return $set;
}

View File

@@ -53,18 +53,8 @@ use Log;
class RecurringRepository implements RecurringRepositoryInterface
{
use CalculateRangeOccurrences, CalculateXOccurrences, CalculateXOccurrencesSince, FiltersWeekends;
/** @var User */
private $user;
private User $user;
/**
* Constructor.
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
/**
* Destroy a recurring transaction.
@@ -246,9 +236,7 @@ class RecurringRepository implements RecurringRepositoryInterface
// filter out all the weekend days:
$occurrences = $this->filterWeekends($repetition, $occurrences);
return $occurrences;
return $this->filterWeekends($repetition, $occurrences);
}
/**
@@ -386,9 +374,7 @@ class RecurringRepository implements RecurringRepositoryInterface
}
// filter out all the weekend days:
$occurrences = $this->filterWeekends($repetition, $occurrences);
return $occurrences;
return $this->filterWeekends($repetition, $occurrences);
}
/**
@@ -536,9 +522,7 @@ class RecurringRepository implements RecurringRepositoryInterface
// filter out everything if "repeat_until" is set.
$repeatUntil = $repetition->recurrence->repeat_until;
$occurrences = $this->filterMaxDate($repeatUntil, $occurrences);
return $occurrences;
return $this->filterMaxDate($repeatUntil, $occurrences);
}
/**

View File

@@ -156,10 +156,7 @@ class TagRepository implements TagRepositoryInterface
*/
public function get(): Collection
{
/** @var Collection $tags */
$tags = $this->user->tags()->orderBy('tag', 'ASC')->get();
return $tags;
return $this->user->tags()->orderBy('tag', 'ASC')->get();
}
/**
@@ -575,7 +572,7 @@ class TagRepository implements TagRepositoryInterface
/** @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());
@@ -584,8 +581,6 @@ class TagRepository implements TagRepositoryInterface
return $attachment;
}
);
return $set;
}
/**