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

@@ -99,4 +99,12 @@ class CacheProperties
$this->md5 = md5($this->md5);
}
/**
* @param $data
*/
public function store($data)
{
Cache::forever($this->md5, $data);
}
}

View File

@@ -118,7 +118,7 @@ class Navigation
'year' => 'endOfYear',
'yearly' => 'endOfYear',
];
$specials = ['mont', 'monthly'];
$specials = ['mont', 'monthly'];
$currentEnd = clone $theCurrentEnd;
@@ -270,7 +270,7 @@ class Navigation
'3M' => 'lastOfQuarter',
'1Y' => 'endOfYear',
];
$end = clone $start;
$end = clone $start;
if (isset($functionMap[$range])) {
$function = $functionMap[$range];

View File

@@ -4,6 +4,7 @@ namespace FireflyIII\Support;
use Auth;
use FireflyIII\Models\Preference;
/**
* Class Preferences
*
@@ -21,14 +22,6 @@ class Preferences
return md5($preference);
}
/**
* @return bool
*/
public function mark() {
$this->set('lastActivity',microtime());
return true;
}
/**
* @param $name
* @param null $default
@@ -85,4 +78,14 @@ class Preferences
return $pref;
}
/**
* @return bool
*/
public function mark()
{
$this->set('lastActivity', microtime());
return true;
}
}

View File

