Skip to content

Commit ac7b53d

Browse files
committed
[ErrorHandler] Add types to private properties
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent 733731f commit ac7b53d

File tree

8 files changed

+70
-94
lines changed

8 files changed

+70
-94
lines changed

BufferingLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class BufferingLogger extends AbstractLogger
2222
{
23-
private $logs = [];
23+
private array $logs = [];
2424

2525
public function log($level, $message, array $context = []): void
2626
{

DebugClassLoader.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,27 @@ class DebugClassLoader
100100
'__serialize' => 'array',
101101
];
102102

103+
/**
104+
* @var callable
105+
*/
103106
private $classLoader;
104-
private $isFinder;
105-
private $loaded = [];
106-
private $patchTypes;
107-
108-
private static $caseCheck;
109-
private static $checkedClasses = [];
110-
private static $final = [];
111-
private static $finalMethods = [];
112-
private static $deprecated = [];
113-
private static $internal = [];
114-
private static $internalMethods = [];
115-
private static $annotatedParameters = [];
116-
private static $darwinCache = ['/' => ['/', []]];
117-
private static $method = [];
118-
private static $returnTypes = [];
119-
private static $methodTraits = [];
120-
private static $fileOffsets = [];
107+
private bool $isFinder;
108+
private array $loaded = [];
109+
private array $patchTypes = [];
110+
111+
private static int $caseCheck;
112+
private static array $checkedClasses = [];
113+
private static array $final = [];
114+
private static array $finalMethods = [];
115+
private static array $deprecated = [];
116+
private static array $internal = [];
117+
private static array $internalMethods = [];
118+
private static array $annotatedParameters = [];
119+
private static array $darwinCache = ['/' => ['/', []]];
120+
private static array $method = [];
121+
private static array $returnTypes = [];
122+
private static array $methodTraits = [];
123+
private static array $fileOffsets = [];
121124

122125
public function __construct(callable $classLoader)
123126
{

Error/FatalError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class FatalError extends \Error
1515
{
16-
private $error;
16+
private array $error;
1717

1818
/**
1919
* {@inheritdoc}

ErrorHandler.php

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
*/
5151
class ErrorHandler
5252
{
53-
private $levels = [
53+
private array $levels = [
5454
\E_DEPRECATED => 'Deprecated',
5555
\E_USER_DEPRECATED => 'User Deprecated',
5656
\E_NOTICE => 'Notice',
@@ -68,7 +68,7 @@ class ErrorHandler
6868
\E_CORE_ERROR => 'Core Error',
6969
];
7070

71-
private $loggers = [
71+
private array $loggers = [
7272
\E_DEPRECATED => [null, LogLevel::INFO],
7373
\E_USER_DEPRECATED => [null, LogLevel::INFO],
7474
\E_NOTICE => [null, LogLevel::WARNING],
@@ -86,24 +86,23 @@ class ErrorHandler
8686
\E_CORE_ERROR => [null, LogLevel::CRITICAL],
8787
];
8888

89-
private $thrownErrors = 0x1FFF; // E_ALL - E_DEPRECATED - E_USER_DEPRECATED
90-
private $scopedErrors = 0x1FFF; // E_ALL - E_DEPRECATED - E_USER_DEPRECATED
91-
private $tracedErrors = 0x77FB; // E_ALL - E_STRICT - E_PARSE
92-
private $screamedErrors = 0x55; // E_ERROR + E_CORE_ERROR + E_COMPILE_ERROR + E_PARSE
93-
private $loggedErrors = 0;
94-
private $configureException;
95-
private $debug;
89+
private int $thrownErrors = 0x1FFF; // E_ALL - E_DEPRECATED - E_USER_DEPRECATED
90+
private int $scopedErrors = 0x1FFF; // E_ALL - E_DEPRECATED - E_USER_DEPRECATED
91+
private int $tracedErrors = 0x77FB; // E_ALL - E_STRICT - E_PARSE
92+
private int $screamedErrors = 0x55; // E_ERROR + E_CORE_ERROR + E_COMPILE_ERROR + E_PARSE
93+
private int $loggedErrors = 0;
94+
private \Closure $configureException;
95+
private bool $debug;
9696

97-
private $isRecursive = 0;
98-
private $isRoot = false;
97+
private bool $isRecursive = false;
98+
private bool $isRoot = false;
9999
private $exceptionHandler;
100-
private $bootstrappingLogger;
100+
private ?BufferingLogger $bootstrappingLogger = null;
101101

102-
private static $reservedMemory;
103-
private static $toStringException;
104-
private static $silencedErrorCache = [];
105-
private static $silencedErrorCount = 0;
106-
private static $exitCode = 0;
102+
private static ?string $reservedMemory = null;
103+
private static array $silencedErrorCache = [];
104+
private static int $silencedErrorCount = 0;
105+
private static int $exitCode = 0;
107106

108107
/**
109108
* Registers the error handler.
@@ -411,10 +410,7 @@ public function handleError(int $type, string $message, string $file, int $line)
411410

412411
$logMessage = $this->levels[$type].': '.$message;
413412

414-
if (null !== self::$toStringException) {
415-
$errorAsException = self::$toStringException;
416-
self::$toStringException = null;
417-
} elseif (!$throw && !($type & $level)) {
413+
if (!$throw && !($type & $level)) {
418414
if (!isset(self::$silencedErrorCache[$id = $file.':'.$line])) {
419415
$lightTrace = $this->tracedErrors & $type ? $this->cleanTrace(debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 5), $type, $file, $line, false) : [];
420416
$errorAsException = new SilencedErrorContext($type, $file, $line, isset($lightTrace[1]) ? [$lightTrace[0]] : $lightTrace);

ErrorRenderer/HtmlErrorRenderer.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,26 @@ class HtmlErrorRenderer implements ErrorRendererInterface
3333
private const GHOST_HEART = 'M125.91386369681868,8.305165958366445 C128.95033202169043,-0.40540639102854037 140.8469835342744,8.305165958366445 125.91386369681868,19.504526138305664 C110.98208663272044,8.305165958366445 122.87795231771452,-0.40540639102854037 125.91386369681868,8.305165958366445 z';
3434
private const GHOST_PLUS = 'M111.36824226379395,8.969108581542969 L118.69175148010254,8.969108581542969 L118.69175148010254,1.6455793380737305 L126.20429420471191,1.6455793380737305 L126.20429420471191,8.969108581542969 L133.52781105041504,8.969108581542969 L133.52781105041504,16.481630325317383 L126.20429420471191,16.481630325317383 L126.20429420471191,23.805158615112305 L118.69175148010254,23.805158615112305 L118.69175148010254,16.481630325317383 L111.36824226379395,16.481630325317383 z';
3535

36-
private $debug;
37-
private $charset;
38-
private $fileLinkFormat;
39-
private $projectDir;
40-
private $outputBuffer;
41-
private $logger;
36+
private bool|\Closure $debug;
37+
private string $charset;
38+
private string|array|FileLinkFormatter|false $fileLinkFormat;
39+
private ?string $projectDir;
40+
private string|\Closure $outputBuffer;
41+
private ?LoggerInterface $logger;
4242

43-
private static $template = 'views/error.html.php';
43+
private static string $template = 'views/error.html.php';
4444

4545
/**
4646
* @param bool|callable $debug The debugging mode as a boolean or a callable that should return it
4747
* @param string|callable $outputBuffer The output buffer as a string or a callable that should return it
4848
*/
4949
public function __construct(bool|callable $debug = false, string $charset = null, string|FileLinkFormatter $fileLinkFormat = null, string $projectDir = null, string|callable $outputBuffer = '', LoggerInterface $logger = null)
5050
{
51-
$this->debug = $debug;
51+
$this->debug = \is_bool($debug) || $debug instanceof \Closure ? $debug : \Closure::fromCallable($debug);
5252
$this->charset = $charset ?: (ini_get('default_charset') ?: 'UTF-8');
5353
$this->fileLinkFormat = $fileLinkFormat ?: (ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'));
5454
$this->projectDir = $projectDir;
55-
$this->outputBuffer = $outputBuffer;
55+
$this->outputBuffer = \is_string($outputBuffer) || $outputBuffer instanceof \Closure ? $outputBuffer : \Closure::fromCallable($outputBuffer);
5656
$this->logger = $logger;
5757
}
5858

ErrorRenderer/SerializerErrorRenderer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
*/
2525
class SerializerErrorRenderer implements ErrorRendererInterface
2626
{
27-
private $serializer;
28-
private $format;
29-
private $fallbackErrorRenderer;
30-
private $debug;
27+
private SerializerInterface $serializer;
28+
private string|\Closure $format;
29+
private ErrorRendererInterface $fallbackErrorRenderer;
30+
private bool|\Closure $debug;
3131

3232
/**
3333
* @param string|callable(FlattenException) $format The format as a string or a callable that should return it
@@ -37,9 +37,9 @@ class SerializerErrorRenderer implements ErrorRendererInterface
3737
public function __construct(SerializerInterface $serializer, string|callable $format, ErrorRendererInterface $fallbackErrorRenderer = null, bool|callable $debug = false)
3838
{
3939
$this->serializer = $serializer;
40-
$this->format = $format;
40+
$this->format = \is_string($format) || $format instanceof \Closure ? $format : \Closure::fromCallable($format);
4141
$this->fallbackErrorRenderer = $fallbackErrorRenderer ?? new HtmlErrorRenderer();
42-
$this->debug = $debug;
42+
$this->debug = \is_bool($debug) || $debug instanceof \Closure ? $debug : \Closure::fromCallable($debug);
4343
}
4444

4545
/**

Exception/FlattenException.php

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,41 +24,18 @@
2424
*/
2525
class FlattenException
2626
{
27-
/** @var string */
28-
private $message;
29-
30-
/** @var int|string */
31-
private $code;
32-
33-
/** @var self|null */
34-
private $previous;
35-
36-
/** @var array */
37-
private $trace;
38-
39-
/** @var string */
40-
private $traceAsString;
41-
42-
/** @var string */
43-
private $class;
44-
45-
/** @var int */
46-
private $statusCode;
47-
48-
/** @var string */
49-
private $statusText;
50-
51-
/** @var array */
52-
private $headers;
53-
54-
/** @var string */
55-
private $file;
56-
57-
/** @var int */
58-
private $line;
59-
60-
/** @var string|null */
61-
private $asString;
27+
private string $message;
28+
private string|int $code;
29+
private ?self $previous = null;
30+
private array $trace;
31+
private string $traceAsString;
32+
private string $class;
33+
private int $statusCode;
34+
private string $statusText;
35+
private array $headers;
36+
private string $file;
37+
private int $line;
38+
private ?string $asString = null;
6239

6340
public static function create(\Exception $exception, int $statusCode = null, array $headers = []): static
6441
{

Exception/SilencedErrorContext.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class SilencedErrorContext implements \JsonSerializable
2020
{
2121
public $count = 1;
2222

23-
private $severity;
24-
private $file;
25-
private $line;
26-
private $trace;
23+
private int $severity;
24+
private string $file;
25+
private int $line;
26+
private array $trace;
2727

2828
public function __construct(int $severity, string $file, int $line, array $trace = [], int $count = 1)
2929
{

0 commit comments

Comments
 (0)