3
3
namespace Illuminated \Console \Exceptions ;
4
4
5
5
use Illuminate \Foundation \Exceptions \Handler ;
6
- use Psr \ Log \ LoggerInterface ;
6
+ use Monolog \ Logger ;
7
7
use Throwable ;
8
8
9
9
class ExceptionHandler extends Handler
10
10
{
11
11
/**
12
12
* The logger instance.
13
- *
14
- * @var \Psr\Log\LoggerInterface
15
13
*/
16
- private $ logger ;
14
+ private Logger $ logger ;
17
15
18
16
/**
19
17
* Time when execution started.
20
- *
21
- * @var float
22
18
*/
23
- private $ timeStarted ;
24
-
25
- /**
26
- * Time when execution finished.
27
- *
28
- * @var float
29
- */
30
- private $ timeFinished ;
19
+ private float $ timeStarted ;
31
20
32
21
/**
33
22
* Reserved memory for the shutdown execution.
34
23
*
35
24
* @see https://github.com/dmitry-ivanov/laravel-console-logger/issues/4
36
- *
37
- * @var string
38
25
*/
39
- protected $ reservedMemory ;
26
+ protected ? string $ reservedMemory ;
40
27
41
28
/**
42
29
* Initialize the exception handler.
43
- *
44
- * @param \Psr\Log\LoggerInterface $logger
45
- * @return void
46
30
*/
47
- public function initialize (LoggerInterface $ logger )
31
+ public function initialize (Logger $ logger ): void
48
32
{
49
33
$ this ->setLogger ($ logger );
50
34
$ this ->registerShutdownFunction ();
51
35
}
52
36
53
37
/**
54
38
* Set the logger.
55
- *
56
- * @param \Psr\Log\LoggerInterface $logger
57
- * @return void
58
39
*/
59
- public function setLogger (LoggerInterface $ logger )
40
+ public function setLogger (Logger $ logger ): void
60
41
{
61
42
$ this ->logger = $ logger ;
62
43
}
@@ -66,11 +47,8 @@ public function setLogger(LoggerInterface $logger)
66
47
*
67
48
* Note that this method doesn't decorate, but overwrite the parent method:
68
49
* @see https://github.com/dmitry-ivanov/laravel-console-logger/pull/11
69
- *
70
- * @param \Throwable $e
71
- * @return void
72
50
*/
73
- public function report (Throwable $ e )
51
+ public function report (Throwable $ e ): void
74
52
{
75
53
$ context = [
76
54
'code ' => $ e ->getCode (),
@@ -93,11 +71,8 @@ public function report(Throwable $e)
93
71
94
72
/**
95
73
* Add Sentry support.
96
- *
97
- * @param \Throwable $e
98
- * @return void
99
74
*/
100
- private function addSentrySupport (Throwable $ e )
75
+ private function addSentrySupport (Throwable $ e ): void
101
76
{
102
77
if (app ()->bound ('sentry ' ) && $ this ->shouldReport ($ e )) {
103
78
app ('sentry ' )->captureException ($ e );
@@ -106,10 +81,8 @@ private function addSentrySupport(Throwable $e)
106
81
107
82
/**
108
83
* Register the shutdown function.
109
- *
110
- * @return void
111
84
*/
112
- private function registerShutdownFunction ()
85
+ private function registerShutdownFunction (): void
113
86
{
114
87
$ this ->timeStarted = microtime (true );
115
88
$ this ->reservedMemory = str_repeat (' ' , 20 * 1024 );
@@ -119,23 +92,21 @@ private function registerShutdownFunction()
119
92
120
93
/**
121
94
* Callback for the shutdown function.
122
- *
123
- * @return void
124
95
*/
125
- public function onShutdown ()
96
+ public function onShutdown (): void
126
97
{
127
98
$ this ->reservedMemory = null ;
128
99
129
- $ this -> timeFinished = microtime (true );
130
- $ executionTime = round ($ this -> timeFinished - $ this ->timeStarted , 3 );
100
+ $ timeFinished = microtime (true );
101
+ $ executionTime = round ($ timeFinished - $ this ->timeStarted , 3 );
131
102
$ this ->logger ->info ("Execution time: {$ executionTime } sec. " );
132
103
133
104
$ memoryPeak = format_bytes (memory_get_peak_usage (true ));
134
105
$ this ->logger ->info ("Memory peak usage: {$ memoryPeak }. " );
135
106
136
107
$ this ->logger ->info ('%separator% ' );
137
108
138
- $ handlers = ( array ) $ this ->logger ->getHandlers ();
109
+ $ handlers = $ this ->logger ->getHandlers ();
139
110
foreach ($ handlers as $ handler ) {
140
111
$ handler ->close ();
141
112
}
0 commit comments