diff --git a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php index 4e446f617b..ef53c4b7bd 100644 --- a/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php +++ b/app/Generator/Chart/Account/ChartJsAccountChartGenerator.php @@ -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); diff --git a/app/Helpers/Csv/Wizard.php b/app/Helpers/Csv/Wizard.php index 148934ee60..03ed929ce0 100644 --- a/app/Helpers/Csv/Wizard.php +++ b/app/Helpers/Csv/Wizard.php @@ -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']) { diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index 6a634369b8..c7ec06cfcd 100755 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -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); } diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index 028174d80e..eb91f28e00 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -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) { diff --git a/app/Http/Controllers/CsvController.php b/app/Http/Controllers/CsvController.php index 9d71d394ad..0006d6cfa5 100644 --- a/app/Http/Controllers/CsvController.php +++ b/app/Http/Controllers/CsvController.php @@ -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: diff --git a/app/Http/Controllers/RuleController.php b/app/Http/Controllers/RuleController.php index 41489928db..9777a8f74a 100644 --- a/app/Http/Controllers/RuleController.php +++ b/app/Http/Controllers/RuleController.php @@ -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) { diff --git a/app/Http/Controllers/RuleGroupController.php b/app/Http/Controllers/RuleGroupController.php index 7c375cd027..e0dda063ea 100644 --- a/app/Http/Controllers/RuleGroupController.php +++ b/app/Http/Controllers/RuleGroupController.php @@ -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')); } diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index a5009e0cca..50760bd6dc 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -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()); diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index 1a57d10806..279fd8f67d 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -54,7 +54,6 @@ class FireflyServiceProvider extends ServiceProvider public function register() { - $this->app->bind( 'preferences', function () { return new Preferences; diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php index 534188bace..6d0cc981d2 100644 --- a/app/Repositories/Category/CategoryRepository.php +++ b/app/Repositories/Category/CategoryRepository.php @@ -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)) { diff --git a/app/Rules/Processor.php b/app/Rules/Processor.php index 49c7bd202b..eb932ca2ec 100644 --- a/app/Rules/Processor.php +++ b/app/Rules/Processor.php @@ -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 . ')'); diff --git a/app/Rules/Triggers/FromAccountEnds.php b/app/Rules/Triggers/FromAccountEnds.php index b207ef6ddd..57f686a063 100644 --- a/app/Rules/Triggers/FromAccountEnds.php +++ b/app/Rules/Triggers/FromAccountEnds.php @@ -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;