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

@@ -102,13 +102,14 @@ class BudgetLimitController extends Controller
}
/**
* @return Factory|View
* @return Redirector|RedirectResponse
*/
public function show(BudgetLimit $budgetLimit)
public function delete(BudgetLimit $budgetLimit)
{
$notes = $this->blRepository->getNoteText($budgetLimit);
$this->blRepository->destroyBudgetLimit($budgetLimit);
session()->flash('success', trans('firefly.deleted_bl'));
return view('budgets.budget-limits.show', compact('budgetLimit', 'notes'));
return redirect(route('budgets.index'));
}
/**
@@ -122,14 +123,13 @@ class BudgetLimitController extends Controller
}
/**
* @return Redirector|RedirectResponse
* @return Factory|View
*/
public function delete(BudgetLimit $budgetLimit)
public function show(BudgetLimit $budgetLimit)
{
$this->blRepository->destroyBudgetLimit($budgetLimit);
session()->flash('success', trans('firefly.deleted_bl'));
$notes = $this->blRepository->getNoteText($budgetLimit);
return redirect(route('budgets.index'));
return view('budgets.budget-limits.show', compact('budgetLimit', 'notes'));
}
/**
@@ -250,7 +250,7 @@ class BudgetLimitController extends Controller
if (-1 === bccomp($amount, '0')) {
$amount = bcmul($amount, '-1');
}
$notes = (string)$request->get('notes');
$notes = (string) $request->get('notes');
if (strlen($notes) > 32768) {
$notes = substr($notes, 0, 32768);
}

View File

@@ -52,7 +52,7 @@ class CreateController extends Controller
parent::__construct();
$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->attachments = app(AttachmentHelperInterface::class);
@@ -73,24 +73,24 @@ class CreateController extends Controller
// auto budget types
$autoBudgetTypes = [
0 => (string)trans('firefly.auto_budget_none'),
AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'),
AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'),
AutoBudget::AUTO_BUDGET_ADJUSTED => (string)trans('firefly.auto_budget_adjusted'),
0 => (string) trans('firefly.auto_budget_none'),
AutoBudget::AUTO_BUDGET_RESET => (string) trans('firefly.auto_budget_reset'),
AutoBudget::AUTO_BUDGET_ROLLOVER => (string) trans('firefly.auto_budget_rollover'),
AutoBudget::AUTO_BUDGET_ADJUSTED => (string) trans('firefly.auto_budget_adjusted'),
];
$autoBudgetPeriods = [
'daily' => (string)trans('firefly.auto_budget_period_daily'),
'weekly' => (string)trans('firefly.auto_budget_period_weekly'),
'monthly' => (string)trans('firefly.auto_budget_period_monthly'),
'quarterly' => (string)trans('firefly.auto_budget_period_quarterly'),
'half_year' => (string)trans('firefly.auto_budget_period_half_year'),
'yearly' => (string)trans('firefly.auto_budget_period_yearly'),
'daily' => (string) trans('firefly.auto_budget_period_daily'),
'weekly' => (string) trans('firefly.auto_budget_period_weekly'),
'monthly' => (string) trans('firefly.auto_budget_period_monthly'),
'quarterly' => (string) trans('firefly.auto_budget_period_quarterly'),
'half_year' => (string) trans('firefly.auto_budget_period_half_year'),
'yearly' => (string) trans('firefly.auto_budget_period_yearly'),
];
$currency = app('amount')->getDefaultCurrency();
$preFilled = [
'auto_budget_period' => $hasOldInput ? (bool)$request->old('auto_budget_period') : 'monthly',
'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id,
'auto_budget_period' => $hasOldInput ? (bool) $request->old('auto_budget_period') : 'monthly',
'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id,
];
$request->session()->flash('preFilled', $preFilled);
@@ -100,7 +100,7 @@ class CreateController extends Controller
$this->rememberPreviousUrl('budgets.create.url');
}
$request->session()->forget('budgets.create.fromStore');
$subTitle = (string)trans('firefly.create_new_budget');
$subTitle = (string) trans('firefly.create_new_budget');
return view('budgets.create', compact('subTitle', 'autoBudgetTypes', 'autoBudgetPeriods'));
}
@@ -116,7 +116,7 @@ class CreateController extends Controller
$budget = $this->repository->store($data);
$this->repository->cleanupBudgets();
$request->session()->flash('success', (string)trans('firefly.stored_new_budget', ['name' => $budget->name]));
$request->session()->flash('success', (string) trans('firefly.stored_new_budget', ['name' => $budget->name]));
app('preferences')->mark();
Log::channel('audit')->info('Stored new budget.', $data);
@@ -129,7 +129,7 @@ class CreateController extends Controller
}
if (null !== $files && auth()->user()->hasRole('demo')) {
Log::channel('audit')->warning(sprintf('The demo user is trying to upload attachments in %s.', __METHOD__));
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -138,7 +138,7 @@ class CreateController extends Controller
$redirect = redirect($this->getPreviousUrl('budgets.create.url'));
if (1 === (int)$request->get('create_another')) {
if (1 === (int) $request->get('create_another')) {
$request->session()->put('budgets.create.fromStore', true);
$redirect = redirect(route('budgets.create'))->withInput();

View File

@@ -50,7 +50,7 @@ class DeleteController 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);
@@ -66,7 +66,7 @@ class DeleteController extends Controller
*/
public function delete(Budget $budget)
{
$subTitle = (string)trans('firefly.delete_budget', ['name' => $budget->name]);
$subTitle = (string) trans('firefly.delete_budget', ['name' => $budget->name]);
// put previous url in session
$this->rememberPreviousUrl('budgets.delete.url');
@@ -83,7 +83,7 @@ class DeleteController extends Controller
{
$name = $budget->name;
$this->repository->destroy($budget);
$request->session()->flash('success', (string)trans('firefly.deleted_budget', ['name' => $name]));
$request->session()->flash('success', (string) trans('firefly.deleted_budget', ['name' => $name]));
app('preferences')->mark();
return redirect($this->getPreviousUrl('budgets.delete.url'));

View File

@@ -53,7 +53,7 @@ class EditController 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->attachments = app(AttachmentHelperInterface::class);
@@ -70,38 +70,38 @@ class EditController extends Controller
*/
public function edit(Request $request, Budget $budget)
{
$subTitle = (string)trans('firefly.edit_budget', ['name' => $budget->name]);
$subTitle = (string) trans('firefly.edit_budget', ['name' => $budget->name]);
$autoBudget = $this->repository->getAutoBudget($budget);
// auto budget types
$autoBudgetTypes = [
0 => (string)trans('firefly.auto_budget_none'),
AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'),
AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'),
AutoBudget::AUTO_BUDGET_ADJUSTED => (string)trans('firefly.auto_budget_adjusted'),
0 => (string) trans('firefly.auto_budget_none'),
AutoBudget::AUTO_BUDGET_RESET => (string) trans('firefly.auto_budget_reset'),
AutoBudget::AUTO_BUDGET_ROLLOVER => (string) trans('firefly.auto_budget_rollover'),
AutoBudget::AUTO_BUDGET_ADJUSTED => (string) trans('firefly.auto_budget_adjusted'),
];
$autoBudgetPeriods = [
'daily' => (string)trans('firefly.auto_budget_period_daily'),
'weekly' => (string)trans('firefly.auto_budget_period_weekly'),
'monthly' => (string)trans('firefly.auto_budget_period_monthly'),
'quarterly' => (string)trans('firefly.auto_budget_period_quarterly'),
'half_year' => (string)trans('firefly.auto_budget_period_half_year'),
'yearly' => (string)trans('firefly.auto_budget_period_yearly'),
'daily' => (string) trans('firefly.auto_budget_period_daily'),
'weekly' => (string) trans('firefly.auto_budget_period_weekly'),
'monthly' => (string) trans('firefly.auto_budget_period_monthly'),
'quarterly' => (string) trans('firefly.auto_budget_period_quarterly'),
'half_year' => (string) trans('firefly.auto_budget_period_half_year'),
'yearly' => (string) trans('firefly.auto_budget_period_yearly'),
];
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');
$currency = app('amount')->getDefaultCurrency();
$preFilled = [
'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active,
'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id,
'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active,
'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id,
];
if (null !== $autoBudget) {
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
if (is_array($amount)) {
$amount = '0';
}
$amount = (string)$amount;
$amount = (string) $amount;
$preFilled['auto_budget_amount'] = app('steam')->bcround($amount, $autoBudget->transactionCurrency->decimal_places);
}
@@ -123,7 +123,7 @@ class EditController extends Controller
$data = $request->getBudgetData();
$this->repository->update($budget, $data);
$request->session()->flash('success', (string)trans('firefly.updated_budget', ['name' => $budget->name]));
$request->session()->flash('success', (string) trans('firefly.updated_budget', ['name' => $budget->name]));
$this->repository->cleanupBudgets();
app('preferences')->mark();
@@ -139,14 +139,14 @@ class EditController extends Controller
}
if (null !== $files && auth()->user()->hasRole('demo')) {
Log::channel('audit')->warning(sprintf('The demo user is trying to upload attachments in %s.', __METHOD__));
session()->flash('info', (string)trans('firefly.no_att_demo_user'));
session()->flash('info', (string) trans('firefly.no_att_demo_user'));
}
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
}
if (1 === (int)$request->get('return_to_edit')) {
if (1 === (int) $request->get('return_to_edit')) {
$request->session()->put('budgets.edit.fromUpdate', true);
$redirect = redirect(route('budgets.edit', [$budget->id]))->withInput(['return_to_edit' => 1]);

View File

@@ -65,7 +65,7 @@ class IndexController 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);
@@ -306,7 +306,7 @@ class IndexController extends Controller
$budgetIds = $request->get('budgetIds');
foreach ($budgetIds as $index => $budgetId) {
$budgetId = (int)$budgetId;
$budgetId = (int) $budgetId;
$budget = $repository->find($budgetId);
if (null !== $budget) {
app('log')->debug(sprintf('Set budget #%d ("%s") to position %d', $budget->id, $budget->name, $index + 1));

View File

@@ -59,7 +59,7 @@ class ShowController extends Controller
parent::__construct();
$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->journalRepos = app(JournalRepositoryInterface::class);
$this->repository = app(BudgetRepositoryInterface::class);
@@ -91,8 +91,8 @@ class ShowController extends Controller
$first = $this->journalRepos->firstNull();
$firstDate = null !== $first ? $first->date : $start;
$periods = $this->getNoBudgetPeriodOverview($firstDate, $end);
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@@ -112,12 +112,12 @@ class ShowController extends Controller
*/
public function noBudgetAll(Request $request)
{
$subTitle = (string)trans('firefly.all_journals_without_budget');
$subTitle = (string) trans('firefly.all_journals_without_budget');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$end = today(config('app.timezone'));
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
@@ -140,8 +140,8 @@ class ShowController extends Controller
/** @var Carbon $allStart */
$allStart = session('first', today(config('app.timezone'))->startOfYear());
$allEnd = today();
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$limits = $this->getLimits($budget, $allStart, $allEnd);
$repetition = null;
$attachments = $this->repository->getAttachments($budget);
@@ -156,7 +156,7 @@ class ShowController extends Controller
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('budgets.show', [$budget->id]));
$subTitle = (string)trans('firefly.all_journals_for_budget', ['name' => $budget->name]);
$subTitle = (string) trans('firefly.all_journals_for_budget', ['name' => $budget->name]);
return view('budgets.show', compact('limits', 'attachments', 'budget', 'repetition', 'groups', 'subTitle'));
}
@@ -174,8 +174,8 @@ class ShowController extends Controller
throw new FireflyException('This budget limit is not part of this budget.');
}
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$subTitle = trans(
'firefly.budget_in_period',
[