Skip to content

Commit e63e29e

Browse files
MyIgellocalheinz
andauthored
Fix PHP 8.2 warning: Use [static::class, '…'] instead of 'static::… for callbacks (#570)
* Fix: Use self::class . '::[…]' instead of 'static::[…]' as callbacks (PHP 8.2 warning) * Fix: Use static * Fix: Remove default value * Fix: Adjust number of allowed deprecations * Fix: Run 'make baseline' * Fix: Avoid string concatenation * Fix: Run 'make baseline' Co-authored-by: Andreas Möller <[email protected]>
1 parent e5e8400 commit e63e29e

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,11 @@ parameters:
633633
count: 1
634634
path: src/Faker/Provider/Base.php
635635

636+
-
637+
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\<int\\|string, string\\>\\)\\: string, array\\{class\\-string\\<static\\(Faker\\\\Provider\\\\Base\\)\\>, 'randomDigit'\\} given\\.$#"
638+
count: 1
639+
path: src/Faker/Provider/Base.php
640+
636641
-
637642
message: "#^Parameter \\$validator of method Faker\\\\Provider\\\\Base\\:\\:valid\\(\\) has invalid type Faker\\\\Provider\\\\Closure\\.$#"
638643
count: 1
@@ -733,6 +738,11 @@ parameters:
733738
count: 2
734739
path: src/Faker/Provider/cs_CZ/Person.php
735740

741+
-
742+
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\<int\\|string, string\\>\\)\\: string, array\\{class\\-string\\<static\\(Faker\\\\Provider\\\\en_CA\\\\Address\\)\\>, 'randomDigit'\\} given\\.$#"
743+
count: 1
744+
path: src/Faker/Provider/en_CA/Address.php
745+
736746
-
737747
message: "#^Unsafe call to private method Faker\\\\Provider\\\\en_GB\\\\Company\\:\\:generateBranchTraderVatNumber\\(\\) through static\\:\\:\\.$#"
738748
count: 1

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
1414
</listeners>
1515
<php>
16-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=404"/>
16+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
1717
</php>
1818
<testsuites>
1919
<testsuite name="Faker Test Suite">

psalm.baseline.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
</UndefinedDocblockClass>
140140
</file>
141141
<file src="src/Faker/Provider/Base.php">
142+
<InvalidArgument occurrences="1">
143+
<code>[static::class, 'randomDigit']</code>
144+
</InvalidArgument>
142145
<NoValue occurrences="1">
143146
<code>$array</code>
144147
</NoValue>

src/Faker/Provider/Base.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public static function shuffleString($string = '', $encoding = 'UTF-8')
363363
return implode('', static::shuffleArray($array));
364364
}
365365

366-
private static function replaceWildcard($string, $wildcard = '#', $callback = 'static::randomDigit')
366+
private static function replaceWildcard($string, $wildcard, $callback)
367367
{
368368
if (($pos = strpos($string, $wildcard)) === false) {
369369
return $string;
@@ -415,7 +415,7 @@ public static function numerify($string = '###')
415415
$string[$toReplace[$i]] = $numbers[$i];
416416
}
417417
}
418-
$string = self::replaceWildcard($string, '%', 'static::randomDigitNotNull');
418+
$string = self::replaceWildcard($string, '%', [static::class, 'randomDigitNotNull']);
419419

420420
return $string;
421421
}
@@ -429,7 +429,7 @@ public static function numerify($string = '###')
429429
*/
430430
public static function lexify($string = '????')
431431
{
432-
return self::replaceWildcard($string, '?', 'static::randomLetter');
432+
return self::replaceWildcard($string, '?', [static::class, 'randomLetter']);
433433
}
434434

435435
/**
@@ -460,7 +460,7 @@ public static function bothify($string = '## ??')
460460
*/
461461
public static function asciify($string = '****')
462462
{
463-
return preg_replace_callback('/\*/u', 'static::randomAscii', $string);
463+
return preg_replace_callback('/\*/u', [static::class, 'randomAscii'], $string);
464464
}
465465

466466
/**
@@ -532,8 +532,8 @@ public static function regexify($regex = '')
532532
return str_replace('.', '\.', $randomElement);
533533
}, $regex);
534534
// replace \d with number and \w with letter and . with ascii
535-
$regex = preg_replace_callback('/\\\w/', 'static::randomLetter', $regex);
536-
$regex = preg_replace_callback('/\\\d/', 'static::randomDigit', $regex);
535+
$regex = preg_replace_callback('/\\\w/', [static::class, 'randomLetter'], $regex);
536+
$regex = preg_replace_callback('/\\\d/', [static::class, 'randomDigit'], $regex);
537537
//replace . with ascii except backslash
538538
$regex = preg_replace_callback('/(?<!\\\)\./', static function () {
539539
$chr = static::asciify('*');

src/Faker/Provider/en_CA/Address.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public static function postcode()
6464
{
6565
$string = static::randomElement(static::$postcode);
6666

67-
$string = preg_replace_callback('/\#/u', 'static::randomDigit', $string);
68-
$string = preg_replace_callback('/\?/u', 'static::randomPostcodeLetter', $string);
67+
$string = preg_replace_callback('/\#/u', [static::class, 'randomDigit'], $string);
68+
$string = preg_replace_callback('/\?/u', [static::class, 'randomPostcodeLetter'], $string);
6969

7070
return static::toUpper($string);
7171
}

0 commit comments

Comments
 (0)