Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP 8.2 warning: Use [static::class, '…'] instead of 'static::… for callbacks #570

Merged
merged 7 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ parameters:
count: 1
path: src/Faker/Provider/Base.php

-
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array<int|string, string>\\)\\: string, 'Faker\\\\\\Provider\\\\\\Base…' given\\.$#"
count: 1
path: src/Faker/Provider/Base.php

-
message: "#^Method Faker\\\\Provider\\\\DateTime\\:\\:resolveTimezone\\(\\) never returns null so it can be removed from the return type\\.$#"
count: 1
Expand Down Expand Up @@ -733,6 +738,11 @@ parameters:
count: 2
path: src/Faker/Provider/cs_CZ/Person.php

-
message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array<int|string, string>\\)\\: string, 'Faker\\\\\\Provider\\\\\\Base…' given\\.$#"
count: 1
path: src/Faker/Provider/en_CA/Address.php

-
message: "#^Unsafe call to private method Faker\\\\Provider\\\\en_GB\\\\Company\\:\\:generateBranchTraderVatNumber\\(\\) through static\\:\\:\\.$#"
count: 1
Expand Down
12 changes: 6 additions & 6 deletions src/Faker/Provider/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public static function shuffleString($string = '', $encoding = 'UTF-8')
return implode('', static::shuffleArray($array));
}

private static function replaceWildcard($string, $wildcard = '#', $callback = 'static::randomDigit')
private static function replaceWildcard($string, $wildcard = '#', $callback = self::class . '::randomDigit')
localheinz marked this conversation as resolved.
Show resolved Hide resolved
localheinz marked this conversation as resolved.
Show resolved Hide resolved
{
if (($pos = strpos($string, $wildcard)) === false) {
return $string;
Expand Down Expand Up @@ -415,7 +415,7 @@ public static function numerify($string = '###')
$string[$toReplace[$i]] = $numbers[$i];
}
}
$string = self::replaceWildcard($string, '%', 'static::randomDigitNotNull');
$string = self::replaceWildcard($string, '%', self::class . '::randomDigitNotNull');
localheinz marked this conversation as resolved.
Show resolved Hide resolved

return $string;
}
Expand All @@ -429,7 +429,7 @@ public static function numerify($string = '###')
*/
public static function lexify($string = '????')
{
return self::replaceWildcard($string, '?', 'static::randomLetter');
return self::replaceWildcard($string, '?', self::class . '::randomLetter');
localheinz marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -460,7 +460,7 @@ public static function bothify($string = '## ??')
*/
public static function asciify($string = '****')
{
return preg_replace_callback('/\*/u', 'static::randomAscii', $string);
return preg_replace_callback('/\*/u', self::class . '::randomAscii', $string);
localheinz marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -532,8 +532,8 @@ public static function regexify($regex = '')
return str_replace('.', '\.', $randomElement);
}, $regex);
// replace \d with number and \w with letter and . with ascii
$regex = preg_replace_callback('/\\\w/', 'static::randomLetter', $regex);
$regex = preg_replace_callback('/\\\d/', 'static::randomDigit', $regex);
$regex = preg_replace_callback('/\\\w/', self::class . '::randomLetter', $regex);
$regex = preg_replace_callback('/\\\d/', self::class . '::randomDigit', $regex);
localheinz marked this conversation as resolved.
Show resolved Hide resolved
//replace . with ascii except backslash
$regex = preg_replace_callback('/(?<!\\\)\./', static function () {
$chr = static::asciify('*');
Expand Down
4 changes: 2 additions & 2 deletions src/Faker/Provider/en_CA/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public static function postcode()
{
$string = static::randomElement(static::$postcode);

$string = preg_replace_callback('/\#/u', 'static::randomDigit', $string);
$string = preg_replace_callback('/\?/u', 'static::randomPostcodeLetter', $string);
$string = preg_replace_callback('/\#/u', self::class . '::randomDigit', $string);
$string = preg_replace_callback('/\?/u', self::class . '::randomPostcodeLetter', $string);
localheinz marked this conversation as resolved.
Show resolved Hide resolved

return static::toUpper($string);
}
Expand Down