Some code cleanup courtesy of PHPStorm.

This commit is contained in:
James Cole 2016-01-15 17:53:54 +01:00
parent 820722f44e
commit f69be86c74
12 changed files with 39 additions and 93 deletions

View File

@ -89,18 +89,13 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
{
// language:
$format = trans('config.month_and_day');
$data = [
'count' => 0,
'labels' => [],
'datasets' => [],
];
$data = ['count' => 0, 'labels' => [], 'datasets' => [],];
$current = clone $start;
while ($current <= $end) {
$data['labels'][] = $current->formatLocalized($format);
$current->addDay();
}
foreach ($accounts as $account) {
$set = [
'label' => $account->name,
@ -148,8 +143,8 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
'datasets' => [
[
'label' => $account->name,
'data' => []
]
'data' => [],
],
],
];
$range = Steam::balanceInRange($account, $start, $end);

View File

@ -63,7 +63,8 @@ class Wizard implements WizardInterface
if (is_array($map)) {
foreach ($map as $index => $field) {
$keys = array_keys($map);
foreach ($keys as $index) {
if (isset($roles[$index])) {
$name = $roles[$index];
if ($configRoles[$name]['mappable']) {

View File

@ -66,15 +66,7 @@ class AuthController extends Controller
*/
public function login(Request $request)
{
$this->validate(
$request, [
$this->loginUsername() => 'required', 'password' => 'required',
]
);
// If the class is using the ThrottlesLogins trait, we can automatically throttle
// the login attempts for this application. We'll key this by the username and
// the IP address of the client making these requests into this application.
$this->validate($request, [$this->loginUsername() => 'required', 'password' => 'required',]);
$throttles = $this->isUsingThrottlesLoginsTrait();
if ($throttles && $this->hasTooManyLoginAttempts($request)) {
@ -102,10 +94,6 @@ class AuthController extends Controller
$message = trans('firefly.' . $code . '_error', ['email' => $credentials['email']]);
}
// If the login attempt was unsuccessful we will increment the number of attempts
// to login and redirect the user back to the login form. Of course, when this
// user surpasses their maximum number of attempts they will get locked out.
if ($throttles) {
$this->incrementLoginAttempts($request);
}

View File

@ -43,6 +43,8 @@ class CategoryController extends Controller
* @param SCRI $repository
* @param Category $category
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function all(SCRI $repository, Category $category)
@ -67,7 +69,6 @@ class CategoryController extends Controller
$spentArray = $repository->spentPerDay($category, $start, $end);
$earnedArray = $repository->earnedPerDay($category, $start, $end);
while ($start <= $end) {
$currentEnd = Navigation::endOfPeriod($start, $range);
@ -161,23 +162,8 @@ class CategoryController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore
}
/**
* category
* year:
* spent: x
* earned: x
* year
* spent: x
* earned: x
*/
$entries = new Collection;
// go by category, not by year.
// given a set of categories and accounts, it should not be difficult to get
// the exact array of data we need.
// then get the data for "no category".
$set = $repository->listMultiYear($categories, $accounts, $start, $end);
$set = $repository->listMultiYear($categories, $accounts, $start, $end);
/** @var Category $category */
foreach ($categories as $category) {

View File

@ -79,8 +79,8 @@ class CsvController extends Controller
if ($this->data->hasHeaders()) {
$headers = $firstRow;
}
foreach (Config::get('csv.roles') as $name => $role) {
$keys = array_keys(Config::get('csv.roles'));
foreach ($keys as $name) {
$availableRoles[$name] = trans('firefly.csv_column_' . $name);//$role['name'];
}
ksort($availableRoles);
@ -105,7 +105,7 @@ class CsvController extends Controller
}
$data = [
'date-format' => Session::get('csv-date-format'),
'has-headers' => Session::get('csv-has-headers')
'has-headers' => Session::get('csv-has-headers'),
];
if (Session::has('csv-map')) {
$data['map'] = Session::get('csv-map');
@ -174,7 +174,7 @@ class CsvController extends Controller
$delimiters = [
',' => trans('form.csv_comma'),
';' => trans('form.csv_semicolon'),
'tab' => trans('form.csv_tab')
'tab' => trans('form.csv_tab'),
];
// get a list of asset accounts:

View File

@ -134,28 +134,20 @@ class RuleController extends Controller
{
// has old input?
if (Input::old()) {
// process old triggers.
$oldTriggers = $this->getPreviousTriggers();
$triggerCount = count($oldTriggers);
// process old actions
$oldActions = $this->getPreviousActions();
$actionCount = count($oldActions);
$oldActions = $this->getPreviousActions();
$actionCount = count($oldActions);
} else {
// get current triggers
$oldTriggers = $this->getCurrentTriggers($rule);
$triggerCount = count($oldTriggers);
// get current actions
$oldActions = $this->getCurrentActions($rule);
$actionCount = count($oldActions);
$oldActions = $this->getCurrentActions($rule);
$actionCount = count($oldActions);
}
// get rule trigger for update / store-journal:
$primaryTrigger = $rule->ruleTriggers()->where('trigger_type', 'user_action')->first()->trigger_value;
$subTitle = trans('firefly.edit_rule', ['title' => $rule->title]);
$subTitle = trans('firefly.edit_rule', ['title' => $rule->title]);
// put previous url in session if not redirect from store (not "return_to_edit").
if (Session::get('rules.rule.edit.fromUpdate') !== true) {

View File

@ -46,7 +46,7 @@ class RuleGroupController extends Controller
Session::flash('gaEventCategory', 'rules');
Session::flash('gaEventAction', 'create-rule-group');
return view('rules.rule-group.create', compact('subTitleIcon', 'what', 'subTitle'));
return view('rules.rule-group.create', compact('subTitleIcon', 'subTitle'));
}

View File

@ -58,9 +58,7 @@ class TransactionController extends Controller
$accounts = ExpandedForm::makeSelectList($repository->getAccounts(['Default account', 'Asset account']));
$budgets = ExpandedForm::makeSelectList(Auth::user()->budgets()->get());
$budgets[0] = trans('form.noBudget');
// piggy bank list:
$piggyBanks = Auth::user()->piggyBanks()->orderBy('order', 'ASC')->get();
$piggyBanks = Auth::user()->piggyBanks()->orderBy('order', 'ASC')->get();
/** @var PiggyBank $piggy */
foreach ($piggyBanks as $piggy) {
$piggy->name = $piggy->name . ' (' . Amount::format($piggy->currentRelevantRep()->currentamount, false) . ')';
@ -161,7 +159,7 @@ class TransactionController extends Controller
'date' => $journal->date->format('Y-m-d'),
'category' => '',
'budget_id' => 0,
'piggy_bank_id' => 0
'piggy_bank_id' => 0,
];
// get tags:
$preFilled['tags'] = join(',', $journal->tags->pluck('tag')->toArray());

View File

@ -54,7 +54,6 @@ class FireflyServiceProvider extends ServiceProvider
public function register()
{
$this->app->bind(
'preferences', function () {
return new Preferences;

View File

@ -76,22 +76,7 @@ class CategoryRepository implements CategoryRepositoryInterface
*/
public function listMultiYear(Collection $categories, Collection $accounts, Carbon $start, Carbon $end)
{
/*
* select categories.id, DATE_FORMAT(transaction_journals.date,"%Y") as dateFormatted, transaction_types.type, SUM(amount) as sum from categories
left join category_transaction_journal ON category_transaction_journal.category_id = categories.id
left join transaction_journals ON transaction_journals.id = category_transaction_journal.transaction_journal_id
left join transaction_types ON transaction_types.id = transaction_journals.transaction_type_id
left join transactions ON transactions.transaction_journal_id = transaction_journals.id
where
categories.user_id =1
and transaction_types.type in ("Withdrawal","Deposit")
and transactions.account_id IN (2,4,6,10,11,610,725,879,1248)
group by categories.id, transaction_types.type, dateFormatted
*/
$set = Auth::user()->categories()
->leftJoin('category_transaction_journal', 'category_transaction_journal.category_id', '=', 'categories.id')
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'category_transaction_journal.transaction_journal_id')
@ -100,6 +85,8 @@ group by categories.id, transaction_types.type, dateFormatted
->whereIn('transaction_types.type', [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL])
->whereIn('transactions.account_id', $accounts->pluck('id')->toArray())
->whereIn('categories.id', $categories->pluck('id')->toArray())
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d'))
->groupBy('categories.id')
->groupBy('transaction_types.type')
->groupBy('dateFormatted')
@ -108,7 +95,7 @@ group by categories.id, transaction_types.type, dateFormatted
'categories.*',
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y") as `dateFormatted`'),
'transaction_types.type',
DB::Raw('SUM(`amount`) as `sum`')
DB::Raw('SUM(`amount`) as `sum`'),
]
);
@ -158,7 +145,7 @@ group by categories.id, transaction_types.type, dateFormatted
[
'categories.*',
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
DB::Raw('SUM(`t_dest`.`amount`) AS `earned`')
DB::Raw('SUM(`t_dest`.`amount`) AS `earned`'),
]
);
@ -212,7 +199,7 @@ group by categories.id, transaction_types.type, dateFormatted
[
'categories.*',
DB::Raw('DATE_FORMAT(`transaction_journals`.`date`,"%Y-%m") as `dateFormatted`'),
DB::Raw('SUM(`t_src`.`amount`) AS `spent`')
DB::Raw('SUM(`t_src`.`amount`) AS `spent`'),
]
);
@ -286,7 +273,7 @@ group by categories.id, transaction_types.type, dateFormatted
$single = $query->first(
[
DB::Raw('SUM(`transactions`.`amount`) as `sum`')
DB::Raw('SUM(`transactions`.`amount`) as `sum`'),
]
);
if (!is_null($single)) {

View File

@ -72,7 +72,7 @@ class Processor
$foundTriggers = 0;
$hitTriggers = 0;
/** @var RuleTrigger $trigger */
foreach ($this->rule->ruleTriggers()->orderBy('order', 'ASC')->get() as $index => $trigger) {
foreach ($this->rule->ruleTriggers()->orderBy('order', 'ASC')->get() as $trigger) {
$foundTriggers++;
$type = $trigger->trigger_type;
@ -110,7 +110,7 @@ class Processor
* @var int $index
* @var RuleAction $action
*/
foreach ($this->rule->ruleActions()->orderBy('order', 'ASC')->get() as $index => $action) {
foreach ($this->rule->ruleActions()->orderBy('order', 'ASC')->get() as $action) {
$type = $action->action_type;
$class = $this->actionTypes[$type];
Log::debug('Action #' . $action->id . ' for rule #' . $action->rule_id . ' (' . $type . ')');

View File

@ -44,29 +44,29 @@ class FromAccountEnds implements TriggerInterface
*/
public function triggered()
{
$fromAccountName = strtolower($this->journal->source_account->name);
$fromAccountNameLength = strlen($fromAccountName);
$search = strtolower($this->trigger->trigger_value);
$searchLength = strlen($search);
$name = strtolower($this->journal->source_account->name);
$nameLength = strlen($name);
$search = strtolower($this->trigger->trigger_value);
$searchLength = strlen($search);
// if the string to search for is longer than the account name,
// shorten the search string.
if ($searchLength > $fromAccountNameLength) {
Log::debug('Search string "' . $search . '" (' . $searchLength . ') is longer than "' . $fromAccountName . '" (' . $fromAccountNameLength . '). ');
$search = substr($search, ($fromAccountNameLength * -1));
if ($searchLength > $nameLength) {
Log::debug('Search string "' . $search . '" (' . $searchLength . ') is longer than "' . $name . '" (' . $nameLength . '). ');
$search = substr($search, ($nameLength * -1));
$searchLength = strlen($search);
Log::debug('Search string is now "' . $search . '" (' . $searchLength . ') instead.');
}
$part = substr($fromAccountName, $searchLength * -1);
$part = substr($name, $searchLength * -1);
if ($part == $search) {
Log::debug('"' . $fromAccountName . '" ends with "' . $search . '". Return true.');
Log::debug('"' . $name . '" ends with "' . $search . '". Return true.');
return true;
}
Log::debug('"' . $fromAccountName . '" does not end with "' . $search . '". Return false.');
Log::debug('"' . $name . '" does not end with "' . $search . '". Return false.');
return false;