Code cleanup

This commit is contained in:
James Cole
2024-12-22 08:43:12 +01:00
parent 5751f7e5a3
commit 565bd87959
574 changed files with 4600 additions and 4604 deletions

View File

@@ -110,7 +110,7 @@ trait AugumentData
$return = [];
foreach ($accountIds as $combinedId) {
$parts = explode('-', $combinedId);
$accountId = (int)$parts[0];
$accountId = (int) $parts[0];
if (array_key_exists($accountId, $grouped)) {
$return[$accountId] = $grouped[$accountId][0]['name'];
}
@@ -135,7 +135,7 @@ trait AugumentData
$return[$budgetId] = $grouped[$budgetId][0]['name'];
}
}
$return[0] = (string)trans('firefly.no_budget');
$return[0] = (string) trans('firefly.no_budget');
return $return;
}
@@ -152,12 +152,12 @@ trait AugumentData
$return = [];
foreach ($categoryIds as $combinedId) {
$parts = explode('-', $combinedId);
$categoryId = (int)$parts[0];
$categoryId = (int) $parts[0];
if (array_key_exists($categoryId, $grouped)) {
$return[$categoryId] = $grouped[$categoryId][0]['name'];
}
}
$return[0] = (string)trans('firefly.no_category');
$return[0] = (string) trans('firefly.no_category');
return $return;
}
@@ -259,7 +259,7 @@ trait AugumentData
];
// loop to support multi currency
foreach ($journals as $journal) {
$currencyId = (int)$journal['currency_id'];
$currencyId = (int) $journal['currency_id'];
// if not set, set to zero:
if (!array_key_exists($currencyId, $sum['per_currency'])) {

View File

@@ -83,7 +83,7 @@ trait ChartGeneration
$previous = array_values($range)[0];
while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d');
$label = trim($currentStart->isoFormat((string)trans('config.month_and_day_js', [], $locale)));
$label = trim($currentStart->isoFormat((string) trans('config.month_and_day_js', [], $locale)));
$balance = $range[$format] ?? $previous;
$previous = $balance;
$currentStart->addDay();

View File

@@ -71,7 +71,7 @@ trait CreateStuff
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$assetAccount = [
'name' => (string)trans('firefly.cash_wallet', [], $language),
'name' => (string) trans('firefly.cash_wallet', [], $language),
'iban' => null,
'account_type_name' => 'asset',
'virtual_balance' => 0,
@@ -106,7 +106,7 @@ trait CreateStuff
Log::alert('NO OAuth keys were found. They have been created.');
file_put_contents($publicKey, (string)$key->getPublicKey());
file_put_contents($publicKey, (string) $key->getPublicKey());
file_put_contents($privateKey, $key->toString('PKCS1'));
}
@@ -118,7 +118,7 @@ trait CreateStuff
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$savingsAccount = [
'name' => (string)trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language),
'name' => (string) trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language),
'iban' => null,
'account_type_name' => 'asset',
'account_type_id' => null,

View File

@@ -40,13 +40,13 @@ trait DateCalculation
*/
public function activeDaysLeft(Carbon $start, Carbon $end): int
{
$difference = (int)($start->diffInDays($end, true) + 1);
$difference = (int) ($start->diffInDays($end, true) + 1);
$today = today(config('app.timezone'))->startOfDay();
if ($start->lte($today) && $end->gte($today)) {
$difference = $today->diffInDays($end) + 1;
}
return (int)(0 === $difference ? 1 : $difference);
return (int) (0 === $difference ? 1 : $difference);
}
/**
@@ -63,7 +63,7 @@ trait DateCalculation
$difference = $start->diffInDays($today, true) + 1;
}
return (int)$difference;
return (int) $difference;
}
protected function calculateStep(Carbon $start, Carbon $end): string

View File

@@ -48,7 +48,7 @@ trait GetConfigurationData
E_COMPILE_ERROR | E_RECOVERABLE_ERROR | E_ERROR | E_CORE_ERROR => 'E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR',
];
return $array[$value] ?? (string)$value;
return $array[$value] ?? (string) $value;
}
/**
@@ -64,7 +64,7 @@ trait GetConfigurationData
$currentStep = $options;
// get the text:
$currentStep['intro'] = (string)trans('intro.'.$route.'_'.$key);
$currentStep['intro'] = (string) trans('intro.'.$route.'_'.$key);
// save in array:
$steps[] = $currentStep;
@@ -133,41 +133,41 @@ trait GetConfigurationData
$todayEnd = app('navigation')->endOfPeriod($todayStart, $viewRange);
if ($todayStart->ne($start) || $todayEnd->ne($end)) {
$ranges[ucfirst((string)trans('firefly.today'))] = [$todayStart, $todayEnd];
$ranges[ucfirst((string) trans('firefly.today'))] = [$todayStart, $todayEnd];
}
// last seven days:
$seven = today(config('app.timezone'))->subDays(7);
$index = (string)trans('firefly.last_seven_days');
$index = (string) trans('firefly.last_seven_days');
$ranges[$index] = [$seven, new Carbon()];
// last 30 days:
$thirty = today(config('app.timezone'))->subDays(30);
$index = (string)trans('firefly.last_thirty_days');
$index = (string) trans('firefly.last_thirty_days');
$ranges[$index] = [$thirty, new Carbon()];
// month to date:
$monthBegin = today(config('app.timezone'))->startOfMonth();
$index = (string)trans('firefly.month_to_date');
$index = (string) trans('firefly.month_to_date');
$ranges[$index] = [$monthBegin, new Carbon()];
// year to date:
$yearBegin = today(config('app.timezone'))->startOfYear();
$index = (string)trans('firefly.year_to_date');
$index = (string) trans('firefly.year_to_date');
$ranges[$index] = [$yearBegin, new Carbon()];
// everything
$index = (string)trans('firefly.everything');
$index = (string) trans('firefly.everything');
$ranges[$index] = [$first, new Carbon()];
return [
'title' => $title,
'configuration' => [
'apply' => (string)trans('firefly.apply'),
'cancel' => (string)trans('firefly.cancel'),
'from' => (string)trans('firefly.from'),
'to' => (string)trans('firefly.to'),
'customRange' => (string)trans('firefly.customRange'),
'apply' => (string) trans('firefly.apply'),
'cancel' => (string) trans('firefly.cancel'),
'from' => (string) trans('firefly.from'),
'to' => (string) trans('firefly.to'),
'customRange' => (string) trans('firefly.customRange'),
'start' => $start->format('Y-m-d'),
'end' => $end->format('Y-m-d'),
'ranges' => $ranges,
@@ -192,7 +192,7 @@ trait GetConfigurationData
$currentStep = $options;
// get the text:
$currentStep['intro'] = (string)trans('intro.'.$route.'_'.$specificPage.'_'.$key);
$currentStep['intro'] = (string) trans('intro.'.$route.'_'.$specificPage.'_'.$key);
// save in array:
$steps[] = $currentStep;
@@ -207,7 +207,7 @@ trait GetConfigurationData
protected function verifyRecurringCronJob(): void
{
$config = app('fireflyconfig')->get('last_rt_job', 0);
$lastTime = (int)$config?->data;
$lastTime = (int) $config?->data;
$now = time();
app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config?->data, $now));
if (0 === $lastTime) {

View File

@@ -86,9 +86,9 @@ trait ModelInformation
/** @var AccountType $mortgage */
$mortgage = $repository->getAccountTypeByType(AccountType::MORTGAGE);
$liabilityTypes = [
$debt->id => (string)trans(sprintf('firefly.account_type_%s', AccountTypeEnum::DEBT->value)),
$loan->id => (string)trans(sprintf('firefly.account_type_%s', AccountTypeEnum::LOAN->value)),
$mortgage->id => (string)trans(sprintf('firefly.account_type_%s', AccountTypeEnum::MORTGAGE->value)),
$debt->id => (string) trans(sprintf('firefly.account_type_%s', AccountTypeEnum::DEBT->value)),
$loan->id => (string) trans(sprintf('firefly.account_type_%s', AccountTypeEnum::LOAN->value)),
$mortgage->id => (string) trans(sprintf('firefly.account_type_%s', AccountTypeEnum::MORTGAGE->value)),
];
asort($liabilityTypes);
@@ -99,7 +99,7 @@ trait ModelInformation
{
$roles = [];
foreach (config('firefly.accountRoles') as $role) {
$roles[$role] = (string)trans(sprintf('firefly.account_role_%s', $role));
$roles[$role] = (string) trans(sprintf('firefly.account_role_%s', $role));
}
return $roles;
@@ -117,7 +117,7 @@ trait ModelInformation
$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);
@@ -168,7 +168,7 @@ trait ModelInformation
$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);

