Code cleanup

This commit is contained in:
James Cole
2021-03-21 09:15:40 +01:00
parent da1751940e
commit 206845575c
317 changed files with 7418 additions and 7362 deletions

View File

@@ -128,8 +128,10 @@ class GracefulNotFoundHandler extends ExceptionHandler
case 'transactions.bulk.edit':
if ('POST' === $request->method()) {
$request->session()->reflash();
return redirect(route('index'));
}
return parent::render($request, $exception);
}
@@ -148,7 +150,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
/** @var User $user */
$user = auth()->user();
$route = $request->route();
$accountId = (int) $route->parameter('account');
$accountId = (int)$route->parameter('account');
/** @var Account $account */
$account = $user->accounts()->with(['accountType'])->withTrashed()->find($accountId);
if (null === $account) {
@@ -163,6 +165,46 @@ class GracefulNotFoundHandler extends ExceptionHandler
return redirect(route('accounts.index', [$shortType]));
}
/**
* @param Throwable $request
* @param Exception $exception
*
* @return RedirectResponse|\Illuminate\Http\Response|Redirector|Response
* @throws Exception
*/
private function handleGroup(Request $request, Throwable $exception)
{
Log::debug('404 page is probably a deleted group. Redirect to overview of group types.');
/** @var User $user */
$user = auth()->user();
$route = $request->route();
$groupId = (int)$route->parameter('transactionGroup');
/** @var TransactionGroup $group */
$group = $user->transactionGroups()->withTrashed()->find($groupId);
if (null === $group) {
Log::error(sprintf('Could not find group %d, so give big fat error.', $groupId));
return parent::render($request, $exception);
}
/** @var TransactionJournal $journal */
$journal = $group->transactionJournals()->withTrashed()->first();
if (null === $journal) {
Log::error(sprintf('Could not find journal for group %d, so give big fat error.', $groupId));
return parent::render($request, $exception);
}
$type = $journal->transactionType->type;
$request->session()->reflash();
if (TransactionType::RECONCILIATION === $type) {
return redirect(route('accounts.index', ['asset']));
}
return redirect(route('transactions.index', [strtolower($type)]));
}
/**
* @param Request $request
* @param Throwable $exception
@@ -176,7 +218,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
/** @var User $user */
$user = auth()->user();
$route = $request->route();
$attachmentId = (int) $route->parameter('attachment');
$attachmentId = (int)$route->parameter('attachment');
/** @var Attachment $attachment */
$attachment = $user->attachments()->withTrashed()->find($attachmentId);
if (null === $attachment) {
@@ -208,44 +250,4 @@ class GracefulNotFoundHandler extends ExceptionHandler
return parent::render($request, $exception);
}
/**
* @param Throwable $request
* @param Exception $exception
*
* @return RedirectResponse|\Illuminate\Http\Response|Redirector|Response
* @throws Exception
*/
private function handleGroup(Request $request, Throwable $exception)
{
Log::debug('404 page is probably a deleted group. Redirect to overview of group types.');
/** @var User $user */
$user = auth()->user();
$route = $request->route();
$groupId = (int) $route->parameter('transactionGroup');
/** @var TransactionGroup $group */
$group = $user->transactionGroups()->withTrashed()->find($groupId);
if (null === $group) {
Log::error(sprintf('Could not find group %d, so give big fat error.', $groupId));
return parent::render($request, $exception);
}
/** @var TransactionJournal $journal */
$journal = $group->transactionJournals()->withTrashed()->first();
if (null === $journal) {
Log::error(sprintf('Could not find journal for group %d, so give big fat error.', $groupId));
return parent::render($request, $exception);
}
$type = $journal->transactionType->type;
$request->session()->reflash();
if (TransactionType::RECONCILIATION === $type) {
return redirect(route('accounts.index', ['asset']));
}
return redirect(route('transactions.index', [strtolower($type)]));
}
}

View File

@@ -36,6 +36,7 @@ use Illuminate\Validation\ValidationException as LaravelValidationException;
use League\OAuth2\Server\Exception\OAuthServerException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Throwable;
/**
* Class Handler
*
@@ -87,7 +88,9 @@ class Handler extends ExceptionHandler
);
}
return response()->json(['message' => sprintf('Internal Firefly III Exception: %s', $exception->getMessage()), 'exception' => get_class($exception)], 500);
return response()->json(
['message' => sprintf('Internal Firefly III Exception: %s', $exception->getMessage()), 'exception' => get_class($exception)], 500
);
}
if ($exception instanceof NotFoundHttpException) {
@@ -115,9 +118,9 @@ class Handler extends ExceptionHandler
*
* @param Exception $exception
*
* @return void
* @throws Exception
*
* @return void
*/
public function report(Throwable $exception)
{
@@ -150,7 +153,7 @@ class Handler extends ExceptionHandler
// create job that will mail.
$ipAddress = request()->ip() ?? '0.0.0.0';
$job = new MailError($userData, (string) config('firefly.site_owner'), $ipAddress, $data);
$job = new MailError($userData, (string)config('firefly.site_owner'), $ipAddress, $data);
dispatch($job);
}