@@ -98,20 +98,15 @@ class ErrorHandler
98
98
private $ bootstrappingLogger ;
99
99
100
100
private static $ reservedMemory ;
101
- private static $ toStringException = null ;
101
+ private static $ toStringException ;
102
102
private static $ silencedErrorCache = [];
103
103
private static $ silencedErrorCount = 0 ;
104
104
private static $ exitCode = 0 ;
105
105
106
106
/**
107
107
* Registers the error handler.
108
- *
109
- * @param self|null $handler The handler to register
110
- * @param bool $replace Whether to replace or not any existing handler
111
- *
112
- * @return self The registered error handler
113
108
*/
114
- public static function register (self $ handler = null , $ replace = true )
109
+ public static function register (self $ handler = null , bool $ replace = true ): self
115
110
{
116
111
if (null === self ::$ reservedMemory ) {
117
112
self ::$ reservedMemory = str_repeat ('x ' , 10240 );
@@ -175,7 +170,7 @@ public function __construct(BufferingLogger $bootstrappingLogger = null)
175
170
* @param array|int $levels An array map of E_* to LogLevel::* or an integer bit field of E_* constants
176
171
* @param bool $replace Whether to replace or not any existing logger
177
172
*/
178
- public function setDefaultLogger (LoggerInterface $ logger , $ levels = E_ALL , $ replace = false )
173
+ public function setDefaultLogger (LoggerInterface $ logger , $ levels = E_ALL , bool $ replace = false ): void
179
174
{
180
175
$ loggers = [];
181
176
@@ -209,7 +204,7 @@ public function setDefaultLogger(LoggerInterface $logger, $levels = E_ALL, $repl
209
204
*
210
205
* @throws \InvalidArgumentException
211
206
*/
212
- public function setLoggers (array $ loggers )
207
+ public function setLoggers (array $ loggers ): array
213
208
{
214
209
$ prevLogged = $ this ->loggedErrors ;
215
210
$ prev = $ this ->loggers ;
@@ -256,11 +251,11 @@ public function setLoggers(array $loggers)
256
251
/**
257
252
* Sets a user exception handler.
258
253
*
259
- * @param callable $handler A handler that will be called on Exception
254
+ * @param callable|null $handler A handler that will be called on Exception
260
255
*
261
256
* @return callable|null The previous exception handler
262
257
*/
263
- public function setExceptionHandler (callable $ handler = null )
258
+ public function setExceptionHandler (? callable $ handler): ? callable
264
259
{
265
260
$ prev = $ this ->exceptionHandler ;
266
261
$ this ->exceptionHandler = $ handler ;
@@ -276,7 +271,7 @@ public function setExceptionHandler(callable $handler = null)
276
271
*
277
272
* @return int The previous value
278
273
*/
279
- public function throwAt ($ levels , $ replace = false )
274
+ public function throwAt (int $ levels , bool $ replace = false ): int
280
275
{
281
276
$ prev = $ this ->thrownErrors ;
282
277
$ this ->thrownErrors = ($ levels | E_RECOVERABLE_ERROR | E_USER_ERROR ) & ~E_USER_DEPRECATED & ~E_DEPRECATED ;
@@ -296,7 +291,7 @@ public function throwAt($levels, $replace = false)
296
291
*
297
292
* @return int The previous value
298
293
*/
299
- public function scopeAt ($ levels , $ replace = false )
294
+ public function scopeAt (int $ levels , bool $ replace = false ): int
300
295
{
301
296
$ prev = $ this ->scopedErrors ;
302
297
$ this ->scopedErrors = (int ) $ levels ;
@@ -315,7 +310,7 @@ public function scopeAt($levels, $replace = false)
315
310
*
316
311
* @return int The previous value
317
312
*/
318
- public function traceAt ($ levels , $ replace = false )
313
+ public function traceAt (int $ levels , bool $ replace = false ): int
319
314
{
320
315
$ prev = $ this ->tracedErrors ;
321
316
$ this ->tracedErrors = (int ) $ levels ;
@@ -334,7 +329,7 @@ public function traceAt($levels, $replace = false)
334
329
*
335
330
* @return int The previous value
336
331
*/
337
- public function screamAt ($ levels , $ replace = false )
332
+ public function screamAt (int $ levels , bool $ replace = false ): int
338
333
{
339
334
$ prev = $ this ->screamedErrors ;
340
335
$ this ->screamedErrors = (int ) $ levels ;
@@ -348,7 +343,7 @@ public function screamAt($levels, $replace = false)
348
343
/**
349
344
* Re-registers as a PHP error handler if levels changed.
350
345
*/
351
- private function reRegister ($ prev )
346
+ private function reRegister (int $ prev ): void
352
347
{
353
348
if ($ prev !== $ this ->thrownErrors | $ this ->loggedErrors ) {
354
349
$ handler = set_error_handler ('var_dump ' );
@@ -368,18 +363,13 @@ private function reRegister($prev)
368
363
/**
369
364
* Handles errors by filtering then logging them according to the configured bit fields.
370
365
*
371
- * @param int $type One of the E_* constants
372
- * @param string $message
373
- * @param string $file
374
- * @param int $line
375
- *
376
366
* @return bool Returns false when no handling happens so that the PHP engine can handle the error itself
377
367
*
378
368
* @throws \ErrorException When $this->thrownErrors requests so
379
369
*
380
370
* @internal
381
371
*/
382
- public function handleError ($ type , $ message , $ file , $ line )
372
+ public function handleError (int $ type , string $ message , string $ file , int $ line ): bool
383
373
{
384
374
// @deprecated to be removed in Symfony 5.0
385
375
if (\PHP_VERSION_ID >= 70300 && $ message && '" ' === $ message [0 ] && 0 === strpos ($ message , '"continue ' ) && preg_match ('/^"continue(?: \d++)?" targeting switch is equivalent to "break(?: \d++)?"\. Did you mean to use "continue(?: \d++)?"\?$/ ' , $ message )) {
@@ -442,7 +432,7 @@ public function handleError($type, $message, $file, $line)
442
432
self ::$ silencedErrorCache [$ id ][$ message ] = $ errorAsException ;
443
433
}
444
434
if (null === $ lightTrace ) {
445
- return ;
435
+ return true ;
446
436
}
447
437
} else {
448
438
$ errorAsException = new \ErrorException ($ logMessage , 0 , $ type , $ file , $ line );
@@ -590,11 +580,11 @@ public function handleException($exception, array $error = null)
590
580
/**
591
581
* Shutdown registered function for handling PHP fatal errors.
592
582
*
593
- * @param array $error An array as returned by error_get_last()
583
+ * @param array|null $error An array as returned by error_get_last()
594
584
*
595
585
* @internal
596
586
*/
597
- public static function handleFatalError (array $ error = null )
587
+ public static function handleFatalError (array $ error = null ): void
598
588
{
599
589
if (null === self ::$ reservedMemory ) {
600
590
return ;
@@ -674,7 +664,7 @@ public static function handleFatalError(array $error = null)
674
664
*
675
665
* @return FatalErrorHandlerInterface[] An array of FatalErrorHandlerInterface
676
666
*/
677
- protected function getFatalErrorHandlers ()
667
+ protected function getFatalErrorHandlers (): array
678
668
{
679
669
return [
680
670
new UndefinedFunctionFatalErrorHandler (),
@@ -686,7 +676,7 @@ protected function getFatalErrorHandlers()
686
676
/**
687
677
* Cleans the trace by removing function arguments and the frames added by the error handler and DebugClassLoader.
688
678
*/
689
- private function cleanTrace ($ backtrace , $ type , $ file , $ line , $ throw )
679
+ private function cleanTrace (array $ backtrace , int $ type , string $ file , int $ line , bool $ throw ): array
690
680
{
691
681
$ lightTrace = $ backtrace ;
692
682
0 commit comments