View File

@@ -166,7 +166,7 @@ trait PeriodOverview
/** @var array $journal */
foreach ($journals as $journal) {
if ($account->id === (int)$journal['source_account_id']) {
if ($account->id === (int) $journal['source_account_id']) {
$return[] = $journal;
}
}
@@ -183,7 +183,7 @@ trait PeriodOverview
/** @var array $journal */
foreach ($journals as $journal) {
if ($account->id === (int)$journal['destination_account_id']) {
if ($account->id === (int) $journal['destination_account_id']) {
$return[] = $journal;
}
}
@@ -197,7 +197,7 @@ trait PeriodOverview
/** @var array $journal */
foreach ($journals as $journal) {
$currencyId = (int)$journal['currency_id'];
$currencyId = (int) $journal['currency_id'];
$foreignCurrencyId = $journal['foreign_currency_id'];
if (!array_key_exists($currencyId, $return)) {
$return[$currencyId] = [
@@ -218,7 +218,7 @@ trait PeriodOverview
$return[$foreignCurrencyId] = [
'amount' => '0',
'count' => 0,
'currency_id' => (int)$foreignCurrencyId,
'currency_id' => (int) $foreignCurrencyId,
'currency_name' => $journal['foreign_currency_name'],
'currency_code' => $journal['foreign_currency_code'],
'currency_symbol' => $journal['foreign_currency_symbol'],

View File

@@ -55,10 +55,10 @@ trait RenderPartialViews
/** @var BudgetRepositoryInterface $budgetRepository */
$budgetRepository = app(BudgetRepositoryInterface::class);
$budget = $budgetRepository->find((int)$attributes['budgetId']);
$budget = $budgetRepository->find((int) $attributes['budgetId']);
$accountRepos = app(AccountRepositoryInterface::class);
$account = $accountRepos->find((int)$attributes['accountId']);
$account = $accountRepos->find((int) $attributes['accountId']);
if (null === $budget || null === $account) {
throw new FireflyException('Could not render popup.report.balance-amount because budget or account is null.');
@@ -114,7 +114,7 @@ trait RenderPartialViews
/** @var PopupReportInterface $popupHelper */
$popupHelper = app(PopupReportInterface::class);
$budget = $budgetRepository->find((int)$attributes['budgetId']);
$budget = $budgetRepository->find((int) $attributes['budgetId']);
if (null === $budget) {
// transactions without a budget.
$budget = new Budget();
@@ -145,7 +145,7 @@ trait RenderPartialViews
/** @var CategoryRepositoryInterface $categoryRepository */
$categoryRepository = app(CategoryRepositoryInterface::class);
$category = $categoryRepository->find((int)$attributes['categoryId']);
$category = $categoryRepository->find((int) $attributes['categoryId']);
$journals = $popupHelper->byCategory($category, $attributes);
try {
@@ -238,7 +238,7 @@ trait RenderPartialViews
/** @var PopupReportInterface $popupHelper */
$popupHelper = app(PopupReportInterface::class);
$account = $accountRepository->find((int)$attributes['accountId']);
$account = $accountRepository->find((int) $attributes['accountId']);
if (null === $account) {
return 'This is an unknown account. Apologies.';
@@ -309,7 +309,7 @@ trait RenderPartialViews
$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);
@@ -324,7 +324,7 @@ trait RenderPartialViews
$count = ($index + 1);
try {
$rootOperator = OperatorQuerySearch::getRootOperator((string)$entry->trigger_type);
$rootOperator = OperatorQuerySearch::getRootOperator((string) $entry->trigger_type);
if (str_starts_with($rootOperator, '-')) {
$rootOperator = substr($rootOperator, 1);
}
@@ -334,7 +334,7 @@ trait RenderPartialViews
'oldTrigger' => $rootOperator,
'oldValue' => $entry->trigger_value,
'oldChecked' => $entry->stop_processing,
'oldProhibited' => str_starts_with((string)$entry->trigger_type, '-'),
'oldProhibited' => str_starts_with((string) $entry->trigger_type, '-'),
'count' => $count,
'triggers' => $triggers,
]
@@ -365,7 +365,7 @@ trait RenderPartialViews
/** @var PopupReportInterface $popupHelper */
$popupHelper = app(PopupReportInterface::class);
$account = $accountRepository->find((int)$attributes['accountId']);
$account = $accountRepository->find((int) $attributes['accountId']);
if (null === $account) {
return 'This is an unknown category. Apologies.';

View File

@@ -64,7 +64,7 @@ trait RequestInformation
'type' => $triggerInfo['type'] ?? '',
'value' => $triggerInfo['value'] ?? '',
'prohibited' => $triggerInfo['prohibited'] ?? false,
'stop_processing' => 1 === (int)($triggerInfo['stop_processing'] ?? '0'),
'stop_processing' => 1 === (int) ($triggerInfo['stop_processing'] ?? '0'),
];
$current = RuleFormRequest::replaceAmountTrigger($current);
$triggers[] = $current;
@@ -170,11 +170,11 @@ trait RequestInformation
final protected function validatePassword(User $user, string $current, string $new): bool // get request info
{
if (!\Hash::check($current, $user->password)) {
throw new ValidationException((string)trans('firefly.invalid_current_password'));
throw new ValidationException((string) trans('firefly.invalid_current_password'));
}
if ($current === $new) {
throw new ValidationException((string)trans('firefly.should_change'));
throw new ValidationException((string) trans('firefly.should_change'));
}
return true;

View File

@@ -50,7 +50,7 @@ trait RuleManagement
[
'oldAction' => $oldAction['type'],
'oldValue' => $oldAction['value'] ?? '',
'oldChecked' => 1 === (int)($oldAction['stop_processing'] ?? '0'),
'oldChecked' => 1 === (int) ($oldAction['stop_processing'] ?? '0'),
'count' => $index + 1,
]
)->render();
@@ -77,7 +77,7 @@ trait RuleManagement
$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);
@@ -93,8 +93,8 @@ trait RuleManagement
[
'oldTrigger' => OperatorQuerySearch::getRootOperator($oldTrigger['type']),
'oldValue' => $oldTrigger['value'] ?? '',
'oldChecked' => 1 === (int)($oldTrigger['stop_processing'] ?? '0'),
'oldProhibited' => 1 === (int)($oldTrigger['prohibited'] ?? '0'),
'oldChecked' => 1 === (int) ($oldTrigger['stop_processing'] ?? '0'),
'oldProhibited' => 1 === (int) ($oldTrigger['prohibited'] ?? '0'),
'count' => $index + 1,
'triggers' => $triggers,
]
@@ -123,7 +123,7 @@ trait RuleManagement
$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);
@@ -131,7 +131,7 @@ trait RuleManagement
$index = 0;
foreach ($submittedOperators as $operator) {
$rootOperator = OperatorQuerySearch::getRootOperator($operator['type']);
$needsContext = (bool)config(sprintf('search.operators.%s.needs_context', $rootOperator));
$needsContext = (bool) config(sprintf('search.operators.%s.needs_context', $rootOperator));
try {
$renderedEntries[] = view(
@@ -163,8 +163,8 @@ trait RuleManagement
$repository = app(RuleGroupRepositoryInterface::class);
if (0 === $repository->count()) {
$data = [
'title' => (string)trans('firefly.default_rule_group_name'),
'description' => (string)trans('firefly.default_rule_group_description'),
'title' => (string) trans('firefly.default_rule_group_name'),
'description' => (string) trans('firefly.default_rule_group_description'),
'active' => true,
];

View File

@@ -49,7 +49,7 @@ trait UserNavigation
final protected function getPreviousUrl(string $identifier): string
{
app('log')->debug(sprintf('Trying to retrieve URL stored under "%s"', $identifier));
$url = (string)session($identifier);
$url = (string) session($identifier);
app('log')->debug(sprintf('The URL is %s', $url));
return app('steam')->getSafeUrl($url, route('index'));