33namespace Illuminated \Console \Exceptions ;
44
55use Illuminate \Foundation \Exceptions \Handler ;
6- use Psr \ Log \ LoggerInterface ;
6+ use Monolog \ Logger ;
77use Throwable ;
88
99class ExceptionHandler extends Handler
1010{
1111 /**
1212 * The logger instance.
13- *
14- * @var \Psr\Log\LoggerInterface
1513 */
16- private $ logger ;
14+ private Logger $ logger ;
1715
1816 /**
1917 * Time when execution started.
20- *
21- * @var float
2218 */
23- private $ timeStarted ;
24-
25- /**
26- * Time when execution finished.
27- *
28- * @var float
29- */
30- private $ timeFinished ;
19+ private float $ timeStarted ;
3120
3221 /**
3322 * Reserved memory for the shutdown execution.
3423 *
3524 * @see https://github.com/dmitry-ivanov/laravel-console-logger/issues/4
36- *
37- * @var string
3825 */
39- protected $ reservedMemory ;
26+ protected ? string $ reservedMemory ;
4027
4128 /**
4229 * Initialize the exception handler.
43- *
44- * @param \Psr\Log\LoggerInterface $logger
45- * @return void
4630 */
47- public function initialize (LoggerInterface $ logger )
31+ public function initialize (Logger $ logger ): void
4832 {
4933 $ this ->setLogger ($ logger );
5034 $ this ->registerShutdownFunction ();
5135 }
5236
5337 /**
5438 * Set the logger.
55- *
56- * @param \Psr\Log\LoggerInterface $logger
57- * @return void
5839 */
59- public function setLogger (LoggerInterface $ logger )
40+ public function setLogger (Logger $ logger ): void
6041 {
6142 $ this ->logger = $ logger ;
6243 }
@@ -66,11 +47,8 @@ public function setLogger(LoggerInterface $logger)
6647 *
6748 * Note that this method doesn't decorate, but overwrite the parent method:
6849 * @see https://github.com/dmitry-ivanov/laravel-console-logger/pull/11
69- *
70- * @param \Throwable $e
71- * @return void
7250 */
73- public function report (Throwable $ e )
51+ public function report (Throwable $ e ): void
7452 {
7553 $ context = [
7654 'code ' => $ e ->getCode (),
@@ -93,11 +71,8 @@ public function report(Throwable $e)
9371
9472 /**
9573 * Add Sentry support.
96- *
97- * @param \Throwable $e
98- * @return void
9974 */
100- private function addSentrySupport (Throwable $ e )
75+ private function addSentrySupport (Throwable $ e ): void
10176 {
10277 if (app ()->bound ('sentry ' ) && $ this ->shouldReport ($ e )) {
10378 app ('sentry ' )->captureException ($ e );
@@ -106,10 +81,8 @@ private function addSentrySupport(Throwable $e)
10681
10782 /**
10883 * Register the shutdown function.
109- *
110- * @return void
11184 */
112- private function registerShutdownFunction ()
85+ private function registerShutdownFunction (): void
11386 {
11487 $ this ->timeStarted = microtime (true );
11588 $ this ->reservedMemory = str_repeat (' ' , 20 * 1024 );
@@ -119,23 +92,21 @@ private function registerShutdownFunction()
11992
12093 /**
12194 * Callback for the shutdown function.
122- *
123- * @return void
12495 */
125- public function onShutdown ()
96+ public function onShutdown (): void
12697 {
12798 $ this ->reservedMemory = null ;
12899
129- $ this -> timeFinished = microtime (true );
130- $ executionTime = round ($ this -> timeFinished - $ this ->timeStarted , 3 );
100+ $ timeFinished = microtime (true );
101+ $ executionTime = round ($ timeFinished - $ this ->timeStarted , 3 );
131102 $ this ->logger ->info ("Execution time: {$ executionTime } sec. " );
132103
133104 $ memoryPeak = format_bytes (memory_get_peak_usage (true ));
134105 $ this ->logger ->info ("Memory peak usage: {$ memoryPeak }. " );
135106
136107 $ this ->logger ->info ('%separator% ' );
137108
138- $ handlers = ( array ) $ this ->logger ->getHandlers ();
109+ $ handlers = $ this ->logger ->getHandlers ();
139110 foreach ($ handlers as $ handler ) {
140111 $ handler ->close ();
141112 }
0 commit comments