Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -33,7 +33,6 @@ use FireflyIII\User;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Throwable;
/**
* Class GracefulNotFoundHandler
@@ -43,13 +42,11 @@ class GracefulNotFoundHandler extends ExceptionHandler
/**
* Render an exception into an HTTP response.
*
* @param Request $request
* @param Throwable $e
* @param Request $request
*
* @return Response
* @throws Throwable
* @throws \Throwable
*/
public function render($request, Throwable $e): Response
public function render($request, \Throwable $e): Response
{
$route = $request->route();
if (null === $route) {
@@ -65,57 +62,69 @@ class GracefulNotFoundHandler extends ExceptionHandler
app('log')->warning(sprintf('GracefulNotFoundHandler cannot handle route with name "%s"', $name));
return parent::render($request, $e);
case 'accounts.show':
case 'accounts.edit':
case 'accounts.show.all':
return $this->handleAccount($request, $e);
case 'transactions.show':
case 'transactions.edit':
return $this->handleGroup($request, $e);
case 'attachments.show':
case 'attachments.edit':
case 'attachments.download':
case 'attachments.view':
// redirect to original attachment holder.
return $this->handleAttachment($request, $e);
case 'bills.show':
$request->session()->reflash();
return redirect(route('bills.index'));
case 'currencies.show':
$request->session()->reflash();
return redirect(route('currencies.index'));
case 'budgets.show':
case 'budgets.edit':
case 'budgets.show.limit':
$request->session()->reflash();
return redirect(route('budgets.index'));
case 'piggy-banks.show':
$request->session()->reflash();
return redirect(route('piggy-banks.index'));
case 'recurring.show':
case 'recurring.edit':
$request->session()->reflash();
return redirect(route('recurring.index'));
case 'tags.show.all':
case 'tags.show':
case 'tags.edit':
$request->session()->reflash();
return redirect(route('tags.index'));
case 'categories.show':
case 'categories.show.all':
$request->session()->reflash();
return redirect(route('categories.index'));
case 'rules.edit':
$request->session()->reflash();
return redirect(route('rules.index'));
case 'transactions.mass.edit':
case 'transactions.mass.delete':
case 'transactions.bulk.edit':
@@ -130,15 +139,12 @@ class GracefulNotFoundHandler extends ExceptionHandler
}
/**
* @param Request $request
* @param Throwable $exception
*
* @return Response
* @throws Throwable
* @throws \Throwable
*/
private function handleAccount(Request $request, Throwable $exception): Response
private function handleAccount(Request $request, \Throwable $exception): Response
{
app('log')->debug('404 page is probably a deleted account. Redirect to overview of account types.');
/** @var User $user */
$user = auth()->user();
$route = $request->route();
@@ -150,7 +156,8 @@ class GracefulNotFoundHandler extends ExceptionHandler
if (!($param instanceof Account) && !is_object($param)) {
$accountId = (int)$param;
}
/** @var Account|null $account */
/** @var null|Account $account */
$account = $user->accounts()->with(['accountType'])->withTrashed()->find($accountId);
if (null === $account) {
app('log')->error(sprintf('Could not find account %d, so give big fat error.', $accountId));
@@ -165,29 +172,29 @@ class GracefulNotFoundHandler extends ExceptionHandler
}
/**
* @param Request $request
* @param Throwable $exception
*
* @return Response
* @throws Throwable
*
* @throws \Throwable
*/
private function handleGroup(Request $request, Throwable $exception)
private function handleGroup(Request $request, \Throwable $exception)
{
app('log')->debug('404 page is probably a deleted group. Redirect to overview of group types.');
/** @var User $user */
$user = auth()->user();
$route = $request->route();
$param = $route->parameter('transactionGroup');
$groupId = !is_object($param) ? (int)$param : 0;
/** @var TransactionGroup|null $group */
/** @var null|TransactionGroup $group */
$group = $user->transactionGroups()->withTrashed()->find($groupId);
if (null === $group) {
app('log')->error(sprintf('Could not find group %d, so give big fat error.', $groupId));
return parent::render($request, $exception);
}
/** @var TransactionJournal|null $journal */
/** @var null|TransactionJournal $journal */
$journal = $group->transactionJournals()->withTrashed()->first();
if (null === $journal) {
app('log')->error(sprintf('Could not find journal for group %d, so give big fat error.', $groupId));
@@ -205,21 +212,21 @@ class GracefulNotFoundHandler extends ExceptionHandler
}
/**
* @param Request $request
* @param Throwable $exception
*
* @return Response
* @throws Throwable
*
* @throws \Throwable
*/
private function handleAttachment(Request $request, Throwable $exception)
private function handleAttachment(Request $request, \Throwable $exception)
{
app('log')->debug('404 page is probably a deleted attachment. Redirect to parent object.');
/** @var User $user */
$user = auth()->user();
$route = $request->route();
$param = $route->parameter('attachment');
$attachmentId = is_object($param) ? 0 : (int)$param;
/** @var Attachment|null $attachment */
/** @var null|Attachment $attachment */
$attachment = $user->attachments()->withTrashed()->find($attachmentId);
if (null === $attachment) {
app('log')->error(sprintf('Could not find attachment %d, so give big fat error.', $attachmentId));
@@ -229,7 +236,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
// get bindable.
if (TransactionJournal::class === $attachment->attachable_type) {
// is linked to journal, get group of journal (if not also deleted)
/** @var TransactionJournal|null $journal */
/** @var null|TransactionJournal $journal */
$journal = $user->transactionJournals()->withTrashed()->find($attachment->attachable_id);
if (null !== $journal) {
return redirect(route('transactions.show', [$journal->transaction_group_id]));
@@ -237,7 +244,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
}
if (Bill::class === $attachment->attachable_type) {
// is linked to bill.
/** @var Bill|null $bill */
/** @var null|Bill $bill */
$bill = $user->bills()->withTrashed()->find($attachment->attachable_id);
if (null !== $bill) {
return redirect(route('bills.show', [$bill->id]));