mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-06 06:01:21 +00:00
Various PSR12 code cleanup
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AutoCompleteController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* BoxController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -37,7 +38,6 @@ use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use JsonException;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ class BoxController extends Controller
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$today = today(config('app.timezone'));
|
||||
$display = 2; // see method docs.
|
||||
$boxTitle = (string) trans('firefly.spent');
|
||||
$boxTitle = (string)trans('firefly.spent');
|
||||
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty($start);
|
||||
@@ -92,21 +92,21 @@ class BoxController extends Controller
|
||||
// spent in this period, in budgets, for default currency.
|
||||
// also calculate spent per day.
|
||||
$spent = $opsRepository->sumExpenses($start, $end, null, null, $currency);
|
||||
$spentAmount = $spent[(int) $currency->id]['sum'] ?? '0';
|
||||
$spentAmount = $spent[(int)$currency->id]['sum'] ?? '0';
|
||||
|
||||
$days = $today->between($start, $end) ? $today->diffInDays($start) + 1 : $end->diffInDays($start) + 1;
|
||||
$spentPerDay = bcdiv($spentAmount, (string) $days);
|
||||
$spentPerDay = bcdiv($spentAmount, (string)$days);
|
||||
if ($availableBudgets->count() > 0) {
|
||||
$display = 0; // assume user overspent
|
||||
$boxTitle = (string) trans('firefly.overspent');
|
||||
$totalAvailableSum = (string) $availableBudgets->sum('amount');
|
||||
$boxTitle = (string)trans('firefly.overspent');
|
||||
$totalAvailableSum = (string)$availableBudgets->sum('amount');
|
||||
// calculate with available budget.
|
||||
$leftToSpendAmount = bcadd($totalAvailableSum, $spentAmount);
|
||||
if (1 === bccomp($leftToSpendAmount, '0')) {
|
||||
$boxTitle = (string) trans('firefly.left_to_spend');
|
||||
$boxTitle = (string)trans('firefly.left_to_spend');
|
||||
$days = $today->diffInDays($end) + 1;
|
||||
$display = 1; // not overspent
|
||||
$leftPerDayAmount = bcdiv($leftToSpendAmount, (string) $days);
|
||||
$leftPerDayAmount = bcdiv($leftToSpendAmount, (string)$days);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ class BoxController extends Controller
|
||||
/**
|
||||
* Current total balance.
|
||||
*
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
* @param CurrencyRepositoryInterface $repository
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
@@ -159,7 +159,7 @@ class BoxController extends Controller
|
||||
$set = $collector->getExtractedJournals();
|
||||
/** @var array $journal */
|
||||
foreach ($set as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$amount = $journal['amount'] ?? '0';
|
||||
$incomes[$currencyId] = $incomes[$currencyId] ?? '0';
|
||||
$incomes[$currencyId] = bcadd($incomes[$currencyId], app('steam')->positive($amount));
|
||||
@@ -175,7 +175,7 @@ class BoxController extends Controller
|
||||
$set = $collector->getExtractedJournals();
|
||||
/** @var array $journal */
|
||||
foreach ($set as $journal) {
|
||||
$currencyId = (int) $journal['currency_id'];
|
||||
$currencyId = (int)$journal['currency_id'];
|
||||
$expenses[$currencyId] = $expenses[$currencyId] ?? '0';
|
||||
$expenses[$currencyId] = bcadd($expenses[$currencyId], $journal['amount'] ?? '0');
|
||||
$sums[$currencyId] = $sums[$currencyId] ?? '0';
|
||||
|
||||
@@ -64,7 +64,7 @@ class BudgetController extends Controller
|
||||
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('title', (string) trans('firefly.budgets'));
|
||||
app('view')->share('title', (string)trans('firefly.budgets'));
|
||||
app('view')->share('mainTitleIcon', 'fa-pie-chart');
|
||||
$this->repository = app(BudgetRepositoryInterface::class);
|
||||
$this->opsRepository = app(OperationsRepositoryInterface::class);
|
||||
@@ -79,9 +79,9 @@ class BudgetController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param TransactionCurrency $currency
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* IntroController.php
|
||||
* Copyright (c) 2019 james@firefly-iii.org
|
||||
@@ -38,8 +39,8 @@ class IntroController extends Controller
|
||||
/**
|
||||
* Returns the introduction wizard for a page.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string|null $specificPage
|
||||
* @param string $route
|
||||
* @param string|null $specificPage
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
@@ -73,7 +74,7 @@ class IntroController extends Controller
|
||||
/**
|
||||
* Returns true if there is a general outro step.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string $route
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
@@ -98,8 +99,8 @@ class IntroController extends Controller
|
||||
/**
|
||||
* Enable the boxes for a specific page again.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string|null $specialPage
|
||||
* @param string $route
|
||||
* @param string|null $specialPage
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
@@ -108,22 +109,22 @@ class IntroController extends Controller
|
||||
{
|
||||
$specialPage = $specialPage ?? '';
|
||||
$route = str_replace('.', '_', $route);
|
||||
$key = 'shown_demo_' . $route;
|
||||
$key = 'shown_demo_'.$route;
|
||||
if ('' !== $specialPage) {
|
||||
$key .= '_' . $specialPage;
|
||||
$key .= '_'.$specialPage;
|
||||
}
|
||||
Log::debug(sprintf('Going to mark the following route as NOT done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||
app('preferences')->set($key, false);
|
||||
app('preferences')->mark();
|
||||
|
||||
return response()->json(['message' => (string) trans('firefly.intro_boxes_after_refresh')]);
|
||||
return response()->json(['message' => (string)trans('firefly.intro_boxes_after_refresh')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set that you saw them.
|
||||
*
|
||||
* @param string $route
|
||||
* @param string|null $specialPage
|
||||
* @param string $route
|
||||
* @param string|null $specialPage
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
@@ -131,9 +132,9 @@ class IntroController extends Controller
|
||||
public function postFinished(string $route, string $specialPage = null): JsonResponse // @phpstan-ignore-line
|
||||
{
|
||||
$specialPage = $specialPage ?? '';
|
||||
$key = 'shown_demo_' . $route;
|
||||
$key = 'shown_demo_'.$route;
|
||||
if ('' !== $specialPage) {
|
||||
$key .= '_' . $specialPage;
|
||||
$key .= '_'.$specialPage;
|
||||
}
|
||||
Log::debug(sprintf('Going to mark the following route as done: %s with special "%s" (%s)', $route, $specialPage, $key));
|
||||
app('preferences')->set($key, true);
|
||||
|
||||
@@ -63,7 +63,7 @@ class ReconcileController extends Controller
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||
app('view')->share('title', (string) trans('firefly.accounts'));
|
||||
app('view')->share('title', (string)trans('firefly.accounts'));
|
||||
$this->repository = app(JournalRepositoryInterface::class);
|
||||
$this->accountRepos = app(AccountRepositoryInterface::class);
|
||||
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
@@ -76,10 +76,10 @@ class ReconcileController extends Controller
|
||||
/**
|
||||
* Overview of reconciliation.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Account|null $account
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Request $request
|
||||
* @param Account|null $account
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
@@ -176,10 +176,10 @@ class ReconcileController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $journal
|
||||
* @param string $amount
|
||||
* @param Account $account
|
||||
* @param TransactionCurrency $currency
|
||||
* @param array $journal
|
||||
* @param string $amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -218,9 +218,9 @@ class ReconcileController extends Controller
|
||||
/**
|
||||
* Returns a list of transactions in a modal.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
* @param Account $account
|
||||
* @param Carbon|null $start
|
||||
* @param Carbon|null $end
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
@@ -274,8 +274,8 @@ class ReconcileController extends Controller
|
||||
/**
|
||||
* "fix" amounts to make it easier on the reconciliation overview:
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $array
|
||||
* @param Account $account
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
||||
@@ -31,6 +31,8 @@ use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Log;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* Class RecurrenceController
|
||||
@@ -61,7 +63,7 @@ class RecurrenceController extends Controller
|
||||
/**
|
||||
* Shows all events for a repetition. Used in calendar.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*
|
||||
@@ -73,10 +75,10 @@ class RecurrenceController extends Controller
|
||||
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
|
||||
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
|
||||
$firstDate = Carbon::createFromFormat('Y-m-d', $request->get('first_date'));
|
||||
$endDate = '' !== (string) $request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null;
|
||||
$endsAt = (string) $request->get('ends');
|
||||
$endDate = '' !== (string)$request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null;
|
||||
$endsAt = (string)$request->get('ends');
|
||||
$repetitionType = explode(',', $request->get('type'))[0];
|
||||
$repetitions = (int) $request->get('reps');
|
||||
$repetitions = (int)$request->get('reps');
|
||||
$repetitionMoment = '';
|
||||
$start->startOfDay();
|
||||
|
||||
@@ -100,8 +102,8 @@ class RecurrenceController extends Controller
|
||||
$repetition = new RecurrenceRepetition();
|
||||
$repetition->repetition_type = $repetitionType;
|
||||
$repetition->repetition_moment = $repetitionMoment;
|
||||
$repetition->repetition_skip = (int) $request->get('skip');
|
||||
$repetition->weekend = (int) $request->get('weekend');
|
||||
$repetition->repetition_skip = (int)$request->get('skip');
|
||||
$repetition->weekend = (int)$request->get('weekend');
|
||||
$actualEnd = clone $end;
|
||||
|
||||
switch ($endsAt) {
|
||||
@@ -122,7 +124,7 @@ class RecurrenceController extends Controller
|
||||
foreach ($occurrences as $current) {
|
||||
if ($current->gte($start)) {
|
||||
$event = [
|
||||
'id' => $repetitionType . $firstDate->format('Ymd'),
|
||||
'id' => $repetitionType.$firstDate->format('Ymd'),
|
||||
'title' => 'X',
|
||||
'allDay' => true,
|
||||
'start' => $current->format('Y-m-d'),
|
||||
@@ -140,43 +142,51 @@ class RecurrenceController extends Controller
|
||||
/**
|
||||
* Suggests repetition moments.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
* @throws FireflyException
|
||||
* @throws \Psr\Container\ContainerExceptionInterface
|
||||
* @throws \Psr\Container\NotFoundExceptionInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function suggest(Request $request): JsonResponse
|
||||
{
|
||||
$string = $request->get('date') ?? date('Y-m-d');
|
||||
$today = Carbon::now()->startOfDay();
|
||||
$date = Carbon::createFromFormat('Y-m-d', $string)->startOfDay();
|
||||
$preSelected = (string) $request->get('pre_select');
|
||||
$preSelected = (string)$request->get('pre_select');
|
||||
$locale = app('steam')->getLocale();
|
||||
|
||||
Log::debug(sprintf('date = %s, today = %s. date > today? %s', $date->toAtomString(), $today->toAtomString(), var_export($date > $today, true)));
|
||||
Log::debug(sprintf('past = true? %s', var_export('true' === (string) $request->get('past'), true)));
|
||||
Log::debug(sprintf('past = true? %s', var_export('true' === (string)$request->get('past'), true)));
|
||||
|
||||
$result = [];
|
||||
if ($date > $today || 'true' === (string) $request->get('past')) {
|
||||
if ($date > $today || 'true' === (string)$request->get('past')) {
|
||||
Log::debug('Will fill dropdown.');
|
||||
$weekly = sprintf('weekly,%s', $date->dayOfWeekIso);
|
||||
$monthly = sprintf('monthly,%s', $date->day);
|
||||
$dayOfWeek = (string) trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
|
||||
$dayOfWeek = (string)trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
|
||||
$ndom = sprintf('ndom,%s,%s', $date->weekOfMonth, $date->dayOfWeekIso);
|
||||
$yearly = sprintf('yearly,%s', $date->format('Y-m-d'));
|
||||
$yearlyDate = $date->isoFormat((string) trans('config.month_and_day_no_year_js', [], $locale));
|
||||
$yearlyDate = $date->isoFormat((string)trans('config.month_and_day_no_year_js', [], $locale));
|
||||
$result = [
|
||||
'daily' => ['label' => (string) trans('firefly.recurring_daily'), 'selected' => str_starts_with($preSelected, 'daily')],
|
||||
$weekly => ['label' => (string) trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
|
||||
'selected' => str_starts_with($preSelected, 'weekly')],
|
||||
$monthly => ['label' => (string) trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]),
|
||||
'selected' => str_starts_with($preSelected, 'monthly')],
|
||||
$ndom => ['label' => (string) trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]),
|
||||
'selected' => str_starts_with($preSelected, 'ndom')],
|
||||
$yearly => ['label' => (string) trans('firefly.recurring_yearly', ['date' => $yearlyDate]),
|
||||
'selected' => str_starts_with($preSelected, 'yearly')],
|
||||
'daily' => ['label' => (string)trans('firefly.recurring_daily'), 'selected' => str_starts_with($preSelected, 'daily')],
|
||||
$weekly => [
|
||||
'label' => (string)trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
|
||||
'selected' => str_starts_with($preSelected, 'weekly'),
|
||||
],
|
||||
$monthly => [
|
||||
'label' => (string)trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]),
|
||||
'selected' => str_starts_with($preSelected, 'monthly'),
|
||||
],
|
||||
$ndom => [
|
||||
'label' => (string)trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]),
|
||||
'selected' => str_starts_with($preSelected, 'ndom'),
|
||||
],
|
||||
$yearly => [
|
||||
'label' => (string)trans('firefly.recurring_yearly', ['date' => $yearlyDate]),
|
||||
'selected' => str_starts_with($preSelected, 'yearly'),
|
||||
],
|
||||
];
|
||||
}
|
||||
Log::debug('Dropdown is', $result);
|
||||
|
||||
@@ -38,17 +38,17 @@ class RuleController extends Controller
|
||||
/**
|
||||
* Render HTML form for rule action.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function action(Request $request): JsonResponse
|
||||
{
|
||||
$count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1;
|
||||
$count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1;
|
||||
$keys = array_keys(config('firefly.rule-actions'));
|
||||
$actions = [];
|
||||
foreach ($keys as $key) {
|
||||
$actions[$key] = (string) trans('firefly.rule_action_' . $key . '_choice');
|
||||
$actions[$key] = (string)trans('firefly.rule_action_'.$key.'_choice');
|
||||
}
|
||||
try {
|
||||
$view = view('rules.partials.action', compact('actions', 'count'))->render();
|
||||
@@ -64,18 +64,18 @@ class RuleController extends Controller
|
||||
/**
|
||||
* Render HTML for rule trigger.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Request $request
|
||||
*
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function trigger(Request $request): JsonResponse
|
||||
{
|
||||
$count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1;
|
||||
$count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1;
|
||||
$operators = config('search.operators');
|
||||
$triggers = [];
|
||||
foreach ($operators as $key => $operator) {
|
||||
if ('user_action' !== $key && false === $operator['alias']) {
|
||||
$triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key));
|
||||
}
|
||||
}
|
||||
asort($triggers);
|
||||
|
||||
Reference in New Issue
Block a user