Reformat various code.

This commit is contained in:
James Cole
2022-03-29 14:58:06 +02:00
parent 1209c4e76a
commit 29bed2547c
140 changed files with 1004 additions and 1010 deletions

View File

@@ -66,7 +66,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);
@@ -93,21 +93,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);
}
}
@@ -161,7 +161,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));
@@ -177,7 +177,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';

View File

@@ -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);

View File

@@ -51,7 +51,7 @@ class FrontpageController extends Controller
if (1 === bccomp($amount, '0')) {
// percentage!
$pct = 0;
if(0.0 !== (float)$piggyBank->targetamount) {
if (0.0 !== (float) $piggyBank->targetamount) {
$pct = round(($amount / $piggyBank->targetamount) * 100);
}

View File

@@ -118,7 +118,7 @@ class IntroController extends Controller
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')]);
}
/**

View File

@@ -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);
@@ -236,8 +236,8 @@ class ReconcileController extends Controller
$startDate->subDay();
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$startBalance = round((float)app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = round((float)app('steam')->balance($account, $end), $currency->decimal_places);
$startBalance = round((float) app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = round((float) app('steam')->balance($account, $end), $currency->decimal_places);
// get the transactions
$selectionStart = clone $start;

View File

@@ -73,10 +73,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 +100,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) {
@@ -149,30 +149,30 @@ class RecurrenceController extends Controller
$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]),
'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]),
$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]),
$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]),
$yearly => ['label' => (string) trans('firefly.recurring_yearly', ['date' => $yearlyDate]),
'selected' => str_starts_with($preSelected, 'yearly')],
];
}

View File

@@ -43,11 +43,11 @@ class RuleController extends Controller
*/
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();
@@ -69,13 +69,13 @@ class RuleController extends Controller
*/
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);