Code cleanup [skip ci]

This commit is contained in:
James Cole
2015-06-03 21:25:11 +02:00
parent 409ec2e086
commit cc7c2e952c
69 changed files with 695 additions and 716 deletions

View File

@@ -4,7 +4,6 @@ namespace FireflyIII\Repositories\Account;
use App;
use Auth;
use Cache;
use Carbon\Carbon;
use Config;
use DB;
@@ -117,7 +116,6 @@ class AccountRepository implements AccountRepositoryInterface
if ($cache->has()) {
return $cache->get();
}
$md5 = $cache->getMd5();
if ($preference->data == []) {
@@ -126,7 +124,7 @@ class AccountRepository implements AccountRepositoryInterface
$accounts = Auth::user()->accounts()->whereIn('id', $preference->data)->orderBy('accounts.name', 'ASC')->get(['accounts.*']);
}
Cache::forever($md5, $accounts);
$cache->store($accounts);
return $accounts;
}
@@ -144,14 +142,13 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function getFrontpageTransactions(Account $account, Carbon $start, Carbon $end)
{
$prop = new CacheProperties();
$prop->addProperty($account->id);
$prop->addProperty($start);
$prop->addProperty($end);
if ($prop->has()) {
return $prop->get();
$cache = new CacheProperties();
$cache->addProperty($account->id);
$cache->addProperty($start);
$cache->addProperty($end);
if ($cache->has()) {
return $cache->get();
}
$md5 = $prop->getMd5();
$set = Auth::user()
->transactionjournals()
@@ -166,7 +163,7 @@ class AccountRepository implements AccountRepositoryInterface
->orderBy('transaction_journals.id', 'DESC')
->take(10)
->get(['transaction_journals.*', 'transaction_currencies.symbol', 'transaction_types.type']);
Cache::forever($md5, $set);
$cache->store($set);
return $set;
}
@@ -238,7 +235,6 @@ class AccountRepository implements AccountRepositoryInterface
if ($cache->has()) {
return $cache->get();
}
$md5 = $cache->getMd5();
$ids = array_unique($ids);
if (count($ids) > 0) {
@@ -264,7 +260,7 @@ class AccountRepository implements AccountRepositoryInterface
}
);
Cache::forever($md5, $accounts);
$cache->store($accounts);
return $accounts;

View File