@@ -25,7 +25,7 @@ class Search implements SearchInterface
public function searchAccounts(array $words)
{
return Auth::user()->accounts()->with('accounttype')->where(
function(EloquentBuilder $q) use ($words) {
function (EloquentBuilder $q) use ($words) {
foreach ($words as $word) {
$q->orWhere('name', 'LIKE', '%' . e($word) . '%');
}
@@ -43,7 +43,7 @@ class Search implements SearchInterface
/** @var Collection $set */
$set = Auth::user()->budgets()->get();
$newSet = $set->filter(
function(Budget $b) use ($words) {
function (Budget $b) use ($words) {
$found = 0;
foreach ($words as $word) {
if (!(strpos(strtolower($b->name), strtolower($word)) === false)) {
@@ -68,7 +68,7 @@ class Search implements SearchInterface
/** @var Collection $set */
$set = Auth::user()->categories()->get();
$newSet = $set->filter(
function(Category $c) use ($words) {
function (Category $c) use ($words) {
$found = 0;
foreach ($words as $word) {
if (!(strpos(strtolower($c->name), strtolower($word)) === false)) {
@@ -103,7 +103,7 @@ class Search implements SearchInterface
{
// decrypted transaction journals:
$decrypted = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 0)->where(
function(EloquentBuilder $q) use ($words) {
function (EloquentBuilder $q) use ($words) {
foreach ($words as $word) {
$q->orWhere('description', 'LIKE', '%' . e($word) . '%');
}
@@ -113,7 +113,7 @@ class Search implements SearchInterface
// encrypted
$all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get();
$set = $all->filter(
function(TransactionJournal $journal) use ($words) {
function (TransactionJournal $journal) use ($words) {
foreach ($words as $word) {
$haystack = strtolower($journal->description);
$word = strtolower($word);
@@ -129,7 +129,7 @@ class Search implements SearchInterface
$filtered = $set->merge($decrypted);
$filtered->sortBy(
function(TransactionJournal $journal) {
function (TransactionJournal $journal) {
return intval($journal->date->format('U'));
}
);

View File

@@ -2,7 +2,6 @@
namespace FireflyIII\Support;
use Cache;
use Carbon\Carbon;
use FireflyIII\Models\Account;
@@ -25,15 +24,14 @@ class Steam
{
// abuse chart properties:
$properties = new CacheProperties;
$properties->addProperty($account->id);
$properties->addProperty('balance');
$properties->addProperty($date);
$properties->addProperty($ignoreVirtualBalance);
if ($properties->has()) {
return $properties->get();
$cache = new CacheProperties;
$cache->addProperty($account->id);
$cache->addProperty('balance');
$cache->addProperty($date);
$cache->addProperty($ignoreVirtualBalance);
if ($cache->has()) {
return $cache->get();
}
$md5 = $properties->getMd5();
// find the first known transaction on this account:
@@ -57,7 +55,7 @@ class Steam
if (!$ignoreVirtualBalance) {
$balance = bcadd($balance, $account->virtual_balance);
}
Cache::forever($md5, round($balance, 2));
$cache->store(round($balance, 2));
return round($balance, 2);
}

View File

@@ -19,18 +19,18 @@ class Budget extends Twig_Extension
*/
public function getFunctions()
{
$functions = [];
$functions = [];
$functions[] = new Twig_SimpleFunction(
'spentInRepetitionCorrected', function(LimitRepetition $repetition) {
'spentInRepetitionCorrected', function (LimitRepetition $repetition) {
$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');
->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');
return floatval($sum);
}

View File

@@ -31,31 +31,31 @@ class General extends Twig_Extension
$filters = [];
$filters[] = new Twig_SimpleFilter(
'formatAmount', function($string) {
'formatAmount', function ($string) {
return App::make('amount')->format($string);
}, ['is_safe' => ['html']]
);
$filters[] = new Twig_SimpleFilter(
'formatTransaction', function(Transaction $transaction) {
'formatTransaction', function (Transaction $transaction) {
return App::make('amount')->formatTransaction($transaction);
}, ['is_safe' => ['html']]
);
$filters[] = new Twig_SimpleFilter(
'formatAmountPlain', function($string) {
'formatAmountPlain', function ($string) {
return App::make('amount')->format($string, false);
}, ['is_safe' => ['html']]
);
$filters[] = new Twig_SimpleFilter(
'formatJournal', function($journal) {
'formatJournal', function ($journal) {
return App::make('amount')->formatJournal($journal);
}, ['is_safe' => ['html']]
);
$filters[] = new Twig_SimpleFilter(
'balance', function(Account $account = null) {
'balance', function (Account $account = null) {
if (is_null($account)) {
return 'NULL';
}
@@ -67,7 +67,7 @@ class General extends Twig_Extension
// should be a function but OK
$filters[] = new Twig_SimpleFilter(
'getAccountRole', function($name) {
'getAccountRole', function ($name) {
return Config::get('firefly.accountRoles.' . $name);
}
);
@@ -83,32 +83,32 @@ class General extends Twig_Extension
$functions = [];
$functions[] = new Twig_SimpleFunction(
'getCurrencyCode', function() {
'getCurrencyCode', function () {
return App::make('amount')->getCurrencyCode();
}
);
$functions[] = new Twig_SimpleFunction(
'getCurrencySymbol', function() {
'getCurrencySymbol', function () {
return App::make('amount')->getCurrencySymbol();
}
);
$functions[] = new Twig_SimpleFunction(
'phpdate', function($str) {
'phpdate', function ($str) {
return date($str);
}
);
$functions[] = new Twig_SimpleFunction(
'env', function($name, $default) {
'env', function ($name, $default) {
return env($name, $default);
}
);
$functions[] = new Twig_SimpleFunction(
'activeRoute', function($context) {
'activeRoute', function ($context) {
$args = func_get_args();
$route = $args[1];
$what = isset($args[2]) ? $args[2] : false;

View File

@@ -4,7 +4,6 @@ namespace FireflyIII\Support\Twig;
use App;
use Cache;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Support\CacheProperties;
use Twig_Extension;
@@ -30,13 +29,12 @@ class Journal extends Twig_Extension
$filters[] = new Twig_SimpleFilter(
'typeIcon', function (TransactionJournal $journal) {
$prop = new CacheProperties();
$prop->addProperty($journal->id);
$prop->addProperty('typeIcon');
if ($prop->has()) {
return $prop->get();
$cache = new CacheProperties();
$cache->addProperty($journal->id);
$cache->addProperty('typeIcon');
if ($cache->has()) {
return $cache->get();
}
$md5 = $prop->getMd5();
$type = $journal->transactionType->type;
@@ -57,7 +55,7 @@ class Journal extends Twig_Extension
$txt = '';
break;
}
Cache::forever($md5, $txt);
$cache->store($txt);
return $txt;

View File

@@ -22,7 +22,7 @@ class PiggyBank extends Twig_Extension
$functions = [];
$functions[] = new Twig_SimpleFunction(
'currentRelevantRepAmount', function(PB $piggyBank) {
'currentRelevantRepAmount', function (PB $piggyBank) {
return $piggyBank->currentRelevantRep()->currentamount;
}
);

View File

@@ -21,7 +21,7 @@ class Translation extends Twig_Extension
$filters = [];
$filters[] = new Twig_SimpleFilter(
'_', function($name) {
'_', function ($name) {
return trans('firefly.' . $name);