Passed
Push — main ( 7be313...891842 )
by Thierry
19:01 queued 53s
created

Handler::getCallableObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Exceptions;
4
5
use App\Ajax\Web\Meeting\Session;
6
use App\Ajax\Web\Planning\Pool;
7
use App\Ajax\Web\Planning\Round;
8
use App\Ajax\Web\Tontine\Member;
9
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
10
use Jaxon\Laravel\Jaxon;
11
use Siak\Tontine\Exception\AuthenticationException;
12
use Siak\Tontine\Exception\MessageException;
13
use Siak\Tontine\Exception\MeetingRoundException;
14
use Siak\Tontine\Exception\PlanningPoolException;
15
use Siak\Tontine\Exception\PlanningRoundException;
16
use Siak\Tontine\Exception\TontineMemberException;
17
use Throwable;
18
19
use function app;
20
use function route;
21
use function trans;
22
23
class Handler extends ExceptionHandler
24
{
25
    /**
26
     * A list of exception types with their corresponding custom log levels.
27
     *
28
     * @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string<\Thro...e>, \Psr\Log\LogLevel:: at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string<\Throwable>, \Psr\Log\LogLevel::.
Loading history...
29
     */
30
    protected $levels = [
31
        //
32
    ];
33
34
    /**
35
     * A list of the exception types that are not reported.
36
     *
37
     * @var array<int, class-string<\Throwable>>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<int, class-string<\Throwable>> at position 4 could not be parsed: Unknown type name 'class-string' at position 4 in array<int, class-string<\Throwable>>.
Loading history...
38
     */
39
    protected $dontReport = [
40
        AuthenticationException::class,
41
        MessageException::class,
42
        PlanningPoolException::class,
43
        PlanningRoundException::class,
44
        TontineMemberException::class,
45
        MeetingRoundException::class,
46
    ];
47
48
    /**
49
     * A list of the inputs that are never flashed to the session on validation exceptions.
50
     *
51
     * @var array<int, string>
52
     */
53
    protected $dontFlash = [
54
        'current_password',
55
        'password',
56
        'password_confirmation',
57
    ];
58
59
    /**
60
     * Register the exception handling callbacks for the application.
61
     *
62
     * @return void
63
     */
64
    public function register()
65
    {
66
        $jaxon = app()->make(Jaxon::class);
67
68
        $this->reportable(function (Throwable $e) {
0 ignored issues
show
Unused Code introduced by
The parameter $e is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

68
        $this->reportable(function (/** @scrutinizer ignore-unused */ Throwable $e) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
            //
70
        });
71
72
        // Redirect to the login page
73
        $this->renderable(function (AuthenticationException $e) use($jaxon) {
0 ignored issues
show
Unused Code introduced by
The parameter $e is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

73
        $this->renderable(function (/** @scrutinizer ignore-unused */ AuthenticationException $e) use($jaxon) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
            $ajaxResponse = $jaxon->ajaxResponse();
75
            $ajaxResponse->redirect(route('login'));
76
77
            return $jaxon->httpResponse();
78
        });
79
80
        // Show the error message in a dialog
81
        $this->renderable(function (MessageException $e) use($jaxon) {
82
            $ajaxResponse = $jaxon->ajaxResponse();
83
            $ajaxResponse->dialog->error($e->getMessage(), trans('common.titles.error'));
0 ignored issues
show
Bug introduced by
Accessing dialog on the interface Jaxon\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
84
85
            return $jaxon->httpResponse();
86
        });
87
88
        // Show the warning message in a dialog, and show the sessions page.
89
        $this->renderable(function (PlanningRoundException $e) use($jaxon) {
90
            $jaxon->cl(Round::class)->home();
91
92
            $ajaxResponse = $jaxon->ajaxResponse();
93
            $ajaxResponse->dialog->warning($e->getMessage(), trans('common.titles.warning'));
0 ignored issues
show
Bug introduced by
Accessing dialog on the interface Jaxon\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
94
95
            return $jaxon->httpResponse();
96
        });
97
98
        // Show the warning message in a dialog, and show the pools page.
99
        $this->renderable(function (PlanningPoolException $e) use($jaxon) {
100
            $jaxon->cl(Pool::class)->home();
101
102
            $ajaxResponse = $jaxon->ajaxResponse();
103
            $ajaxResponse->dialog->warning($e->getMessage(), trans('common.titles.warning'));
0 ignored issues
show
Bug introduced by
Accessing dialog on the interface Jaxon\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
104
105
            return $jaxon->httpResponse();
106
        });
107
108
        // Show the warning message in a dialog, and show the members page.
109
        $this->renderable(function (TontineMemberException $e) use($jaxon) {
110
            $jaxon->cl(Member::class)->home();
111
112
            $ajaxResponse = $jaxon->ajaxResponse();
113
            $ajaxResponse->dialog->warning($e->getMessage(), trans('common.titles.warning'));
0 ignored issues
show
Bug introduced by
Accessing dialog on the interface Jaxon\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
114
115
            return $jaxon->httpResponse();
116
        });
117
118
        // Show the warning message in a dialog, and show the sessions page.
119
        $this->renderable(function (MeetingRoundException $e) use($jaxon) {
120
            $jaxon->cl(Session::class)->home();
121
122
            $ajaxResponse = $jaxon->ajaxResponse();
123
            $ajaxResponse->dialog->warning($e->getMessage(), trans('common.titles.warning'));
0 ignored issues
show
Bug introduced by
Accessing dialog on the interface Jaxon\Response\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
124
125
            return $jaxon->httpResponse();
126
        });
127
    }
128
}
129