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

@@ -60,7 +60,7 @@ class CreateController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string)trans('firefly.rules'));
app('view')->share('title', (string) trans('firefly.rules'));
app('view')->share('mainTitleIcon', 'fa-random');
$this->ruleRepos = app(RuleRepositoryInterface::class);
@@ -87,7 +87,7 @@ class CreateController extends Controller
$oldActions = [];
// build triggers from query, if present.
$query = (string)$request->get('from_query');
$query = (string) $request->get('from_query');
if ('' !== $query) {
$search = app(SearchInterface::class);
$search->parseQuery($query);
@@ -115,9 +115,9 @@ class CreateController extends Controller
$subTitleIcon = 'fa-clone';
// title depends on whether or not there is a rule group:
$subTitle = (string)trans('firefly.make_new_rule_no_group');
$subTitle = (string) trans('firefly.make_new_rule_no_group');
if (null !== $ruleGroup) {
$subTitle = (string)trans('firefly.make_new_rule', ['title' => $ruleGroup->title]);
$subTitle = (string) trans('firefly.make_new_rule', ['title' => $ruleGroup->title]);
}
// flash old data
@@ -144,13 +144,13 @@ class CreateController extends Controller
*/
public function createFromBill(Request $request, Bill $bill)
{
$request->session()->flash('info', (string)trans('firefly.instructions_rule_from_bill', ['name' => e($bill->name)]));
$request->session()->flash('info', (string) trans('firefly.instructions_rule_from_bill', ['name' => e($bill->name)]));
$this->createDefaultRuleGroup();
$preFilled = [
'strict' => true,
'title' => (string)trans('firefly.new_rule_for_bill_title', ['name' => $bill->name]),
'description' => (string)trans('firefly.new_rule_for_bill_description', ['name' => $bill->name]),
'title' => (string) trans('firefly.new_rule_for_bill_title', ['name' => $bill->name]),
'description' => (string) trans('firefly.new_rule_for_bill_description', ['name' => $bill->name]),
];
// make triggers and actions from the bill itself.
@@ -170,7 +170,7 @@ class CreateController extends Controller
$subTitleIcon = 'fa-clone';
// title depends on whether there is a rule group:
$subTitle = (string)trans('firefly.make_new_rule_no_group');
$subTitle = (string) trans('firefly.make_new_rule_no_group');
// flash old data
$request->session()->flash('preFilled', $preFilled);
@@ -194,10 +194,10 @@ class CreateController extends Controller
*/
public function createFromJournal(Request $request, TransactionJournal $journal)
{
$request->session()->flash('info', (string)trans('firefly.instructions_rule_from_journal', ['name' => e($journal->description)]));
$request->session()->flash('info', (string) trans('firefly.instructions_rule_from_journal', ['name' => e($journal->description)]));
$subTitleIcon = 'fa-clone';
$subTitle = (string)trans('firefly.make_new_rule_no_group');
$subTitle = (string) trans('firefly.make_new_rule_no_group');
// get triggers and actions for journal.
$oldTriggers = $this->getTriggersForJournal($journal);
@@ -208,8 +208,8 @@ class CreateController extends Controller
// collect pre-filled information:
$preFilled = [
'strict' => true,
'title' => (string)trans('firefly.new_rule_for_journal_title', ['description' => $journal->description]),
'description' => (string)trans('firefly.new_rule_for_journal_description', ['description' => $journal->description]),
'title' => (string) trans('firefly.new_rule_for_journal_title', ['description' => $journal->description]),
'description' => (string) trans('firefly.new_rule_for_journal_description', ['description' => $journal->description]),
];
// restore actions and triggers from old input:
@@ -238,7 +238,7 @@ class CreateController extends Controller
public function duplicate(Request $request): JsonResponse
{
$ruleId = (int)$request->get('id');
$ruleId = (int) $request->get('id');
$rule = $this->ruleRepos->find($ruleId);
if (null !== $rule) {
$this->ruleRepos->duplicate($rule);
@@ -257,22 +257,22 @@ class CreateController extends Controller
$data = $request->getRuleData();
$rule = $this->ruleRepos->store($data);
session()->flash('success', (string)trans('firefly.stored_new_rule', ['title' => $rule->title]));
session()->flash('success', (string) trans('firefly.stored_new_rule', ['title' => $rule->title]));
app('preferences')->mark();
// redirect to show bill.
if ('true' === $request->get('return_to_bill') && (int)$request->get('bill_id') > 0) {
return redirect(route('bills.show', [(int)$request->get('bill_id')]));
if ('true' === $request->get('return_to_bill') && (int) $request->get('bill_id') > 0) {
return redirect(route('bills.show', [(int) $request->get('bill_id')]));
}
// redirect to new bill creation.
if ((int)$request->get('bill_id') > 0) {
if ((int) $request->get('bill_id') > 0) {
return redirect($this->getPreviousUrl('bills.create.url'));
}
$redirect = redirect($this->getPreviousUrl('rules.create.url'));
if (1 === (int)$request->get('create_another')) {
if (1 === (int) $request->get('create_another')) {
session()->put('rules.create.fromStore', true);
$redirect = redirect(route('rules.create', [$data['rule_group_id']]))->withInput();
}

View File

@@ -48,7 +48,7 @@ class DeleteController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string)trans('firefly.rules'));
app('view')->share('title', (string) trans('firefly.rules'));
app('view')->share('mainTitleIcon', 'fa-random');
$this->ruleRepos = app(RuleRepositoryInterface::class);
@@ -65,7 +65,7 @@ class DeleteController extends Controller
*/
public function delete(Rule $rule)
{
$subTitle = (string)trans('firefly.delete_rule', ['title' => $rule->title]);
$subTitle = (string) trans('firefly.delete_rule', ['title' => $rule->title]);
// put previous url in session
$this->rememberPreviousUrl('rules.delete.url');
@@ -81,7 +81,7 @@ class DeleteController extends Controller
$title = $rule->title;
$this->ruleRepos->destroy($rule);
session()->flash('success', (string)trans('firefly.deleted_rule', ['title' => $title]));
session()->flash('success', (string) trans('firefly.deleted_rule', ['title' => $title]));
app('preferences')->mark();
return redirect($this->getPreviousUrl('rules.delete.url'));

View File

@@ -58,7 +58,7 @@ class EditController extends Controller
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string)trans('firefly.rules'));
app('view')->share('title', (string) trans('firefly.rules'));
app('view')->share('mainTitleIcon', 'fa-random');
$this->ruleRepos = app(RuleRepositoryInterface::class);
@@ -83,7 +83,7 @@ class EditController extends Controller
$oldTriggers = [];
// build triggers from query, if present.
$query = (string)$request->get('from_query');
$query = (string) $request->get('from_query');
if ('' !== $query) {
$search = app(SearchInterface::class);
$search->parseQuery($query);
@@ -113,14 +113,14 @@ class EditController extends Controller
$hasOldInput = null !== $request->old('_token');
$preFilled = [
'active' => $hasOldInput ? (bool)$request->old('active') : $rule->active,
'stop_processing' => $hasOldInput ? (bool)$request->old('stop_processing') : $rule->stop_processing,
'strict' => $hasOldInput ? (bool)$request->old('strict') : $rule->strict,
'active' => $hasOldInput ? (bool) $request->old('active') : $rule->active,
'stop_processing' => $hasOldInput ? (bool) $request->old('stop_processing') : $rule->stop_processing,
'strict' => $hasOldInput ? (bool) $request->old('strict') : $rule->strict,
];
// get rule trigger for update / store-journal:
$primaryTrigger = $this->ruleRepos->getPrimaryTrigger($rule);
$subTitle = (string)trans('firefly.edit_rule', ['title' => $rule->title]);
$subTitle = (string) trans('firefly.edit_rule', ['title' => $rule->title]);
// put previous url in session if not redirect from store (not "return_to_edit").
if (true !== session('rules.edit.fromUpdate')) {
@@ -144,7 +144,7 @@ class EditController extends Controller
$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);
@@ -186,10 +186,10 @@ class EditController extends Controller
$this->ruleRepos->update($rule, $data);
session()->flash('success', (string)trans('firefly.updated_rule', ['title' => $rule->title]));
session()->flash('success', (string) trans('firefly.updated_rule', ['title' => $rule->title]));
app('preferences')->mark();
$redirect = redirect($this->getPreviousUrl('rules.edit.url'));
if (1 === (int)$request->get('return_to_edit')) {
if (1 === (int) $request->get('return_to_edit')) {
session()->put('rules.edit.fromUpdate', true);
$redirect = redirect(route('rules.edit', [$rule->id]))->withInput(['return_to_edit' => 1]);

View File

@@ -53,7 +53,7 @@ class IndexController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
app('view')->share('title', (string)trans('firefly.rules'));
app('view')->share('title', (string) trans('firefly.rules'));
app('view')->share('mainTitleIcon', 'fa-random');
$this->ruleGroupRepos = app(RuleGroupRepositoryInterface::class);
$this->ruleRepos = app(RuleRepositoryInterface::class);
@@ -79,7 +79,7 @@ class IndexController extends Controller
public function moveRule(Request $request, Rule $rule, RuleGroup $ruleGroup): JsonResponse
{
$order = (int)$request->get('order');
$order = (int) $request->get('order');
$this->ruleRepos->moveRule($rule, $ruleGroup, $order);
return response()->json([]);

View File

@@ -56,7 +56,7 @@ class SelectController extends Controller
$this->middleware(
static function ($request, $next) {
app('view')->share('title', (string)trans('firefly.rules'));
app('view')->share('title', (string) trans('firefly.rules'));
app('view')->share('mainTitleIcon', 'fa-random');
return $next($request);
@@ -108,7 +108,7 @@ class SelectController extends Controller
// does the user have shared accounts?
$first = session('first', today(config('app.timezone'))->subYear())->format('Y-m-d');
$today = today(config('app.timezone'))->format('Y-m-d');
$subTitle = (string)trans('firefly.apply_rule_selection', ['title' => $rule->title]);
$subTitle = (string) trans('firefly.apply_rule_selection', ['title' => $rule->title]);
return view('rules.rule.select-transactions', compact('first', 'today', 'rule', 'subTitle'));
}
@@ -133,7 +133,7 @@ class SelectController extends Controller
// warn if nothing.
if (0 === count($textTriggers)) {
return response()->json(['html' => '', 'warning' => (string)trans('firefly.warning_no_valid_triggers')]);
return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]);
}
foreach ($textTriggers as $textTrigger) {
@@ -166,7 +166,7 @@ class SelectController extends Controller
// Warn the user if only a subset of transactions is returned
$warning = '';
if (0 === count($collection)) {
$warning = (string)trans('firefly.warning_no_matching_transactions');
$warning = (string) trans('firefly.warning_no_matching_transactions');
}
// Return json response
@@ -196,7 +196,7 @@ class SelectController extends Controller
$triggers = $rule->ruleTriggers;
if (0 === count($triggers)) {
return response()->json(['html' => '', 'warning' => (string)trans('firefly.warning_no_valid_triggers')]);
return response()->json(['html' => '', 'warning' => (string) trans('firefly.warning_no_valid_triggers')]);
}
// create new rule engine:
$newRuleEngine = app(RuleEngineInterface::class);
@@ -208,7 +208,7 @@ class SelectController extends Controller
$warning = '';
if (0 === count($collection)) {
$warning = (string)trans('firefly.warning_no_matching_transactions');
$warning = (string) trans('firefly.warning_no_matching_transactions');
}
// Return json response