Completed
Push — master ( 273f6a...0114af )
by Abdelrahman
08:12
created

Handler::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 3
nop 2
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Exceptions;
17
18
use Exception;
19
use Illuminate\Support\Facades\Lang;
20
use Illuminate\Auth\AuthenticationException;
21
use App\Exceptions\Handler as ExceptionHandler;
22
use Rinvex\Repository\Exceptions\EntityNotFoundException;
23
24
class Handler extends ExceptionHandler
25
{
26
    /**
27
     * Render an exception into an HTTP response.
28
     *
29
     * @param  \Illuminate\Http\Request $request
30
     * @param  \Exception               $exception
31
     *
32
     * @return \Illuminate\Http\Response
33
     */
34
    public function render($request, Exception $exception)
35
    {
36
        if ($exception instanceof InvalidPersistenceException) {
37
            return intend([
38
                'route'      => 'rinvex.fort.frontend.auth.login',
39
                'withErrors' => ['rinvex.fort.session.expired' => Lang::get('rinvex.fort::frontend/messages.auth.session.expired')],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
40
            ], 401);
41
        } else if ($exception instanceof EntityNotFoundException) {
42
            $single = strtolower(trim(strrchr($exception->getModel(), '\\'), '\\'));
43
            $plural = str_plural($single);
44
45
            return intend([
46
                'route'      => 'rinvex.fort.backend.'.$plural.'.index',
47
                'withErrors' => ['rinvex.fort.'.$single.'.not_found' => trans('rinvex.fort::backend/messages.'.$single.'.not_found', [$single => $exception->getId()])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 168 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
48
            ]);
49
        }
50
51
        return parent::render($request, $exception);
52
    }
53
54
    /**
55
     * Convert an authentication exception into an unauthenticated response.
56
     *
57
     * @param  \Illuminate\Http\Request                 $request
58
     * @param  \Illuminate\Auth\AuthenticationException $exception
59
     *
60
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\Redirec...inate\Http\JsonResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
61
     */
62
    protected function unauthenticated($request, AuthenticationException $exception)
63
    {
64
        return intend([
65
            'route'      => 'rinvex.fort.frontend.auth.login',
66
            'withErrors' => ['rinvex.fort.session.required' => Lang::get('rinvex.fort::frontend/messages.auth.session.required')],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 130 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
67
        ], 401);
68
    }
69
}
70