Skip to content

Commit 7c4c59e

Browse files
committed
added PHP 8 typehints
1 parent 7e58925 commit 7c4c59e

File tree

8 files changed

+34
-79
lines changed

8 files changed

+34
-79
lines changed

src/Bridges/Nette/MailSender.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ public function __construct(Nette\Mail\IMailer $mailer, ?string $fromEmail = nul
3333
}
3434

3535

36-
/**
37-
* @param mixed $message
38-
*/
39-
public function send($message, string $email): void
36+
public function send(mixed $message, string $email): void
4037
{
4138
$host = preg_replace('#[^\w.-]+#', '', $_SERVER['SERVER_NAME'] ?? php_uname('n'));
4239

src/Bridges/Nette/TracyExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
166166
/**
167167
* @param string|string[] $value
168168
*/
169-
private function parseErrorSeverity($value): int
169+
private function parseErrorSeverity(string|array $value): int
170170
{
171171
$value = implode('|', (array) $value);
172172
$res = (int) @parse_ini_string('e = ' . $value)['e']; // @ may fail

src/Tracy/Debugger/Debugger.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ final public function __construct()
158158
* @param string $logDirectory error log directory
159159
* @param string|array $email administrator email; enables email sending in production mode
160160
*/
161-
public static function enable($mode = null, ?string $logDirectory = null, $email = null): void
162-
{
161+
public static function enable(
162+
bool|string|array|null $mode = null,
163+
?string $logDirectory = null,
164+
string|array|null $email = null,
165+
): void {
163166
if ($mode !== null || self::$productionMode === null) {
164167
self::$productionMode = is_bool($mode)
165168
? $mode
@@ -422,8 +425,8 @@ public static function getLogger(): ILogger
422425
}
423426

424427

425-
/** @return ProductionStrategy|DevelopmentStrategy @internal */
426-
public static function getStrategy()
428+
/** @internal */
429+
public static function getStrategy(): ProductionStrategy|DevelopmentStrategy
427430
{
428431
if (empty(self::$strategy[self::$productionMode])) {
429432
self::$strategy[self::$productionMode] = self::$productionMode
@@ -471,7 +474,7 @@ public static function getSessionStorage(): SessionStorage
471474
* @param bool $return return output instead of printing it? (bypasses $productionMode)
472475
* @return mixed variable itself or dump
473476
*/
474-
public static function dump($var, bool $return = false)
477+
public static function dump(mixed $var, bool $return = false): mixed
475478
{
476479
if ($return) {
477480
$options = [
@@ -518,10 +521,9 @@ public static function timer(?string $name = null): float
518521
/**
519522
* Dumps information about a variable in Tracy Debug Bar.
520523
* @tracySkipLocation
521-
* @param mixed $var
522524
* @return mixed variable itself
523525
*/
524-
public static function barDump($var, ?string $title = null, array $options = [])
526+
public static function barDump(mixed $var, ?string $title = null, array $options = []): mixed
525527
{
526528
if (!self::$productionMode) {
527529
static $panel;
@@ -543,10 +545,8 @@ public static function barDump($var, ?string $title = null, array $options = [])
543545

544546
/**
545547
* Logs message or exception.
546-
* @param mixed $message
547-
* @return mixed
548548
*/
549-
public static function log($message, string $level = ILogger::INFO)
549+
public static function log(mixed $message, string $level = ILogger::INFO): mixed
550550
{
551551
return self::getLogger()->log($message, $level);
552552
}
@@ -576,7 +576,7 @@ public static function mapSource(string $file, int $line): ?array
576576
* Detects debug mode by IP address.
577577
* @param string|array $list IP addresses or computer names whitelist detection
578578
*/
579-
public static function detectDebugMode($list = null): bool
579+
public static function detectDebugMode(string|array|null $list = null): bool
580580
{
581581
$addr = $_SERVER['REMOTE_ADDR'] ?? php_uname('n');
582582
$secret = isset($_COOKIE[self::COOKIE_SECRET]) && is_string($_COOKIE[self::COOKIE_SECRET])

src/Tracy/Dumper/Describer.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ public function describe($var): \stdClass
6767
}
6868

6969

70-
/**
71-
* @return mixed
72-
*/
73-
private function describeVar($var, int $depth = 0, ?int $refId = null)
70+
private function describeVar($var, int $depth = 0, ?int $refId = null): mixed
7471
{
7572
if ($var === null || is_bool($var)) {
7673
return $var;
@@ -81,21 +78,15 @@ private function describeVar($var, int $depth = 0, ?int $refId = null)
8178
}
8279

8380

84-
/**
85-
* @return Value|int
86-
*/
87-
private function describeInteger(int $num)
81+
private function describeInteger(int $num): Value|int
8882
{
8983
return $num <= self::JsSafeInteger && $num >= -self::JsSafeInteger
9084
? $num
9185
: new Value(Value::TypeNumber, "$num");
9286
}
9387

9488

95-
/**
96-
* @return Value|float
97-
*/
98-
private function describeDouble(float $num)
89+
private function describeDouble(float $num): Value|float
9990
{
10091
if (!is_finite($num)) {
10192
return new Value(Value::TypeNumber, (string) $num);
@@ -108,10 +99,7 @@ private function describeDouble(float $num)
10899
}
109100

110101

111-
/**
112-
* @return Value|string
113-
*/
114-
private function describeString(string $s, int $depth = 0)
102+
private function describeString(string $s, int $depth = 0): Value|string
115103
{
116104
$encoded = Helpers::encodeString($s, $depth ? $this->maxLength : null);
117105
if ($encoded === $s) {
@@ -124,10 +112,7 @@ private function describeString(string $s, int $depth = 0)
124112
}
125113

126114

127-
/**
128-
* @return Value|array
129-
*/
130-
private function describeArray(array $arr, int $depth = 0, ?int $refId = null)
115+
private function describeArray(array $arr, int $depth = 0, ?int $refId = null): Value|array
131116
{
132117
if ($refId) {
133118
$res = new Value(Value::TypeRef, 'p' . $refId);
@@ -231,10 +216,7 @@ private function describeResource($resource, int $depth = 0): Value
231216
}
232217

233218

234-
/**
235-
* @return Value|string
236-
*/
237-
public function describeKey(string $key)
219+
public function describeKey(string $key): Value|string
238220
{
239221
if (preg_match('#^[\w!\#$%&*+./;<>?@^{|}~-]{1,50}$#D', $key) && !preg_match('#^(true|false|null)$#iD', $key)) {
240222
return $key;
@@ -254,7 +236,7 @@ public function addPropertyTo(
254236
$type = Value::PropVirtual,
255237
?int $refId = null,
256238
?string $class = null,
257-
) {
239+
): void {
258240
if ($value->depth && $this->maxItems && count($value->items ?? []) >= $this->maxItems) {
259241
$value->length = ($value->length ?? count($value->items)) + 1;
260242
return;

src/Tracy/Dumper/Dumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Dumper
9292
* Dumps variable to the output.
9393
* @return mixed variable
9494
*/
95-
public static function dump($var, array $options = [])
95+
public static function dump($var, array $options = []): mixed
9696
{
9797
if (Helpers::isCli()) {
9898
$useColors = self::$terminalColors && Helpers::detectColors();

src/Tracy/Dumper/Exposer.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ public static function exposeDOMNode(\DOMNode $obj, Value $value, Describer $des
142142
}
143143

144144

145-
/**
146-
* @param \DOMNodeList|\DOMNamedNodeMap $obj
147-
*/
148-
public static function exposeDOMNodeList($obj, Value $value, Describer $describer): void
149-
{
145+
public static function exposeDOMNodeList(
146+
\DOMNodeList|\DOMNamedNodeMap $obj,
147+
Value $value,
148+
Describer $describer,
149+
): void {
150150
$describer->addPropertyTo($value, 'length', $obj->length, Value::PropPublic);
151151
$describer->addPropertyTo($value, 'items', iterator_to_array($obj));
152152
}

src/Tracy/Dumper/Renderer.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ public function renderAsText(\stdClass $model, array $colors = []): string
113113
}
114114

115115

116-
/**
117-
* @param mixed $value
118-
* @param string|int|null $keyType
119-
*/
120-
private function renderVar($value, int $depth = 0, $keyType = null): string
116+
private function renderVar(mixed $value, int $depth = 0, string|int|null $keyType = null): string
121117
{
122118
switch (true) {
123119
case $value === null:
@@ -164,11 +160,7 @@ private function renderVar($value, int $depth = 0, $keyType = null): string
164160
}
165161

166162

167-
/**
168-
* @param string|Value $str
169-
* @param string|int|null $keyType
170-
*/
171-
private function renderString($str, int $depth, $keyType): string
163+
private function renderString(string|Value $str, int $depth, string|int|null $keyType): string
172164
{
173165
if ($keyType === self::TypeArrayKey) {
174166
$indent = '<span class="tracy-dump-indent"> ' . str_repeat('| ', $depth - 1) . ' </span>';
@@ -241,10 +233,7 @@ private function renderString($str, int $depth, $keyType): string
241233
}
242234

243235

244-
/**
245-
* @param array|Value $array
246-
*/
247-
private function renderArray($array, int $depth): string
236+
private function renderArray(array|Value $array, int $depth): string
248237
{
249238
$out = '<span class="tracy-dump-array">array</span> (';
250239

src/Tracy/Logger/Logger.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ class Logger implements ILogger
3333
private ?BlueScreen $blueScreen = null;
3434

3535

36-
/**
37-
* @param string|array|null $email
38-
*/
39-
public function __construct(?string $directory, $email = null, ?BlueScreen $blueScreen = null)
36+
public function __construct(?string $directory, string|array|null $email = null, ?BlueScreen $blueScreen = null)
4037
{
4138
$this->directory = $directory;
4239
$this->email = $email;
@@ -81,10 +78,7 @@ public function log($message, $level = self::INFO)
8178
}
8279

8380

84-
/**
85-
* @param mixed $message
86-
*/
87-
public static function formatMessage($message): string
81+
public static function formatMessage(mixed $message): string
8882
{
8983
if ($message instanceof \Throwable) {
9084
foreach (Helpers::getExceptionChain($message) as $exception) {
@@ -104,10 +98,7 @@ public static function formatMessage($message): string
10498
}
10599

106100

107-
/**
108-
* @param mixed $message
109-
*/
110-
public static function formatLogLine($message, ?string $exceptionFile = null): string
101+
public static function formatLogLine(mixed $message, ?string $exceptionFile = null): string
111102
{
112103
return implode(' ', [
113104
date('[Y-m-d H-i-s]'),
@@ -152,10 +143,7 @@ protected function logException(\Throwable $exception, ?string $file = null): st
152143
}
153144

154145

155-
/**
156-
* @param mixed $message
157-
*/
158-
protected function sendEmail($message): void
146+
protected function sendEmail(mixed $message): void
159147
{
160148
$snooze = is_numeric($this->emailSnooze)
161149
? $this->emailSnooze
@@ -174,10 +162,9 @@ protected function sendEmail($message): void
174162

175163
/**
176164
* Default mailer.
177-
* @param mixed $message
178165
* @internal
179166
*/
180-
public function defaultMailer($message, string $email): void
167+
public function defaultMailer(mixed $message, string $email): void
181168
{
182169
$host = preg_replace('#[^\w.-]+#', '', $_SERVER['SERVER_NAME'] ?? php_uname('n'));
183170
$parts = str_replace(

0 commit comments

Comments
 (0)