@@ -79,10 +79,10 @@ class BudgetRepository implements BudgetRepositoryInterface
/** @var Collection $repetitions */
return LimitRepetition::
leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00'))
->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00'))
->where('budget_limits.budget_id', $budget->id)
->get(['limit_repetitions.*']);
->where('limit_repetitions.startdate', '<=', $end->format('Y-m-d 00:00:00'))
->where('limit_repetitions.startdate', '>=', $start->format('Y-m-d 00:00:00'))
->where('budget_limits.budget_id', $budget->id)
->get(['limit_repetitions.*']);
}
/**
@@ -154,9 +154,9 @@ class BudgetRepository implements BudgetRepositoryInterface
$setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC');
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC');
$countQuery = $budget->transactionJournals();
@@ -196,9 +196,9 @@ class BudgetRepository implements BudgetRepositoryInterface
public function getLimitAmountOnDate(Budget $budget, Carbon $date)
{
$repetition = LimitRepetition::leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00'))
->where('budget_limits.budget_id', $budget->id)
->first(['limit_repetitions.*']);
->where('limit_repetitions.startdate', $date->format('Y-m-d 00:00:00'))
->where('budget_limits.budget_id', $budget->id)
->first(['limit_repetitions.*']);
if ($repetition) {
return floatval($repetition->amount);
@@ -216,15 +216,15 @@ class BudgetRepository implements BudgetRepositoryInterface
public function getWithoutBudget(Carbon $start, Carbon $end)
{
return Auth::user()
->transactionjournals()
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->whereNull('budget_transaction_journal.id')
->before($end)
->after($start)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*']);
->transactionjournals()
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->whereNull('budget_transaction_journal.id')
->before($end)
->after($start)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*']);
}
/**
@@ -236,22 +236,22 @@ class BudgetRepository implements BudgetRepositoryInterface
public function getWithoutBudgetSum(Carbon $start, Carbon $end)
{
$noBudgetSet = Auth::user()
->transactionjournals()
->whereNotIn(
'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) {
$query
->select('transaction_journals.id')
->from('transaction_journals')
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'))
->whereNotNull('budget_transaction_journal.budget_id');
}
)
->after($start)
->before($end)
->transactionTypes(['Withdrawal'])
->get(['transaction_journals.*'])->sum('amount');
->transactionjournals()
->whereNotIn(
'transaction_journals.id', function (QueryBuilder $query) use ($start, $end) {
$query
->select('transaction_journals.id')
->from('transaction_journals')
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->where('transaction_journals.date', '>=', $start->format('Y-m-d 00:00:00'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d 00:00:00'))
->whereNotNull('budget_transaction_journal.budget_id');
}
)
->after($start)
->before($end)
->transactionTypes(['Withdrawal'])
->get(['transaction_journals.*'])->sum('amount');
return floatval($noBudgetSet) * -1;
}
@@ -272,18 +272,18 @@ class BudgetRepository implements BudgetRepositoryInterface
} else {
// get all journals in this month where the asset account is NOT shared.
$sum = $budget->transactionjournals()
->before($end)
->after($start)
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin(
'account_meta', function (JoinClause $join) {
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
}
)
->where('account_meta.data', '!=', '"sharedAsset"')
->get(['transaction_journals.*'])
->sum('amount');
->before($end)
->after($start)
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin(
'account_meta', function (JoinClause $join) {
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
}
)
->where('account_meta.data', '!=', '"sharedAsset"')
->get(['transaction_journals.*'])
->sum('amount');
$sum = floatval($sum);
}

View File

@@ -49,7 +49,7 @@ class CategoryRepository implements CategoryRepositoryInterface
/** @var Collection $set */
$set = Auth::user()->categories()->orderBy('name', 'ASC')->get();
$set->sortBy(
function(Category $category) {
function (Category $category) {
return $category->name;
}
);
@@ -67,16 +67,16 @@ class CategoryRepository implements CategoryRepositoryInterface
public function getCategoriesAndExpensesCorrected($start, $end)
{
$set = Auth::user()->transactionjournals()
->leftJoin(
'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
)
->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id')
->before($end)
->where('categories.user_id', Auth::user()->id)
->after($start)
->transactionTypes(['Withdrawal'])
->groupBy('categories.id')
->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']);
->leftJoin(
'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id'
)
->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id')
->before($end)
->where('categories.user_id', Auth::user()->id)
->after($start)
->transactionTypes(['Withdrawal'])
->groupBy('categories.id')
->get(['categories.id as category_id', 'categories.encrypted as category_encrypted', 'categories.name', 'transaction_journals.*']);
$result = [];
foreach ($set as $entry) {
@@ -143,10 +143,10 @@ class CategoryRepository implements CategoryRepositoryInterface
public function getLatestActivity(Category $category)
{
$latest = $category->transactionjournals()
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->first();
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->first();
if ($latest) {
return $latest->date;
}
@@ -163,15 +163,15 @@ class CategoryRepository implements CategoryRepositoryInterface
public function getWithoutCategory(Carbon $start, Carbon $end)
{
return Auth::user()
->transactionjournals()
->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->whereNull('category_transaction_journal.id')
->before($end)
->after($start)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*']);
->transactionjournals()
->leftJoin('category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->whereNull('category_transaction_journal.id')
->before($end)
->after($start)
->orderBy('transaction_journals.date', 'DESC')
->orderBy('transaction_journals.order', 'ASC')
->orderBy('transaction_journals.id', 'DESC')
->get(['transaction_journals.*']);
}
/**
@@ -190,8 +190,8 @@ class CategoryRepository implements CategoryRepositoryInterface
// always ignore transfers between accounts!
$sum = floatval(
$category->transactionjournals()
->transactionTypes(['Withdrawal'])
->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount')
->transactionTypes(['Withdrawal'])
->before($end)->after($start)->get(['transaction_journals.*'])->sum('amount')
);
} else {
@@ -204,7 +204,7 @@ class CategoryRepository implements CategoryRepositoryInterface
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin(
'account_meta', function(JoinClause $join) {
'account_meta', function (JoinClause $join) {
$join->on('account_meta.account_id', '=', 'accounts.id')->where('account_meta.name', '=', 'accountRole');
}
)

View File

@@ -111,7 +111,7 @@ class JournalRepository implements JournalRepositoryInterface
*/
public function getJournalsOfTypes(array $types, $offset, $page)
{
$set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset)
$set = Auth::user()->transactionJournals()->transactionTypes($types)->withRelevantData()->take(50)->offset($offset)
->orderBy('date', 'DESC')
->orderBy('order', 'ASC')
->orderBy('id', 'DESC')

View File

@@ -102,7 +102,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
public function setOrder($id, $order)
{
$piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id)
->where('piggy_banks.id', $id)->first(['piggy_banks.*']);
->where('piggy_banks.id', $id)->first(['piggy_banks.*']);
if ($piggyBank) {
$piggyBank->order = $order;
$piggyBank->save();

View File

@@ -36,14 +36,14 @@ class ReminderRepository implements ReminderRepositoryInterface
$today = new Carbon;
// active reminders:
$active = Auth::user()->reminders()
->where('notnow', 0)
->where('active', 1)
->where('startdate', '<=', $today->format('Y-m-d 00:00:00'))
->where('enddate', '>=', $today->format('Y-m-d 00:00:00'))
->get();
->where('notnow', 0)
->where('active', 1)
->where('startdate', '<=', $today->format('Y-m-d 00:00:00'))
->where('enddate', '>=', $today->format('Y-m-d 00:00:00'))
->get();
$active->each(
function(Reminder $reminder) {
function (Reminder $reminder) {
$reminder->description = $this->helper->getReminderText($reminder);
}
);
@@ -58,11 +58,11 @@ class ReminderRepository implements ReminderRepositoryInterface
public function getDismissedReminders()
{
$dismissed = Auth::user()->reminders()
->where('notnow', 1)
->get();
->where('notnow', 1)
->get();
$dismissed->each(
function(Reminder $reminder) {
function (Reminder $reminder) {
$reminder->description = $this->helper->getReminderText($reminder);
}
);
@@ -77,18 +77,18 @@ class ReminderRepository implements ReminderRepositoryInterface
{
$expired = Auth::user()->reminders()
->where('notnow', 0)
->where('active', 1)
->where(
function (Builder $q) {
$today = new Carbon;
$q->where('startdate', '>', $today->format('Y-m-d 00:00:00'));
$q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00'));
}
)->get();
->where('notnow', 0)
->where('active', 1)
->where(
function (Builder $q) {
$today = new Carbon;
$q->where('startdate', '>', $today->format('Y-m-d 00:00:00'));
$q->orWhere('enddate', '<', $today->format('Y-m-d 00:00:00'));
}
)->get();
$expired->each(
function(Reminder $reminder) {
function (Reminder $reminder) {
$reminder->description = $this->helper->getReminderText($reminder);
}
);
@@ -106,7 +106,7 @@ class ReminderRepository implements ReminderRepositoryInterface
->get();
$inactive->each(
function(Reminder $reminder) {
function (Reminder $reminder) {
$reminder->description = $this->helper->getReminderText($reminder);
}
);

View File

@@ -109,7 +109,7 @@ class TagRepository implements TagRepositoryInterface
/** @var Collection $tags */
$tags = Auth::user()->tags()->get();
$tags->sortBy(
function(Tag $tag) {
function (Tag $tag) {
return $tag->tag;
}
);