Code clean up

This commit is contained in:
James Cole
2016-09-16 12:15:58 +02:00
parent f38984398d
commit d25d0454fc
52 changed files with 135 additions and 185 deletions

View File

@@ -12,7 +12,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Binder;
use Auth;
use FireflyIII\Models\Account;
use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -43,7 +42,7 @@ class AccountList implements BinderInterface
/** @var \Illuminate\Support\Collection $object */
$object = Account::leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->whereIn('accounts.id', $ids)
->where('user_id', Auth::user()->id)
->where('user_id', auth()->user()->id)
->get(['accounts.*']);
if ($object->count() > 0) {
return $object;

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Binder;
use Auth;
use FireflyIII\Models\Budget;
use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -38,7 +37,7 @@ class BudgetList implements BinderInterface
/** @var \Illuminate\Support\Collection $object */
$object = Budget::where('active', 1)
->whereIn('id', $ids)
->where('user_id', Auth::user()->id)
->where('user_id', auth()->user()->id)
->get();
// add empty budget if applicable.

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Binder;
use Auth;
use FireflyIII\Models\Category;
use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -36,7 +35,7 @@ class CategoryList implements BinderInterface
$ids = explode(',', $value);
/** @var \Illuminate\Support\Collection $object */
$object = Category::whereIn('id', $ids)
->where('user_id', Auth::user()->id)
->where('user_id', auth()->user()->id)
->get();
// add empty category if applicable.

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Binder;
use Auth;
use Carbon\Carbon;
use Exception;
use FireflyIII\Helpers\FiscalHelper;
@@ -42,7 +41,7 @@ class Date implements BinderInterface
try {
$date = new Carbon($value);
} catch (Exception $e) {
Log::error('Could not parse date "' . $value . '" for user #' . Auth::user()->id);
Log::error('Could not parse date "' . $value . '" for user #' . auth()->user()->id);
throw new NotFoundHttpException;
}

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Binder;
use Auth;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -37,7 +36,7 @@ class JournalList implements BinderInterface
/** @var \Illuminate\Support\Collection $object */
$object = TransactionJournal::whereIn('transaction_journals.id', $ids)
->expanded()
->where('transaction_journals.user_id', Auth::user()->id)
->where('transaction_journals.user_id', auth()->user()->id)
->get(TransactionJournal::queryFields());
if ($object->count() > 0) {

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Binder;
use Auth;
use FireflyIII\Models\TransactionJournal;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -36,7 +35,7 @@ class UnfinishedJournal implements BinderInterface
$object = TransactionJournal::where('transaction_journals.id', $value)
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->where('completed', 0)
->where('user_id', Auth::user()->id)->first(['transaction_journals.*']);
->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
if ($object) {
return $object;
}

View File

@@ -12,7 +12,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support;
use Auth;
use Cache;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
@@ -39,7 +38,7 @@ class CacheProperties
{
$this->properties = new Collection;
if (auth()->check()) {
$this->addProperty(Auth::user()->id);
$this->addProperty(auth()->user()->id);
$this->addProperty(Prefs::lastActivity());
}
}

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support;
use Auth;
use Cache;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Preference;
@@ -32,11 +31,11 @@ class FireflyConfig
*/
public function delete($name): bool
{
$fullName = 'preference' . Auth::user()->id . $name;
$fullName = 'preference' . auth()->user()->id . $name;
if (Cache::has($fullName)) {
Cache::forget($fullName);
}
Preference::where('user_id', Auth::user()->id)->where('name', $name)->delete();
Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete();
return true;
}

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support;
use Auth;
use Cache;
use FireflyIII\Models\Preference;
use FireflyIII\User;
@@ -31,11 +30,11 @@ class Preferences
*/
public function delete($name): bool
{
$fullName = 'preference' . Auth::user()->id . $name;
$fullName = 'preference' . auth()->user()->id . $name;
if (Cache::has($fullName)) {
Cache::forget($fullName);
}
Preference::where('user_id', Auth::user()->id)->where('name', $name)->delete();
Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete();
return true;
}
@@ -48,12 +47,12 @@ class Preferences
*/
public function get($name, $default = null)
{
$user = Auth::user();
$user = auth()->user();
if (is_null($user)) {
return $default;
}
return $this->getForUser(Auth::user(), $name, $default);
return $this->getForUser(auth()->user(), $name, $default);
}
/**
@@ -115,7 +114,7 @@ class Preferences
*/
public function set($name, $value): Preference
{
$user = Auth::user();
$user = auth()->user();
if (is_null($user)) {
// make new preference, return it:
$pref = new Preference;
@@ -125,7 +124,7 @@ class Preferences
return $pref;
}
return $this->setForUser(Auth::user(), $name, $value);
return $this->setForUser(auth()->user(), $name, $value);
}
/**

View File

@@ -12,7 +12,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Search;
use Auth;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\TransactionJournal;
@@ -33,7 +32,7 @@ class Search implements SearchInterface
*/
public function searchAccounts(array $words): Collection
{
return Auth::user()->accounts()->with('accounttype')->where(
return auth()->user()->accounts()->with('accounttype')->where(
function (EloquentBuilder $q) use ($words) {
foreach ($words as $word) {
$q->orWhere('name', 'LIKE', '%' . e($word) . '%');
@@ -50,7 +49,7 @@ class Search implements SearchInterface
public function searchBudgets(array $words): Collection
{
/** @var Collection $set */
$set = Auth::user()->budgets()->get();
$set = auth()->user()->budgets()->get();
$newSet = $set->filter(
function (Budget $b) use ($words) {
$found = 0;
@@ -75,7 +74,7 @@ class Search implements SearchInterface
public function searchCategories(array $words): Collection
{
/** @var Collection $set */
$set = Auth::user()->categories()->get();
$set = auth()->user()->categories()->get();
$newSet = $set->filter(
function (Category $c) use ($words) {
$found = 0;
@@ -111,7 +110,7 @@ class Search implements SearchInterface
public function searchTransactions(array $words): Collection
{
// decrypted transaction journals:
$decrypted = Auth::user()->transactionJournals()->expanded()->where('transaction_journals.encrypted', 0)->where(
$decrypted = auth()->user()->transactionJournals()->expanded()->where('transaction_journals.encrypted', 0)->where(
function (EloquentBuilder $q) use ($words) {
foreach ($words as $word) {
$q->orWhere('transaction_journals.description', 'LIKE', '%' . e($word) . '%');
@@ -120,7 +119,7 @@ class Search implements SearchInterface
)->get(TransactionJournal::queryFields());
// encrypted
$all = Auth::user()->transactionJournals()->expanded()->where('transaction_journals.encrypted', 1)->get(TransactionJournal::queryFields());
$all = auth()->user()->transactionJournals()->expanded()->where('transaction_journals.encrypted', 1)->get(TransactionJournal::queryFields());
$set = $all->filter(
function (TransactionJournal $journal) use ($words) {
foreach ($words as $word) {

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support;
use Auth;
use Carbon\Carbon;
use DB;
use FireflyIII\Models\Account;
@@ -185,10 +184,10 @@ class Steam
{
$list = [];
$set = Auth::user()->transactions()
->whereIn('transactions.account_id', $accounts)
->groupBy(['transactions.account_id', 'transaction_journals.user_id'])
->get(['transactions.account_id', DB::raw('MAX(`transaction_journals`.`date`) as `max_date`')]);
$set = auth()->user()->transactions()
->whereIn('transactions.account_id', $accounts)
->groupBy(['transactions.account_id', 'transaction_journals.user_id'])
->get(['transactions.account_id', DB::raw('MAX(`transaction_journals`.`date`) as `max_date`')]);
foreach ($set as $entry) {
$list[intval($entry->account_id)] = new Carbon($entry->max_date);

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Support\Twig;
use Auth;
use FireflyIII\Models\LimitRepetition;
use FireflyIII\Support\CacheProperties;
use Twig_Extension;
@@ -39,14 +38,14 @@ class Budget extends Twig_Extension
return $cache->get();
}
$sum
= Auth::user()->transactionJournals()
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id')
->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
->before($repetition->enddate)
->after($repetition->startdate)
->where('limit_repetitions.id', '=', $repetition->id)
->get(['transaction_journals.*'])->sum('amount');
= auth()->user()->transactionJournals()
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id')
->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')
->before($repetition->enddate)
->after($repetition->startdate)
->where('limit_repetitions.id', '=', $repetition->id)
->get(['transaction_journals.*'])->sum('amount');
$cache->store($sum);
return $sum;