From e63e29e464e8ff11bc69e14e80bcfc1fde3b99db Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 13 Dec 2022 10:12:04 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20PHP=208.2=20warning:=20Use=20`[static::cl?= =?UTF-8?q?ass,=20'=E2=80=A6']`=20instead=20of=20`'static::=E2=80=A6`=20fo?= =?UTF-8?q?r=20callbacks=20(#570)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- phpstan-baseline.neon | 10 ++++++++++ phpunit.xml.dist | 2 +- psalm.baseline.xml | 3 +++ src/Faker/Provider/Base.php | 12 ++++++------ src/Faker/Provider/en_CA/Address.php | 4 ++-- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 93513469a8..67c2a8417f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -633,6 +633,11 @@ parameters: count: 1 path: src/Faker/Provider/Base.php + - + message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\\\)\\: string, array\\{class\\-string\\, 'randomDigit'\\} given\\.$#" + count: 1 + path: src/Faker/Provider/Base.php + - message: "#^Parameter \\$validator of method Faker\\\\Provider\\\\Base\\:\\:valid\\(\\) has invalid type Faker\\\\Provider\\\\Closure\\.$#" count: 1 @@ -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\\\\)\\: string, array\\{class\\-string\\, 'randomDigit'\\} 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 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1c521356cc..37222a4ffe 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,7 +13,7 @@ - + diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 2a60af42df..7c3b4e8717 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -139,6 +139,9 @@ + + [static::class, 'randomDigit'] + $array diff --git a/src/Faker/Provider/Base.php b/src/Faker/Provider/Base.php index 4ff4492a4e..e3713ce0e6 100644 --- a/src/Faker/Provider/Base.php +++ b/src/Faker/Provider/Base.php @@ -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) { if (($pos = strpos($string, $wildcard)) === false) { return $string; @@ -415,7 +415,7 @@ public static function numerify($string = '###') $string[$toReplace[$i]] = $numbers[$i]; } } - $string = self::replaceWildcard($string, '%', 'static::randomDigitNotNull'); + $string = self::replaceWildcard($string, '%', [static::class, 'randomDigitNotNull']); return $string; } @@ -429,7 +429,7 @@ public static function numerify($string = '###') */ public static function lexify($string = '????') { - return self::replaceWildcard($string, '?', 'static::randomLetter'); + return self::replaceWildcard($string, '?', [static::class, 'randomLetter']); } /** @@ -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', [static::class, 'randomAscii'], $string); } /** @@ -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/', [static::class, 'randomLetter'], $regex); + $regex = preg_replace_callback('/\\\d/', [static::class, 'randomDigit'], $regex); //replace . with ascii except backslash $regex = preg_replace_callback('/(?