Code cleanup that (hopefully) matches style CI

This commit is contained in:
James Cole
2020-03-17 15:01:00 +01:00
parent bd2f064eeb
commit 2b6c3fd743
110 changed files with 2060 additions and 1660 deletions

View File

@@ -22,6 +22,7 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Amount;
use Carbon\Carbon;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\Account;
@@ -78,7 +79,7 @@ class AutoCompleteController extends Controller
Log::debug(sprintf('Now in accounts("%s"). Filtering results.', $search), $filteredAccountTypes);
$return = [];
$result = $repository->searchAccount((string)$search, $filteredAccountTypes);
$result = $repository->searchAccount((string) $search, $filteredAccountTypes);
$defaultCurrency = app('amount')->getDefaultCurrency();
/** @var Account $account */
@@ -117,7 +118,7 @@ class AutoCompleteController extends Controller
*/
public function allJournals(Request $request): JsonResponse
{
$search = (string)$request->get('search');
$search = (string) $request->get('search');
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$result = $repository->searchJournalDescriptions($search);
@@ -132,7 +133,8 @@ class AutoCompleteController extends Controller
$journal['name'] = $journal['description'];
return $journal;
}, $array
},
$array
);
return response()->json(array_values($array));
@@ -150,7 +152,7 @@ class AutoCompleteController extends Controller
*/
public function allJournalsWithID(Request $request): JsonResponse
{
$search = (string)$request->get('search');
$search = (string) $request->get('search');
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
@@ -161,7 +163,7 @@ class AutoCompleteController extends Controller
$array = [];
if (is_numeric($search)) {
// search for group, not journal.
$firstResult = $groupRepos->find((int)$search);
$firstResult = $groupRepos->find((int) $search);
if (null !== $firstResult) {
// group may contain multiple journals, each a result:
foreach ($firstResult->transactionJournals as $journal) {
@@ -201,7 +203,7 @@ class AutoCompleteController extends Controller
Log::debug(sprintf('Now in expenseAccounts(%s). Filtering results.', $search), $allowedAccountTypes);
$return = [];
$result = $repository->searchAccount((string)$search, $allowedAccountTypes);
$result = $repository->searchAccount((string) $search, $allowedAccountTypes);
/** @var Account $account */
foreach ($result as $account) {
@@ -223,7 +225,7 @@ class AutoCompleteController extends Controller
*/
public function bills(Request $request): JsonResponse
{
$query = (string)$request->get('search');
$query = (string) $request->get('search');
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
$result = $repository->searchBill($query);
@@ -239,7 +241,7 @@ class AutoCompleteController extends Controller
*/
public function budgets(Request $request): JsonResponse
{
$search = (string)$request->get('search');
$search = (string) $request->get('search');
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$result = $repository->searchBudget($search);
@@ -255,7 +257,7 @@ class AutoCompleteController extends Controller
*/
public function categories(Request $request): JsonResponse
{
$query = (string)$request->get('search');
$query = (string) $request->get('search');
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
$result = $repository->searchCategory($query);
@@ -297,7 +299,7 @@ class AutoCompleteController extends Controller
*/
public function currencyNames(Request $request): JsonResponse
{
$query = (string)$request->get('search');
$query = (string) $request->get('search');
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
$result = $repository->searchCurrency($query)->toArray();
@@ -326,7 +328,7 @@ class AutoCompleteController extends Controller
Log::debug(sprintf('Now in expenseAccounts(%s). Filtering results.', $search), $allowedAccountTypes);
$return = [];
$result = $repository->searchAccount((string)$search, $allowedAccountTypes);
$result = $repository->searchAccount((string) $search, $allowedAccountTypes);
/** @var Account $account */
foreach ($result as $account) {
@@ -353,7 +355,7 @@ class AutoCompleteController extends Controller
$accountRepos = app(AccountRepositoryInterface::class);
$piggies = $repository->getPiggyBanks();
$defaultCurrency = \Amount::getDefaultCurrency();
$defaultCurrency = Amount::getDefaultCurrency();
$response = [];
/** @var PiggyBank $piggy */
foreach ($piggies as $piggy) {
@@ -389,7 +391,7 @@ class AutoCompleteController extends Controller
Log::debug('Now in revenueAccounts(). Filtering results.', $allowedAccountTypes);
$return = [];
$result = $repository->searchAccount((string)$search, $allowedAccountTypes);
$result = $repository->searchAccount((string) $search, $allowedAccountTypes);
/** @var Account $account */
foreach ($result as $account) {
@@ -411,7 +413,7 @@ class AutoCompleteController extends Controller
*/
public function tags(Request $request): JsonResponse
{
$search = (string)$request->get('search');
$search = (string) $request->get('search');
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$result = $repository->searchTags($search);
@@ -432,7 +434,7 @@ class AutoCompleteController extends Controller
*/
public function transactionTypes(Request $request): JsonResponse
{
$query = (string)$request->get('search');
$query = (string) $request->get('search');
/** @var TransactionTypeRepositoryInterface $repository */
$repository = app(TransactionTypeRepositoryInterface::class);
$array = $repository->searchTypes($query)->toArray();
@@ -444,5 +446,4 @@ class AutoCompleteController extends Controller
return response()->json($array);
}
}

View File

@@ -34,7 +34,6 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\CacheProperties;
@@ -71,7 +70,7 @@ class BoxController extends Controller
$end = session('end', Carbon::now()->endOfMonth());
$today = new Carbon;
$display = 2; // see method docs.
$boxTitle = (string)trans('firefly.spent');
$boxTitle = (string) trans('firefly.spent');
$cache = new CacheProperties;
$cache->addProperty($start);
@@ -98,19 +97,19 @@ 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';
$spentPerDay = '-1';
if ($availableBudgets->count() > 0) {
$display = 0; // assume user overspent
$boxTitle = (string)trans('firefly.overspent');
$totalAvailableSum = (string)$availableBudgets->sum('amount');
$display = 0; // assume user overspent
$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);
}
}
@@ -164,7 +163,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));
@@ -180,7 +179,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

@@ -73,7 +73,7 @@ class ExchangeController extends Controller
$return['amount'] = null;
if (null !== $request->get('amount')) {
// assume amount is in "from" currency:
$return['amount'] = bcmul($request->get('amount'), (string)$rate->rate, 12);
$return['amount'] = bcmul($request->get('amount'), (string) $rate->rate, 12);
// round to toCurrency decimal places:
$return['amount'] = round($return['amount'], $toCurrency->decimal_places);
}

View File

@@ -115,7 +115,7 @@ class IntroController
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

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Http\Controllers\Controller;
@@ -56,6 +55,7 @@ class ReconcileController extends Controller
/**
* ReconcileController constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
@@ -66,7 +66,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);
@@ -81,8 +81,8 @@ class ReconcileController extends Controller
*
* @param Request $request
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*/
@@ -141,11 +141,22 @@ class ReconcileController extends Controller
try {
$view = view(
'accounts.reconcile.overview', compact(
'account', 'start', 'diffCompare', 'difference', 'end', 'clearedAmount',
'startBalance', 'endBalance', 'amount',
'route', 'countCleared', 'reconSum', 'selectedIds'
)
'accounts.reconcile.overview',
compact(
'account',
'start',
'diffCompare',
'difference',
'end',
'clearedAmount',
'startBalance',
'endBalance',
'amount',
'route',
'countCleared',
'reconSum',
'selectedIds'
)
)->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
@@ -168,8 +179,8 @@ class ReconcileController extends Controller
* Returns a list of transactions in a modal.
*
* @param Account $account
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*
* @return mixed
*
@@ -231,8 +242,10 @@ class ReconcileController extends Controller
}
try {
$html = view('accounts.reconcile.transactions',
compact('account', 'journals', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd'))->render();
$html = view(
'accounts.reconcile.transactions',
compact('account', 'journals', 'currency', 'start', 'end', 'selectionStart', 'selectionEnd')
)->render();
// @codeCoverageIgnoreStart
} catch (Throwable $e) {
Log::debug(sprintf('Could not render: %s', $e->getMessage()));
@@ -245,10 +258,11 @@ class ReconcileController extends Controller
}
/**
* @param Account $account
* @param Account $account
* @param TransactionCurrency $currency
* @param array $journal
* @param string $amount
* @param array $journal
* @param string $amount
*
* @return string
*/
private function processJournal(Account $account, TransactionCurrency $currency, array $journal, string $amount): string

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\Json;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Http\Controllers\Controller;
@@ -65,9 +64,9 @@ class RecurrenceController extends Controller
*
* @param Request $request
*
* @throws FireflyException
* @return JsonResponse
*
* @throws FireflyException
*/
public function events(Request $request): JsonResponse
{
@@ -75,10 +74,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();
@@ -101,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;
$occurrences = [];
switch ($endsAt) {
@@ -150,30 +149,31 @@ 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');
$date = Carbon::createFromFormat('Y-m-d', $string)->startOfDay();
$preSelected = (string) $request->get('pre_select');
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('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)));
$result = [];
if ($date > $today || 'true' === (string)$request->get('past')) {
$result = [];
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->formatLocalized((string)trans('config.month_and_day_no_year'));
$yearlyDate = $date->formatLocalized((string) trans('config.month_and_day_no_year'));
$result = [
'daily' => ['label' => (string)trans('firefly.recurring_daily'), 'selected' => 0 === strpos($preSelected, 'daily')],
$weekly => ['label' => (string)trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
'daily' => ['label' => (string) trans('firefly.recurring_daily'), 'selected' => 0 === strpos($preSelected, 'daily')],
$weekly => ['label' => (string) trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
'selected' => 0 === strpos($preSelected, 'weekly')],
$monthly => ['label' => (string)trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]),
$monthly => ['label' => (string) trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]),
'selected' => 0 === strpos($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' => 0 === strpos($preSelected, 'ndom')],
$yearly => ['label' => (string)trans('firefly.recurring_yearly', ['date' => $yearlyDate]), 'selected' => 0 === strpos($preSelected, 'yearly')],
$yearly => ['label' => (string) trans('firefly.recurring_yearly', ['date' => $yearlyDate]),
'selected' => 0 === strpos($preSelected, 'yearly')],
];
}
Log::debug('Dropdown is', $result);
@@ -181,5 +181,4 @@ class RecurrenceController extends Controller
return response()->json($result);
}
}

View File

@@ -44,11 +44,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();
@@ -72,12 +72,12 @@ 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;
$keys = array_keys(config('firefly.rule-triggers'));
$triggers = [];
foreach ($keys as $key) {
if ('user_action' !== $key) {
$triggers[$key] = (string)trans('firefly.rule_trigger_' . $key . '_choice');
$triggers[$key] = (string) trans('firefly.rule_trigger_' . $key . '_choice');
}
}
asort($triggers);